| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
/* SoC-level support. |
| 8 |
* |
| 9 |
* Provide a unified register-level interface. |
| 10 |
* |
| 11 |
* This is the same information provided in the register headers |
| 12 |
* of ESP8266 Non-OS SDK and ESP-IDF soc component, however |
| 13 |
* only values that are needed for the flasher stub are included here. |
| 14 |
* |
| 15 |
*/ |
| 16 |
#pragma once |
| 17 |
|
| 18 |
#include <stdint.h> |
| 19 |
#include <stdbool.h> |
| 20 |
#include <stddef.h> |
| 21 |
|
| 22 |
#define READ_REG(REG) (*((volatile uint32_t *)(REG))) |
| 23 |
#define WRITE_REG(REG, VAL) *((volatile uint32_t *)(REG)) = (VAL) |
| 24 |
#define REG_SET_MASK(reg, mask) WRITE_REG((reg), (READ_REG(reg)|(mask))) |
| 25 |
#define REG_CLR_MASK(reg, mask) WRITE_REG((reg), (READ_REG(reg)&(~(mask)))) |
| 26 |
#define REG_SET_FIELD(_r, _f, _v) (WRITE_REG((_r),((READ_REG(_r) & ~((_f) << (_f##_S)))|(((_v) & (_f))<<(_f##_S))))) |
| 27 |
|
| 28 |
#define ESP32_OR_LATER !(ESP8266) |
| 29 |
#define ESP32S2_OR_LATER !(ESP8266 || ESP32) |
| 30 |
#define ESP32S3_OR_LATER !(ESP8266 || ESP32 || ESP32S2) |
| 31 |
|
| 32 |
/********************************************************** |
| 33 |
* Per-SOC capabilities |
| 34 |
*/ |
| 35 |
#ifdef ESP32S2 |
| 36 |
#define WITH_USB_OTG 1 |
| 37 |
#endif // ESP32S2 |
| 38 |
|
| 39 |
#ifdef ESP32C3 |
| 40 |
#define WITH_USB_JTAG_SERIAL 1 |
| 41 |
#define IS_RISCV 1 |
| 42 |
#endif // ESP32C3 |
| 43 |
|
| 44 |
#ifdef ESP32S3 |
| 45 |
#define WITH_USB_JTAG_SERIAL 1 |
| 46 |
#define WITH_USB_OTG 1 |
| 47 |
#endif // ESP32S3 |
| 48 |
|
| 49 |
#ifdef ESP32C6 |
| 50 |
#define WITH_USB_JTAG_SERIAL 1 |
| 51 |
#define IS_RISCV 1 |
| 52 |
#endif // ESP32C6 |
| 53 |
|
| 54 |
#ifdef ESP32H2 |
| 55 |
#define WITH_USB_JTAG_SERIAL 1 |
| 56 |
#define IS_RISCV 1 |
| 57 |
#endif // ESP32H2 |
| 58 |
|
| 59 |
#ifdef ESP32P4 |
| 60 |
// TODO: Add support for USB modes when MP is available |
| 61 |
// #define WITH_USB_JTAG_SERIAL 1 |
| 62 |
// #define WITH_USB_OTG 1 |
| 63 |
#define IS_RISCV 1 |
| 64 |
#endif // ESP32P4 |
| 65 |
|
| 66 |
// Increase CPU freq to speed up read/write operations over USB |
| 67 |
// Disabled on the S3 due to stability issues, would require dbias adjustment. |
| 68 |
// https://github.com/espressif/esptool/issues/832, https://github.com/espressif/esptool/issues/808 |
| 69 |
#define USE_MAX_CPU_FREQ ((WITH_USB_JTAG_SERIAL || WITH_USB_OTG) && !ESP32S3) |
| 70 |
|
| 71 |
// Later chips don't support ets_efuse_get_spiconfig. |
| 72 |
#define SUPPORT_CONFIG_SPI (ESP32 || ESP32S2 || ESP32S3 || ESP32S3BETA2 || ESP32C3 || ESP32H2BETA1 || ESP32H2BETA2 || ESP32C6BETA) |
| 73 |
|
| 74 |
/********************************************************** |
| 75 |
* Per-SOC based peripheral register base addresses |
| 76 |
* Sync with reg_base.h in ESP-IDF |
| 77 |
*/ |
| 78 |
#ifdef ESP8266 |
| 79 |
#define UART_BASE_REG 0x60000000 /* UART0 */ |
| 80 |
#define SPI_BASE_REG 0x60000200 /* SPI peripheral 0 */ |
| 81 |
#endif |
| 82 |
|
| 83 |
#ifdef ESP32 |
| 84 |
#define UART_BASE_REG 0x3ff40000 /* UART0 */ |
| 85 |
#define SPI_BASE_REG 0x3ff42000 /* SPI peripheral 1, used for SPI flash */ |
| 86 |
#define SPI0_BASE_REG 0x3ff43000 /* SPI peripheral 0, inner state machine */ |
| 87 |
#define GPIO_BASE_REG 0x3ff44000 /* GPIO */ |
| 88 |
#define DR_REG_IO_MUX_BASE 0x3ff49000 |
| 89 |
#endif |
| 90 |
|
| 91 |
#ifdef ESP32S2 |
| 92 |
#define UART_BASE_REG 0x60000000 /* UART0 */ |
| 93 |
#define SPI_BASE_REG 0x3f402000 /* SPI peripheral 1, used for SPI flash */ |
| 94 |
#define SPI0_BASE_REG 0x3f403000 /* SPI peripheral 0, inner state machine */ |
| 95 |
#define GPIO_BASE_REG 0x3f404000 |
| 96 |
#define USB_BASE_REG 0x60080000 |
| 97 |
#define RTCCNTL_BASE_REG 0x3f408000 |
| 98 |
#define SYSTEM_BASE_REG 0x3F4C0000 |
| 99 |
#define DR_REG_IO_MUX_BASE 0x3f409000 |
| 100 |
#endif |
| 101 |
|
| 102 |
#ifdef ESP32S3 |
| 103 |
#define UART_BASE_REG 0x60000000 /* UART0 */ |
| 104 |
#define SPI_BASE_REG 0x60002000 /* SPI peripheral 1, used for SPI flash */ |
| 105 |
#define SPI0_BASE_REG 0x60003000 /* SPI peripheral 0, inner state machine */ |
| 106 |
#define GPIO_BASE_REG 0x60004000 /* GPIO */ |
| 107 |
#define USB_BASE_REG 0x60080000 |
| 108 |
#define RTCCNTL_BASE_REG 0x60008000 /* RTC Control */ |
| 109 |
#define USB_DEVICE_BASE_REG 0x60038000 |
| 110 |
#define SYSTEM_BASE_REG 0x600C0000 |
| 111 |
#define DR_REG_IO_MUX_BASE 0x60009000 |
| 112 |
#endif |
| 113 |
|
| 114 |
#ifdef ESP32S3BETA2 |
| 115 |
#define UART_BASE_REG 0x60000000 /* UART0 */ |
| 116 |
#define SPI_BASE_REG 0x60002000 /* SPI peripheral 1, used for SPI flash */ |
| 117 |
#define SPI0_BASE_REG 0x60003000 /* SPI peripheral 0, inner state machine */ |
| 118 |
#define GPIO_BASE_REG 0x60004000 /* GPIO */ |
| 119 |
#define USB_BASE_REG 0x60080000 |
| 120 |
#define RTCCNTL_BASE_REG 0x60008000 /* RTC Control */ |
| 121 |
#define USB_DEVICE_BASE_REG 0x60038000 |
| 122 |
#define SYSTEM_BASE_REG 0x600C0000 |
| 123 |
#define DR_REG_IO_MUX_BASE 0x60009000 |
| 124 |
#endif |
| 125 |
|
| 126 |
#ifdef ESP32C3 |
| 127 |
#define UART_BASE_REG 0x60000000 /* UART0 */ |
| 128 |
#define SPI_BASE_REG 0x60002000 /* SPI peripheral 1, used for SPI flash */ |
| 129 |
#define SPI0_BASE_REG 0x60003000 /* SPI peripheral 0, inner state machine */ |
| 130 |
#define GPIO_BASE_REG 0x60004000 |
| 131 |
#define RTCCNTL_BASE_REG 0x60008000 /* RTC Control */ |
| 132 |
#define USB_DEVICE_BASE_REG 0x60043000 |
| 133 |
#define SYSTEM_BASE_REG 0x600C0000 |
| 134 |
#define DR_REG_IO_MUX_BASE 0x60009000 |
| 135 |
#endif |
| 136 |
|
| 137 |
#ifdef ESP32C6BETA |
| 138 |
#define UART_BASE_REG 0x60000000 /* UART0 */ |
| 139 |
#define SPI_BASE_REG 0x60002000 /* SPI peripheral 1, used for SPI flash */ |
| 140 |
#define SPI0_BASE_REG 0x60003000 /* SPI peripheral 0, inner state machine */ |
| 141 |
#define GPIO_BASE_REG 0x60004000 |
| 142 |
#define DR_REG_IO_MUX_BASE 0x60009000 |
| 143 |
#endif |
| 144 |
|
| 145 |
#ifdef ESP32H2BETA1 |
| 146 |
#define UART_BASE_REG 0x60000000 /* UART0 */ |
| 147 |
#define SPI_BASE_REG 0x60002000 /* SPI peripheral 1, used for SPI flash */ |
| 148 |
#define SPI0_BASE_REG 0x60003000 /* SPI peripheral 0, inner state machine */ |
| 149 |
#define GPIO_BASE_REG 0x60004000 |
| 150 |
#define RTCCNTL_BASE_REG 0x60008000 |
| 151 |
#define DR_REG_IO_MUX_BASE 0x60009000 |
| 152 |
#endif |
| 153 |
|
| 154 |
#ifdef ESP32H2BETA2 |
| 155 |
#define UART_BASE_REG 0x60000000 /* UART0 */ |
| 156 |
#define SPI_BASE_REG 0x60002000 /* SPI peripheral 1, used for SPI flash */ |
| 157 |
#define SPI0_BASE_REG 0x60003000 /* SPI peripheral 0, inner state machine */ |
| 158 |
#define GPIO_BASE_REG 0x60004000 |
| 159 |
#define DR_REG_IO_MUX_BASE 0x60009000 |
| 160 |
#endif |
| 161 |
|
| 162 |
#ifdef ESP32C2 |
| 163 |
#define UART_BASE_REG 0x60000000 /* UART0 */ |
| 164 |
#define SPI_BASE_REG 0x60002000 /* SPI peripheral 1, used for SPI flash */ |
| 165 |
#define SPI0_BASE_REG 0x60003000 /* SPI peripheral 0, inner state machine */ |
| 166 |
#define GPIO_BASE_REG 0x60004000 |
| 167 |
#define DR_REG_IO_MUX_BASE 0x60009000 |
| 168 |
#endif |
| 169 |
|
| 170 |
#ifdef ESP32C6 |
| 171 |
#define UART_BASE_REG 0x60000000 /* UART0 */ |
| 172 |
#define SPI_BASE_REG 0x60003000 /* SPI peripheral 1, used for SPI flash */ |
| 173 |
#define SPI0_BASE_REG 0x60002000 /* SPI peripheral 0, inner state machine */ |
| 174 |
#define GPIO_BASE_REG 0x60091000 |
| 175 |
#define USB_DEVICE_BASE_REG 0x6000F000 |
| 176 |
#define DR_REG_PCR_BASE 0x60096000 |
| 177 |
#define DR_REG_LP_WDT_BASE 0x600B1C00 |
| 178 |
#define DR_REG_IO_MUX_BASE 0x60009000 |
| 179 |
#endif |
| 180 |
|
| 181 |
#ifdef ESP32H2 |
| 182 |
#define UART_BASE_REG 0x60000000 /* UART0 */ |
| 183 |
#define SPI_BASE_REG 0x60003000 /* SPI peripheral 1, used for SPI flash */ |
| 184 |
#define SPI0_BASE_REG 0x60002000 /* SPI peripheral 0, inner state machine */ |
| 185 |
#define GPIO_BASE_REG 0x60091000 |
| 186 |
#define USB_DEVICE_BASE_REG 0x6000F000 |
| 187 |
#define DR_REG_PCR_BASE 0x60096000 |
| 188 |
#define DR_REG_LP_WDT_BASE 0x600B1C00 |
| 189 |
#define DR_REG_IO_MUX_BASE 0x60009000 |
| 190 |
#endif |
| 191 |
|
| 192 |
#ifdef ESP32P4 |
| 193 |
#define UART_BASE_REG 0x500CA000 /* UART0 */ |
| 194 |
#define SPI_BASE_REG 0x5008D000 /* SPI peripheral 1, used for SPI flash */ |
| 195 |
#define SPI0_BASE_REG 0x5008C000 /* SPI peripheral 0, inner state machine */ |
| 196 |
#define GPIO_BASE_REG 0x500E0000 |
| 197 |
#define DR_REG_IO_MUX_BASE 0x500E1000 |
| 198 |
#endif |
| 199 |
|
| 200 |
/********************************************************** |
| 201 |
* UART peripheral |
| 202 |
* |
| 203 |
* The features we use are basically the same on all chips |
| 204 |
* |
| 205 |
* Only UART0 is used |
| 206 |
*/ |
| 207 |
#define UART_CLKDIV_REG(X) (UART_BASE_REG + 0x14) |
| 208 |
#define UART_CLKDIV_M (0x000FFFFF) |
| 209 |
|
| 210 |
#if ESP32_OR_LATER |
| 211 |
#define UART_CLKDIV_FRAG_S 20 |
| 212 |
#define UART_CLKDIV_FRAG_V 0xF |
| 213 |
#endif |
| 214 |
|
| 215 |
#define UART_FIFO(X) (UART_BASE_REG + 0x00) |
| 216 |
#define UART_INT_ST(X) (UART_BASE_REG + 0x08) |
| 217 |
#define UART_INT_ENA(X) (UART_BASE_REG + 0x0C) |
| 218 |
#define UART_INT_CLR(X) (UART_BASE_REG + 0x10) |
| 219 |
#define UART_STATUS(X) (UART_BASE_REG + 0x1C) |
| 220 |
|
| 221 |
#if ESP32S2_OR_LATER && !ESP32C6 && !ESP32H2 |
| 222 |
#define UART_RXFIFO_CNT_M 0x3FF |
| 223 |
#else |
| 224 |
#define UART_RXFIFO_CNT_M 0xFF |
| 225 |
#endif |
| 226 |
|
| 227 |
#define UART_RXFIFO_FULL_INT_ENA (1<<0) |
| 228 |
#define UART_RXFIFO_TOUT_INT_ENA (1<<8) |
| 229 |
|
| 230 |
#define ETS_UART0_INUM 5 |
| 231 |
|
| 232 |
|
| 233 |
/********************************************************** |
| 234 |
* SPI peripheral |
| 235 |
* |
| 236 |
* The features we use are mostly the same on all chips |
| 237 |
* except for W0 base address & option for 2-byte status command |
| 238 |
* |
| 239 |
* Only one SPI peripheral is used (0 on ESP8266, 1 on ESP32). |
| 240 |
* On ESP32S2 && ESP32S3 this is called SPI_MEM_xxx index 1 |
| 241 |
*/ |
| 242 |
#define SPI_CMD_REG (SPI_BASE_REG + 0x00) |
| 243 |
#define SPI_FLASH_WREN (1<<30) |
| 244 |
#define SPI_FLASH_RDSR (1<<27) |
| 245 |
#define SPI_FLASH_SE (1<<24) |
| 246 |
#define SPI_FLASH_BE (1<<23) |
| 247 |
|
| 248 |
#define SPI_ADDR_REG (SPI_BASE_REG + 0x04) |
| 249 |
|
| 250 |
#define SPI_CTRL_REG (SPI_BASE_REG + 0x08) |
| 251 |
#if ESP32_OR_LATER |
| 252 |
#define SPI_WRSR_2B (1<<22) |
| 253 |
#endif |
| 254 |
|
| 255 |
#if ESP32S2_OR_LATER |
| 256 |
#define SPI_RD_STATUS_REG (SPI_BASE_REG + 0x2C) |
| 257 |
#else |
| 258 |
#define SPI_RD_STATUS_REG (SPI_BASE_REG + 0x10) |
| 259 |
#endif |
| 260 |
|
| 261 |
#ifdef ESP8266 |
| 262 |
#define SPI_W0_REG (SPI_BASE_REG + 0x40) |
| 263 |
#endif |
| 264 |
#ifdef ESP32 |
| 265 |
#define SPI_W0_REG (SPI_BASE_REG + 0x80) |
| 266 |
#endif |
| 267 |
#if ESP32S2_OR_LATER |
| 268 |
#define SPI_W0_REG (SPI_BASE_REG + 0x58) |
| 269 |
#endif |
| 270 |
|
| 271 |
#if ESP32S2_OR_LATER |
| 272 |
#define SPI_EXT2_REG (SPI_BASE_REG + 0x54) /* renamed SPI_MEM_FSM_REG */ |
| 273 |
#else |
| 274 |
#define SPI_EXT2_REG (SPI_BASE_REG + 0xF8) |
| 275 |
#endif |
| 276 |
|
| 277 |
#define SPI_ST 0x7 /* done state value */ |
| 278 |
|
| 279 |
#ifdef ESP32 |
| 280 |
/* On ESP32 & newer the SPI peripherals are layered |
| 281 |
* flash, this lets us check the state of the internal |
| 282 |
* state machine under the SPI flash controller |
| 283 |
*/ |
| 284 |
#define SPI0_EXT2_REG (SPI0_BASE_REG + 0xF8) |
| 285 |
#endif |
| 286 |
#if ESP32S2_OR_LATER |
| 287 |
#define SPI0_EXT2_REG (SPI0_BASE_REG + 0x54) |
| 288 |
#endif |
| 289 |
|
| 290 |
/********************************************************** |
| 291 |
* GPIO peripheral |
| 292 |
* |
| 293 |
* We only need to read the strapping register on ESP32 or later |
| 294 |
*/ |
| 295 |
#define GPIO_STRAP_REG (GPIO_BASE_REG + 0x38) |
| 296 |
|
| 297 |
/********************************************************** |
| 298 |
* USB peripheral |
| 299 |
*/ |
| 300 |
|
| 301 |
#ifdef ESP32S2 |
| 302 |
#define UART_USB_OTG 2 |
| 303 |
|
| 304 |
#define ETS_USB_INTR_SOURCE 48 |
| 305 |
#define ETS_USB_INUM 9 /* arbitrary level 1 level interrupt */ |
| 306 |
#endif // ESP32S2 |
| 307 |
|
| 308 |
#ifdef ESP32C3 |
| 309 |
#define UART_USB_JTAG_SERIAL 3 |
| 310 |
|
| 311 |
#define DR_REG_INTERRUPT_CORE0_BASE 0x600c2000 |
| 312 |
#define INTERRUPT_CORE0_USB_INTR_MAP_REG (DR_REG_INTERRUPT_CORE0_BASE + 0x068) /* USB-JTAG-Serial */ |
| 313 |
|
| 314 |
#define ETS_USB_INUM 17 /* arbitrary level 1 level interrupt */ |
| 315 |
#endif // ESP32C3 |
| 316 |
|
| 317 |
#ifdef ESP32S3 |
| 318 |
#define UART_USB_OTG 3 |
| 319 |
#define UART_USB_JTAG_SERIAL 4 |
| 320 |
|
| 321 |
#define DR_REG_INTERRUPT_CORE0_BASE 0x600c2000 |
| 322 |
#define INTERRUPT_CORE0_USB_INTR_MAP_REG (DR_REG_INTERRUPT_CORE0_BASE + 0x098) /* DWC-OTG */ |
| 323 |
#define INTERRUPT_CORE0_USB_DEVICE_INT_MAP_REG (DR_REG_INTERRUPT_CORE0_BASE + 0x180) /* USB-JTAG-Serial */ |
| 324 |
|
| 325 |
#define ETS_USB_INUM 17 /* arbitrary level 1 level interrupt */ |
| 326 |
#endif // ESP32S3 |
| 327 |
|
| 328 |
#ifdef ESP32C6 |
| 329 |
#define UART_USB_JTAG_SERIAL 3 |
| 330 |
|
| 331 |
#define DR_REG_INTERRUPT_MATRIX_BASE 0x60010000 |
| 332 |
#define INTERRUPT_CORE0_USB_INTR_MAP_REG (DR_REG_INTERRUPT_MATRIX_BASE + 0xC0) /* USB-JTAG-Serial, INTMTX_CORE0_USB_INTR_MAP_REG */ |
| 333 |
|
| 334 |
#define ETS_USB_INUM 17 /* arbitrary level 1 level interrupt */ |
| 335 |
#endif // ESP32C6 |
| 336 |
|
| 337 |
#ifdef ESP32H2 |
| 338 |
#define UART_USB_JTAG_SERIAL 3 |
| 339 |
|
| 340 |
#define DR_REG_INTERRUPT_MATRIX_BASE 0x60010000 |
| 341 |
#define INTERRUPT_CORE0_USB_INTR_MAP_REG (DR_REG_INTERRUPT_MATRIX_BASE + 0x94) /* USB-JTAG-Serial, INTMTX_CORE0_USB_INTR_MAP_REG */ |
| 342 |
|
| 343 |
#define ETS_USB_INUM 17 /* arbitrary level 1 level interrupt */ |
| 344 |
#endif // ESP32H2 |
| 345 |
|
| 346 |
#ifdef WITH_USB_JTAG_SERIAL |
| 347 |
#define USB_DEVICE_INT_ENA_REG (USB_DEVICE_BASE_REG + 0x010) |
| 348 |
#define USB_DEVICE_INT_CLR_REG (USB_DEVICE_BASE_REG + 0x014) |
| 349 |
#define USB_DEVICE_EP1_CONF_REG (USB_DEVICE_BASE_REG + 0x004) |
| 350 |
#define USB_DEVICE_EP1_REG (USB_DEVICE_BASE_REG + 0x000) |
| 351 |
#define USB_DEVICE_SERIAL_OUT_RECV_PKT_INT_CLR (1<<2) |
| 352 |
#define USB_DEVICE_SERIAL_OUT_EP_DATA_AVAIL (1<<2) |
| 353 |
#define USB_DEVICE_SERIAL_OUT_RECV_PKT_INT_ENA (1<<2) |
| 354 |
#endif // WITH_USB_JTAG_SERIAL |
| 355 |
|
| 356 |
#define USB_GAHBCFG_REG (USB_BASE_REG + 0x8) |
| 357 |
#define USB_GLBLLNTRMSK (1 << 0) |
| 358 |
|
| 359 |
|
| 360 |
/********************************************************** |
| 361 |
* RTC_CNTL peripheral |
| 362 |
*/ |
| 363 |
|
| 364 |
#ifdef ESP32S2 |
| 365 |
#define RTC_CNTL_OPTION1_REG (RTCCNTL_BASE_REG + 0x0128) |
| 366 |
#endif |
| 367 |
|
| 368 |
#ifdef ESP32S3 |
| 369 |
#define RTC_CNTL_OPTION1_REG (RTCCNTL_BASE_REG + 0x012C) |
| 370 |
#define RTC_CNTL_WDTCONFIG0_REG (RTCCNTL_BASE_REG + 0x0098) // RTC_CNTL_RTC_WDTCONFIG0_REG |
| 371 |
#define RTC_CNTL_WDTWPROTECT_REG (RTCCNTL_BASE_REG + 0x00B0) // RTC_CNTL_RTC_WDTWPROTECT_REG |
| 372 |
#define RTC_CNTL_SWD_CONF_REG (RTCCNTL_BASE_REG + 0x00B4) |
| 373 |
#define RTC_CNTL_SWD_WPROTECT_REG (RTCCNTL_BASE_REG + 0x00B8) |
| 374 |
#define RTC_CNTL_SWD_WKEY 0x8F1D312A |
| 375 |
#define RTC_CNTL_SWD_AUTO_FEED_EN (1 << 31) |
| 376 |
#endif |
| 377 |
|
| 378 |
#ifdef ESP32C3 |
| 379 |
#define RTC_CNTL_WDTCONFIG0_REG (RTCCNTL_BASE_REG + 0x0090) |
| 380 |
#define RTC_CNTL_WDTWPROTECT_REG (RTCCNTL_BASE_REG + 0x00A8) |
| 381 |
#define RTC_CNTL_SWD_CONF_REG (RTCCNTL_BASE_REG + 0x00AC) |
| 382 |
#define RTC_CNTL_SWD_WPROTECT_REG (RTCCNTL_BASE_REG + 0x00B0) |
| 383 |
#define RTC_CNTL_SWD_WKEY 0x8F1D312A |
| 384 |
#define RTC_CNTL_SWD_AUTO_FEED_EN (1 << 31) |
| 385 |
#endif |
| 386 |
|
| 387 |
#ifdef ESP32C6 |
| 388 |
#define RTC_CNTL_WDTCONFIG0_REG (DR_REG_LP_WDT_BASE + 0x0) // LP_WDT_RWDT_CONFIG0_REG |
| 389 |
#define RTC_CNTL_WDTWPROTECT_REG (DR_REG_LP_WDT_BASE + 0x0018) // LP_WDT_RWDT_WPROTECT_REG |
| 390 |
#define RTC_CNTL_SWD_CONF_REG (DR_REG_LP_WDT_BASE + 0x001C) // LP_WDT_SWD_CONFIG_REG |
| 391 |
#define RTC_CNTL_SWD_WPROTECT_REG (DR_REG_LP_WDT_BASE + 0x0020) // LP_WDT_SWD_WPROTECT_REG |
| 392 |
#define RTC_CNTL_SWD_WKEY 0x50D83AA1 |
| 393 |
#define RTC_CNTL_SWD_AUTO_FEED_EN (1 << 18) |
| 394 |
#endif |
| 395 |
|
| 396 |
#ifdef ESP32H2 |
| 397 |
#define RTC_CNTL_WDTCONFIG0_REG (DR_REG_LP_WDT_BASE + 0x0) // LP_WDT_RWDT_CONFIG0_REG |
| 398 |
#define RTC_CNTL_WDTWPROTECT_REG (DR_REG_LP_WDT_BASE + 0x001C) // LP_WDT_RWDT_WPROTECT_REG |
| 399 |
#define RTC_CNTL_SWD_CONF_REG (DR_REG_LP_WDT_BASE + 0x0020) // LP_WDT_SWD_CONFIG_REG |
| 400 |
#define RTC_CNTL_SWD_WPROTECT_REG (DR_REG_LP_WDT_BASE + 0x0024) // LP_WDT_SWD_WPROTECT_REG |
| 401 |
#define RTC_CNTL_SWD_WKEY 0x50D83AA1 |
| 402 |
#define RTC_CNTL_SWD_AUTO_FEED_EN (1 << 18) |
| 403 |
#endif |
| 404 |
|
| 405 |
#define RTC_CNTL_WDT_WKEY 0x50D83AA1 |
| 406 |
#define RTC_CNTL_FORCE_DOWNLOAD_BOOT (1 << 0) |
| 407 |
|
| 408 |
/********************************************************** |
| 409 |
* SYSTEM registers |
| 410 |
*/ |
| 411 |
|
| 412 |
#ifdef ESP32C3 |
| 413 |
#define SYSTEM_CPU_PER_CONF_REG (SYSTEM_BASE_REG + 0x008) |
| 414 |
#define SYSTEM_CPUPERIOD_SEL_M ((SYSTEM_CPUPERIOD_SEL_V)<<(SYSTEM_CPUPERIOD_SEL_S)) |
| 415 |
#define SYSTEM_CPUPERIOD_SEL_V 0x3 |
| 416 |
#define SYSTEM_CPUPERIOD_SEL_S 0 |
| 417 |
#define SYSTEM_CPUPERIOD_MAX 1 // CPU_CLK frequency is 160 MHz |
| 418 |
|
| 419 |
#define SYSTEM_SYSCLK_CONF_REG (SYSTEM_BASE_REG + 0x058) |
| 420 |
#define SYSTEM_SOC_CLK_SEL_M ((SYSTEM_SOC_CLK_SEL_V)<<(SYSTEM_SOC_CLK_SEL_S)) |
| 421 |
#define SYSTEM_SOC_CLK_SEL_V 0x3 |
| 422 |
#define SYSTEM_SOC_CLK_SEL_S 10 |
| 423 |
#define SYSTEM_SOC_CLK_MAX 1 |
| 424 |
#endif // ESP32C3 |
| 425 |
|
| 426 |
#ifdef ESP32S2 |
| 427 |
#define SYSTEM_CPU_PER_CONF_REG (SYSTEM_BASE_REG + 0x018) |
| 428 |
#define SYSTEM_CPUPERIOD_SEL_M ((SYSTEM_CPUPERIOD_SEL_V)<<(SYSTEM_CPUPERIOD_SEL_S)) |
| 429 |
#define SYSTEM_CPUPERIOD_SEL_V 0x3 |
| 430 |
#define SYSTEM_CPUPERIOD_SEL_S 0 |
| 431 |
#define SYSTEM_CPUPERIOD_MAX 2 // CPU_CLK frequency is 240 MHz |
| 432 |
|
| 433 |
#define SYSTEM_SYSCLK_CONF_REG (SYSTEM_BASE_REG + 0x08C) |
| 434 |
#define SYSTEM_SOC_CLK_SEL_M ((SYSTEM_SOC_CLK_SEL_V)<<(SYSTEM_SOC_CLK_SEL_S)) |
| 435 |
#define SYSTEM_SOC_CLK_SEL_V 0x3 |
| 436 |
#define SYSTEM_SOC_CLK_SEL_S 10 |
| 437 |
#define SYSTEM_SOC_CLK_MAX 1 |
| 438 |
#endif // ESP32S2 |
| 439 |
|
| 440 |
#ifdef ESP32C6 |
| 441 |
#define PCR_SYSCLK_CONF_REG (DR_REG_PCR_BASE + 0x110) |
| 442 |
#define PCR_SOC_CLK_SEL_M ((PCR_SOC_CLK_SEL_V)<<(PCR_SOC_CLK_SEL_S)) |
| 443 |
#define PCR_SOC_CLK_SEL_V 0x3 |
| 444 |
#define PCR_SOC_CLK_SEL_S 16 |
| 445 |
#define PCR_SOC_CLK_MAX 1 // CPU_CLK frequency is 160 MHz (source is PLL_CLK) |
| 446 |
#endif // ESP32C6 |
| 447 |
|
| 448 |
#ifdef ESP32H2 |
| 449 |
#define PCR_SYSCLK_CONF_REG (DR_REG_PCR_BASE + 0x10c) |
| 450 |
#define PCR_SOC_CLK_SEL_M ((PCR_SOC_CLK_SEL_V)<<(PCR_SOC_CLK_SEL_S)) |
| 451 |
#define PCR_SOC_CLK_SEL_V 0x3 |
| 452 |
#define PCR_SOC_CLK_SEL_S 16 |
| 453 |
#define PCR_SOC_CLK_MAX 1 // CPU_CLK frequency is 160 MHz (source is PLL_CLK) |
| 454 |
#endif // ESP32H2 |
| 455 |
|
| 456 |
/********************************************************** |
| 457 |
* Per-SOC security info buffer size |
| 458 |
*/ |
| 459 |
|
| 460 |
#ifdef ESP32S2 |
| 461 |
#define SECURITY_INFO_BYTES 12 /* doesn't include chip_id and api_version */ |
| 462 |
#endif // ESP32S2 |
| 463 |
|
| 464 |
#if ESP32S3_OR_LATER |
| 465 |
#define SECURITY_INFO_BYTES 20 |
| 466 |
#endif // ESP32S3_OR_LATER |
| 467 |
|
| 468 |
/********************************************************** |
| 469 |
* Per-SOC address of the rom_spiflash_legacy_funcs symbol in ROM |
| 470 |
* Can be retrieved with gdb: "info address rom_spiflash_legacy_funcs" |
| 471 |
*/ |
| 472 |
|
| 473 |
#if ESP32 || ESP32S2 || ESP32S3 || ESP32S3BETA2 |
| 474 |
#define ROM_SPIFLASH_LEGACY 0x3ffae270 |
| 475 |
#endif // ESP32 || ESP32S2 || ESP32S3 || ESP32S3BETA2 |
| 476 |
|
| 477 |
#if ESP32C3 || ESP32C6BETA || ESP32C2 || ESP32C6 |
| 478 |
#define ROM_SPIFLASH_LEGACY 0x3fcdfff4 |
| 479 |
#endif // ESP32C3 || ESP32C6BETA || ESP32C2 || ESP32C6 |
| 480 |
|
| 481 |
#if ESP32H2BETA1 || ESP32H2BETA2 |
| 482 |
#define ROM_SPIFLASH_LEGACY 0x3fcdfff0 |
| 483 |
#endif // ESP32H2BETA1 || ESP32H2BETA2 |
| 484 |
|
| 485 |
#if ESP32H2 |
| 486 |
#define ROM_SPIFLASH_LEGACY 0x4084fff0 |
| 487 |
#endif // ESP32H2 |
| 488 |
|
| 489 |
#if ESP32P4 |
| 490 |
#define ROM_SPIFLASH_LEGACY 0x4ff3ffec |
| 491 |
#endif // ESP32P4 |
| 492 |
|
| 493 |
/********************************************************** |
| 494 |
* IO-MUX peripheral |
| 495 |
*/ |
| 496 |
|
| 497 |
#define MCU_SEL 0x7 |
| 498 |
#define MCU_SEL_S 12 |
| 499 |
|
| 500 |
#define PIN_FUNC_SELECT(PIN_NAME, FUNC) REG_SET_FIELD(PIN_NAME, MCU_SEL, FUNC) |
| 501 |
|
| 502 |
#if ESP32 |
| 503 |
// PERIPHS_IO_MUX_SD_... |
| 504 |
#define PERIPHS_IO_MUX_SPICLK_U (DR_REG_IO_MUX_BASE + 0x60) |
| 505 |
#define PERIPHS_IO_MUX_SPID_U (DR_REG_IO_MUX_BASE + 0x68) |
| 506 |
#define PERIPHS_IO_MUX_SPIQ_U (DR_REG_IO_MUX_BASE + 0x64) |
| 507 |
#define PERIPHS_IO_MUX_SPICS0_U (DR_REG_IO_MUX_BASE + 0x5c) |
| 508 |
#define FUNC_GPIO 2 |
| 509 |
#endif // ESP32 |
| 510 |
|
| 511 |
#if ESP32S2 |
| 512 |
#define PERIPHS_IO_MUX_SPICLK_U (DR_REG_IO_MUX_BASE + 0x7c) |
| 513 |
#define PERIPHS_IO_MUX_SPIQ_U (DR_REG_IO_MUX_BASE + 0x80) |
| 514 |
#define PERIPHS_IO_MUX_SPID_U (DR_REG_IO_MUX_BASE + 0x84) |
| 515 |
#define PERIPHS_IO_MUX_SPICS0_U (DR_REG_IO_MUX_BASE + 0x78) |
| 516 |
#define FUNC_GPIO 1 |
| 517 |
#endif // ESP32S2 |
| 518 |
|
| 519 |
#if ESP32C3 |
| 520 |
#define PERIPHS_IO_MUX_SPICLK_U (DR_REG_IO_MUX_BASE + 0x40) |
| 521 |
#define PERIPHS_IO_MUX_SPIQ_U (DR_REG_IO_MUX_BASE + 0x48) |
| 522 |
#define PERIPHS_IO_MUX_SPID_U (DR_REG_IO_MUX_BASE + 0x44) |
| 523 |
#define PERIPHS_IO_MUX_SPICS0_U (DR_REG_IO_MUX_BASE + 0x3c) |
| 524 |
#define FUNC_GPIO 1 |
| 525 |
#endif // ESP32C3 |
| 526 |
|
| 527 |
#if ESP32S3 || ESP32S3BETA2 |
| 528 |
#define PERIPHS_IO_MUX_SPICLK_U (DR_REG_IO_MUX_BASE + 0x7c) |
| 529 |
#define PERIPHS_IO_MUX_SPIQ_U (DR_REG_IO_MUX_BASE + 0x80) |
| 530 |
#define PERIPHS_IO_MUX_SPID_U (DR_REG_IO_MUX_BASE + 0x84) |
| 531 |
#define PERIPHS_IO_MUX_SPICS0_U (DR_REG_IO_MUX_BASE + 0x78) |
| 532 |
#define FUNC_GPIO 1 |
| 533 |
#endif // ESP32S3 || ESP32S3BETA2 |
| 534 |
|
| 535 |
#if ESP32C2 |
| 536 |
#define PERIPHS_IO_MUX_SPICLK_U (DR_REG_IO_MUX_BASE + 0x40) |
| 537 |
#define PERIPHS_IO_MUX_SPIQ_U (DR_REG_IO_MUX_BASE + 0x48) |
| 538 |
#define PERIPHS_IO_MUX_SPID_U (DR_REG_IO_MUX_BASE + 0x44) |
| 539 |
#define PERIPHS_IO_MUX_SPICS0_U (DR_REG_IO_MUX_BASE + 0x3c) |
| 540 |
#define FUNC_GPIO 1 |
| 541 |
#endif // ESP32C2 |
| 542 |
|
| 543 |
#if ESP32C6 || ESP32C6BETA |
| 544 |
#define PERIPHS_IO_MUX_SPICLK_U (DR_REG_IO_MUX_BASE + 0x78) |
| 545 |
#define PERIPHS_IO_MUX_SPIQ_U (DR_REG_IO_MUX_BASE + 0x68) |
| 546 |
#define PERIPHS_IO_MUX_SPID_U (DR_REG_IO_MUX_BASE + 0x7c) |
| 547 |
#define PERIPHS_IO_MUX_SPICS0_U (DR_REG_IO_MUX_BASE + 0x64) |
| 548 |
#define FUNC_GPIO 1 |
| 549 |
#endif // ESP32C6 || ESP32C6BETA |
| 550 |
|
| 551 |
#if ESP32H2 || ESP32H2BETA1 || ESP32H2BETA2 |
| 552 |
#define PERIPHS_IO_MUX_SPICLK_U (DR_REG_IO_MUX_BASE + 0x50) |
| 553 |
#define PERIPHS_IO_MUX_SPIQ_U (DR_REG_IO_MUX_BASE + 0x44) |
| 554 |
#define PERIPHS_IO_MUX_SPID_U (DR_REG_IO_MUX_BASE + 0x54) |
| 555 |
#define PERIPHS_IO_MUX_SPICS0_U (DR_REG_IO_MUX_BASE + 0x40) |
| 556 |
#define FUNC_GPIO 1 |
| 557 |
#endif // ESP32H2 || ESP32H2BETA1 || ESP32H2BETA2 |
| 558 |
|
| 559 |
#if ESP32P4 |
| 560 |
#define PERIPHS_IO_MUX_SPICLK_U (DR_REG_IO_MUX_BASE + 0x7c) |
| 561 |
#define PERIPHS_IO_MUX_SPIQ_U (DR_REG_IO_MUX_BASE + 0x80) |
| 562 |
#define PERIPHS_IO_MUX_SPID_U (DR_REG_IO_MUX_BASE + 0x84) |
| 563 |
#define PERIPHS_IO_MUX_SPICS0_U (DR_REG_IO_MUX_BASE + 0x78) |
| 564 |
#define FUNC_GPIO 1 |
| 565 |
#endif // ESP32P4 |