README.txt 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. README for the Expressif ESP32 Core board (V2)
  2. ==============================================
  3. The ESP32 is a dual-core system from Expressif with two Harvard
  4. architecture Xtensa LX6 CPUs. All embedded memory, external memory and
  5. peripherals are located on the data bus and/or the instruction bus of
  6. these CPUs. With some minor exceptions, the address mapping of two CPUs
  7. is symmetric, meaning they use the same addresses to access the same
  8. memory. Multiple peripherals in the system can access embedded memory via
  9. DMA.
  10. The two CPUs are named "PRO_CPU" and "APP_CPU" (for "protocol" and
  11. "application"), however for most purposes the two CPUs are
  12. interchangeable.
  13. Contents
  14. ========
  15. o STATUS
  16. o ESP32 Features
  17. o ESP32 Toolchain
  18. o Memory Map
  19. o Serial Console
  20. o Buttons and LEDs
  21. o SMP
  22. o OpenOCD for the ESP32
  23. o Executing and Debugging from FLASH and IRAM
  24. o Configurations
  25. o Things to Do
  26. STATUS
  27. ======
  28. The basic port is underway. No testing has yet been performed.
  29. ESP32 Features
  30. ==============
  31. * Address Space
  32. - Symmetric address mapping
  33. - 4 GB (32-bit) address space for both data bus and instruction bus
  34. - 1296 KB embedded memory address space
  35. - 19704 KB external memory address space
  36. - 512 KB peripheral address space
  37. - Some embedded and external memory regions can be accessed by either
  38. data bus or instruction bus
  39. - 328 KB DMA address space
  40. * Embedded Memory
  41. - 448 KB Internal ROM
  42. - 520 KB Internal SRAM
  43. - 8 KB RTC FAST Memory
  44. - 8 KB RTC SLOW Memory
  45. * External Memory
  46. Off-chip SPI memory can be mapped into the available address space as
  47. external memory. Parts of the embedded memory can be used as transparent
  48. cache for this external memory.
  49. - Supports up to 16 MB off-Chip SPI Flash.
  50. - Supports up to 8 MB off-Chip SPI SRAM.
  51. * Peripherals
  52. - 41 peripherals
  53. * DMA
  54. - 13 modules are capable of DMA operation
  55. ESP32 Toolchain
  56. ===============
  57. You must use the custom Xtensa toolchain in order to build the ESP32 Core
  58. BSP. The steps to build toolchain with crosstool-NG on Linux are as
  59. follows:
  60. git clone -b xtensa-1.22.x https://github.com/espressif/crosstool-NG.git
  61. cd crosstool-NG
  62. ./bootstrap && ./configure --prefix=$PWD && make install
  63. ./ct-ng xtensa-esp32-elf
  64. ./ct-ng build
  65. chmod -R u+w builds/xtensa-esp32-elf
  66. These steps are given in setup guide in ESP-IDF repository:
  67. https://github.com/espressif/esp-idf/blob/master/docs/linux-setup.rst#alternative-step-1-compile-the-toolchain-from-source-using-crosstool-ng
  68. NOTE: The xtensa-esp32-elf configuration is only available in the
  69. xtensa-1.22.x branch.
  70. Memory Map
  71. ==========
  72. Address Mapping
  73. ----------- ---------- ---------- --------------- ---------------
  74. BUS TYPE START LAST DESCRIPTION NOTES
  75. ----------- ---------- ---------- --------------- ---------------
  76. 0x00000000 0x3F3FFFFF Reserved
  77. Data 0x3F400000 0x3F7FFFFF External Memory
  78. Data 0x3F800000 0x3FBFFFFF External Memory
  79. 0x3FC00000 0x3FEFFFFF Reserved
  80. Data 0x3FF00000 0x3FF7FFFF Peripheral
  81. Data 0x3FF80000 0x3FFFFFFF Embedded Memory
  82. Instruction 0x40000000 0x400C1FFF Embedded Memory
  83. Instruction 0x400C2000 0x40BFFFFF External Memory
  84. 0x40C00000 0x4FFFFFFF Reserved
  85. Data / 0x50000000 0x50001FFF Embedded Memory
  86. Instruction
  87. 0x50002000 0xFFFFFFFF Reserved
  88. Embedded Memory
  89. ----------- ---------- ---------- --------------- ---------------
  90. BUS TYPE START LAST DESCRIPTION NOTES
  91. ----------- ---------- ---------- --------------- ---------------
  92. Data 0x3ff80000 0x3ff81fff RTC FAST Memory PRO_CPU Only
  93. 0x3ff82000 0x3ff8ffff Reserved
  94. Data 0x3ff90000 0x3ff9ffff Internal ROM 1
  95. 0x3ffa0000 0x3ffadfff Reserved
  96. Data 0x3ffae000 0x3ffdffff Internal SRAM 2 DMA
  97. Data 0x3ffe0000 0x3fffffff Internal SRAM 1 DMA
  98. Boundary Address
  99. ----------- ---------- ---------- --------------- ---------------
  100. BUS TYPE START LAST DESCRIPTION NOTES
  101. ----------- ---------- ---------- --------------- ---------------
  102. Instruction 0x40000000 0x40007fff Internal ROM 0 Remap
  103. Instruction 0x40008000 0x4005ffff Internal ROM 0
  104. 0x40060000 0x4006ffff Reserved
  105. Instruction 0x40070000 0x4007ffff Internal SRAM 0 Cache
  106. Instruction 0x40080000 0x4009ffff Internal SRAM 0
  107. Instruction 0x400a0000 0x400affff Internal SRAM 1
  108. Instruction 0x400b0000 0x400b7FFF Internal SRAM 1 Remap
  109. Instruction 0x400b8000 0x400bffff Internal SRAM 1
  110. Instruction 0x400c0000 0x400c1FFF RTC FAST Memory PRO_CPU Only
  111. Data / 0x50000000 0x50001fff RTC SLOW Memory
  112. Instruction
  113. External Memory
  114. ----------- ---------- ---------- --------------- ---------------
  115. BUS TYPE START LAST DESCRIPTION NOTES
  116. ----------- ---------- ---------- --------------- ---------------
  117. Data 0x3f400000 0x3f7fffff External Flash Read
  118. Data 0x3f800000 0x3fbfffff External SRAM Read and Write
  119. Boundary Address
  120. ----------------
  121. Instruction 0x400c2000 0x40bfffff 11512 KB External Flash Read
  122. Linker Segments
  123. ------------------ ---------- ---------- ---- ----------------------------
  124. DESCRIPTION START END ATTR LINKER SEGMENT NAME
  125. ------------------ ---------- ---------- ---- ----------------------------
  126. FLASH mapped data: 0x3f400010 0x3fc00010 R drom0_0_seg
  127. - .rodata
  128. - Constructors/destructors
  129. COMMON data RAM: 0x3ffb0000 0x40000000 RW dram0_0_seg (NOTE 1,2)
  130. - .bss/.data
  131. IRAM for PRO cpu: 0x40080000 0x400a0000 RX iram0_0_seg
  132. - Interrupt Vectors
  133. - Low level handlers
  134. - Xtensa/Expressif libraries
  135. RTC fast memory: 0x400c0000 0x400c2000 RWX rtc_iram_seg (PRO_CPU only)
  136. - .rtc.text (unused?)
  137. FLASH: 0x400d0018 0x40400018 RX iram0_2_seg (actually FLASH)
  138. - .text
  139. RTC slow memory: 0x50000000 0x50001000 RW rtc_slow_seg (NOTE 3)
  140. - .rtc.data/rodata (unused?)
  141. NOTE 1: Linker script will reserve space at the beginning of the segment
  142. for BT and at the end for trace memory.
  143. NOTE 2: Heap enads at the top of dram_0_seg
  144. NOTE 3: Linker script will reserve space at the beginning of the segment
  145. for co-processor reserve memory and at the end for ULP coprocessor
  146. reserve memory.
  147. Serial Console
  148. ==============
  149. UART0 is, by default, the serial console. It connects to the on-board
  150. CP2102 converter and is available on the USB connector USB CON8 (J1).
  151. It will show up as /dev/ttypUSB[n] where [n] will probably be 0 (is it 1
  152. on my PC because I have a another device at ttyUSB0).
  153. Buttons and LEDs
  154. ================
  155. Buttons
  156. -------
  157. There are two buttons labeled Boot and EN. The EN button is not available
  158. to software. It pulls the chip enable line that doubles as a reset line.
  159. The BOOT button is connected to IO0. On reset it is used as a strapping
  160. pin to determine whether the chip boots normally or into the serial
  161. bootloader. After reset, however, the BOOT button can be used for software
  162. input.
  163. LEDs
  164. ----
  165. There are several on-board LEDs for that indicate the presence of power
  166. and USB activity. None of these are available for use by sofware.
  167. SMP
  168. ===
  169. The ESP32 has 2 CPUs. Support is included for testing an SMP configuration.
  170. That configuration is still not yet ready for usage but can be enabled with
  171. the following configuration settings:
  172. RTOS Features -> Tasks and Scheduling
  173. CONFIG_SPINLOCK=y
  174. CONFIG_SMP=y
  175. CONFIG_SMP_NCPUS=2
  176. CONFIG_SMP_IDLETHREAD_STACKSIZE=3072
  177. Debug Tip: During debug session, OpenOCD may mysteriously switch from one
  178. CPU to another. This behavior can be eliminated by uncommenting one of the
  179. following in scripts/esp32.cfg
  180. # Only configure the PRO CPU
  181. #set ESP32_ONLYCPU 1
  182. # Only configure the APP CPU
  183. #set ESP32_ONLYCPU 2
  184. Open Issues:
  185. 1. Cache Issues. I have not though about this yet, but certainly caching is
  186. an issue in an SMP system:
  187. - Cache coherency. Are there separate caches for each CPU? Or a single
  188. shared cache? If the are separate then keep the caches coherent will
  189. be an issue.
  190. - Caching MAY interfere with spinlocks as they are currently implemented.
  191. Waiting on a cached copy of the spinlock may result in a hang or a
  192. failure to wait.
  193. 2. Assertions. On a fatal assertions, other CPUs need to be stopped.
  194. OpenOCD for the ESP32
  195. =====================
  196. First you in need some debug environment which would be a JTAG emulator
  197. and the ESP32 OpenOCD software which is available here:
  198. https://github.com/espressif/openocd-esp32
  199. OpenOCD Documentation
  200. ---------------------
  201. There is on overiew of the use of OpenOCD here:
  202. https://dl.espressif.com/doc/esp-idf/latest/openocd.html
  203. This document is also available in ESP-IDF source tree in docs
  204. directory (https://github.com/espressif/esp-idf).
  205. OpenOCD Configuration File
  206. --------------------------
  207. A template ESP32 OpenOCD configuration file is provided in
  208. ESP-IDF docs directory (esp32.cfg). Since you are not using
  209. FreeRTOS, you will need to uncomment the line:
  210. set ESP32_RTOS none
  211. in the OpenOCD configuration file. You will also need to change
  212. the source line from:
  213. find interface/ftdi/tumpa.cfg
  214. to reflect the physical JTAG adapter connected.
  215. NOTE: A copy of this OpenOCD configuration file available in the NuttX
  216. source tree at nuttx/config/esp32-core/scripts/esp32.cfg.. It has these
  217. modifications:
  218. - The referenced "set ESP32_RTOS none" line has been uncommented
  219. - The "ind interface/ftdi/tumpa.cfg". This means that you will
  220. need to specify the interface configuration file on the OpenOCD
  221. command line.
  222. General OpenOCD build instructions
  223. ----------------------------------
  224. Installing OpenOCD. The sources for the ESP32-enabled variant of
  225. OpenOCD are available from Espressifs Github. To download the source,
  226. use the following commands:
  227. git clone https://github.com/espressif/openocd-esp32.git
  228. cd openocd-esp32
  229. git submodule init
  230. git submodule update
  231. Then look at the README and the docs/INSTALL.txt files in the
  232. openocd-esp32 directory for further instructions. There area
  233. separate README files for Linux/Cygwin, OSX, and Windows. Here
  234. is what I ended up doing (under Linux):
  235. cd openocd-esp32
  236. ./bootstrap
  237. ./configure
  238. make
  239. If you do not do the install step, then you will have a localhost
  240. version of the OpenOCD binary at openocd-esp32/src.
  241. Starting the OpenOCD Server
  242. ---------------------------
  243. - cd to openocd-esp32 directory
  244. - copy the modified esp32.cfg script to this directory
  245. Then start OpenOCD by executing a command like the following. Here
  246. I assume that:
  247. - You did not install OpenOCD; binararies are avalable at
  248. openocd-esp32/src and interface scripts are in
  249. openocd-eps32/tcl/interface
  250. - I select the configuration for the Olimex ARM-USB-OCD
  251. debugger.
  252. Then the command to start OpenOCD is:
  253. sudo ./src/openocd -s ./tcl -f tcl/interface/ftdi/olimex-arm-usb-ocd.cfg -f ./esp32.cfg
  254. I then see:
  255. Open On-Chip Debugger 0.10.0-dev-g3098897 (2016-11-14-12:19)
  256. Licensed under GNU GPL v2
  257. For bug reports, read
  258. http://openocd.org/doc/doxygen/bugs.html
  259. adapter speed: 200 kHz
  260. force hard breakpoints
  261. Info : clock speed 200 kHz
  262. Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
  263. Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
  264. Info : esp32.cpu0: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
  265. Info : esp32.cpu0: Core was reset (pwrstat=0x5F, after clear 0x0F).
  266. Connecting a debugger to OpenOCD
  267. --------------------------------
  268. OpenOCD should now be ready to accept gdb connections. If you have
  269. compiled the ESP32 toolchain using Crosstool-NG, or if you have
  270. downloaded a precompiled toolchain from the Espressif website, you
  271. should already have xtensa-esp32-elf-gdb, a version of gdb that can
  272. be used for this
  273. First, make sure the project you want to debug is compiled and
  274. flashed into the ESP32’s SPI flash. Then, in a different console
  275. than OpenOCD is running in, invoke gdb. For example, for the
  276. template app, you would do this like such:
  277. cd nuttx
  278. xtensa-esp32-elf-gdb -ex 'target remote localhost:3333' nuttx
  279. This should give you a gdb prompt.
  280. Breakpoints
  281. -----------
  282. You can set up to 2 hardware breakpoints, which can be anywhere in the
  283. address space. Also 2 hardware watchpoints.
  284. The openocd esp32.cfg file currently forces gdb to use hardware
  285. breakpoints, I believe because software breakpoints (or, at least, the
  286. memory map for automatically choosing them) aren't implemented yet
  287. (as of 2016-11-14).
  288. JTAG Emulator
  289. -------------
  290. The documentation indicates that you need to use an external JTAG
  291. like the TIAO USB Multi-protocol Adapter and the Flyswatter2.
  292. The instructions at http://www.esp32.com/viewtopic.php?t=381 show
  293. use of an FTDI C232HM-DDHSL-0 USB 2.0 high speed to MPSSE cable.
  294. The ESP32 Core v2 board has no on board JTAG connector. It will
  295. be necessary to make a cable or some other board to connect a JTAG
  296. emulator. Refer to http://www.esp32.com/viewtopic.php?t=381 "How
  297. to debug ESP32 with JTAG / OpenOCD / GDB 1st part connect the
  298. hardware."
  299. Relevant pin-out:
  300. -------- ----------
  301. PIN JTAG
  302. LABEL FUNCTION
  303. -------- ----------
  304. IO14 TMS
  305. IO12 TDI
  306. GND GND
  307. IO13 TCK
  308. -------- ----------
  309. IO15 TDO
  310. -------- ----------
  311. You can find the mapping of JTAG signals to ESP32 GPIO numbers in
  312. "ESP32 Pin List" document found here:
  313. http://espressif.com/en/support/download/documents?keys=&field_type_tid%5B%5D=13
  314. I put the ESP32 on a prototyping board and used a standard JTAG 20-pin
  315. connector with an older Olimex JTAG that I had. Here is how I wired
  316. the 20-pin connector:
  317. ----------------- ----------
  318. 20-PIN JTAG ESP32 PIN
  319. CONNECTOR LABEL
  320. ----------------- ----------
  321. 1 VREF INPUT 3V3
  322. 3 nTRST OUTPUT N/C
  323. 5 TDI OUTPUT IO12
  324. 7 TMS OUTPUT IO14
  325. 9 TCLK OUTPUT IO13
  326. 11 RTCK INPUT N/C
  327. 13 TDO INPUT IO15
  328. 15 RESET I/O N/C
  329. 17 DBGRQ OUTPUT N/C
  330. 19 5V OUTPUT N/C
  331. ------------ ----------
  332. 2 VCC INPUT 3V3
  333. 4 GND N/A GND
  334. 6 GND N/A GND
  335. 8 GND N/A GND
  336. 10 GND N/A GND
  337. 12 GND N/A GND
  338. 14 GND N/A GND
  339. 16 GND N/A GND
  340. 18 GND N/A GND
  341. 20 GND N/A GND
  342. ------------ ----------
  343. Executing and Debugging from FLASH and IRAM
  344. ===========================================
  345. Enable Debug Symbols
  346. --------------------
  347. To debug with GDB, you will need to enable symbols in the build. You do this
  348. with 'make menuconfig' then selecting:
  349. - "Build Setup" -> "Debug Options" -> "Generate Debug Symbols"
  350. And, to make debugging easier, also disable optimizations. This will make
  351. your code a lot bigger:
  352. - "Build Setup" -> "Optimization Level" -> "Suppress Optimization"
  353. FLASH
  354. -----
  355. OpenOCD currently doesn't have a FLASH driver for ESP32, so you can load
  356. code into IRAM only via JTAG. FLASH-resident sections like .FLASH.rodata
  357. will fail to load. The bootloader in ROM doesn't parse ELF, so any imag
  358. which is bootloaded from FLASH has to be converted into a custom image
  359. format first.
  360. The tool esp-idf uses for flashing is a command line Python tool called
  361. "esptool.py" which talks to a serial bootloader in ROM. A version is
  362. supplied in the esp-idf codebase in components/esptool_py/esptool, the
  363. "upstream" for that tool is here:
  364. https://github.com/espressif/esptool/pull/121
  365. The master branch for esptool.py is currently ESP8266-only (as of 2016-11-14),
  366. this PR has the ESP32 support which still needs some final tidying up before
  367. it's
  368. merged.
  369. To FLASH an ELF via the command line is a two step process, something like
  370. this:
  371. esptool.py --chip esp32 elf2image --flash_mode dio --flash_size 4MB -o ./nuttx.bin nuttx
  372. esptool.py --chip esp32 --port COMx write_flash 0x1000 bootloader.bin 0x4000 partition_table.bin 0x10000 nuttx.bin
  373. The first step converts an ELF image into an ESP32-compatible binary
  374. image format, and the second step flashes it (along with bootloader image and
  375. partition table binary.)
  376. To put the ESP32 into serial flashing mode, it needs to be reset with IO0 held
  377. low. On the Core boards this can be accomplished by holding the button marked
  378. "Boot" and pressing then releasing the button marked "EN". Actually, esptool.py
  379. can enter bootloader mode automatically (via RTS/DTR control lines), but
  380. unfortunately a timing interaction between the Windows CP2012 driver and the
  381. hardware means this doesn't currently work on Windows.
  382. Secondary Boot Loader / Partition Table
  383. ---------------------------------------
  384. See https://github.com/espressif/esp-idf/tree/master/components/bootloader
  385. and https://github.com/espressif/esp-idf/tree/master/components/partition_table.
  386. Running from IRAM with OpenOCD
  387. ------------------------------
  388. Running from IRAM is a good debug option. You should be able to load the
  389. ELF directly via JTAG in this case, and you may not need the bootloader.
  390. NuttX supports a configuration option, CONFIG_ESP32CORE_RUN_IRAM, that may be
  391. selected for execution from IRAM. This option simply selects the correct
  392. linker script for IRAM execution.
  393. Skipping the Secondary Bootloader
  394. ---------------------------------
  395. It is possible to skip the secondary bootloader and run out of IRAM using
  396. only the primary bootloader if your application of small enough (< 128KiB code,
  397. <180KiB data), then you can simplify initial bring-up by avoiding second stage
  398. bootloader. Your application will be loaded into IRAM using first stage
  399. bootloader present in ESP32 ROM. To achieve this, you need two things:
  400. 1. Have a linker script which places all code into IRAM and all data into
  401. IRAM/DRAM
  402. 2. Use "esptool.py" utility found in ESP-IDF to convert application .elf
  403. file into binary format which can be loaded by first stage bootloader.
  404. Again you would need to link the ELF file and convert it to binary format suitable
  405. for flashing into the board. The command should to convert ELF file to binary
  406. image looks as follows:
  407. python esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 elf2image --flash_mode "dio" --flash_freq "40m" --flash_size "2MB" -o nuttx.bin nuttx
  408. To flash binary image to your development board, use the same esptool.py utility:
  409. python esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 write_flash -z --flash_mode dio --flash_freq 40m --flash_size 2MB 0x1000 nuttx.bin
  410. The argument before app.bin (0x1000) indicates the offset in flash where binary
  411. will be written. ROM bootloader expects to find an application (or second stage
  412. bootloader) image at offset 0x1000, so we are writing the binary there.
  413. Clocking
  414. --------
  415. Right now, the NuttX port depends on the bootloader to initialize hardware,
  416. including basic (slow) clocking. If I had the clock configuration logic,
  417. would I be able to run directly out of IRAM without a bootloader? That
  418. might be a simpler bring-up.
  419. Sample OpenOCD Debug Steps
  420. --------------------------
  421. I did the initial bring-up using the IRAM configuration and OpenOCD. Here
  422. is a synopsis of my debug steps:
  423. configs/esp32-core/nsh with
  424. CONFIG_DEBUG_ASSERTIONS=y
  425. CONFIG_DEBUG_FEATURES=y
  426. CONFIG_DEBUG_SYMBOLS=y
  427. CONFIG_ESP32CORE_RUN_IRAM=y
  428. I also made this change which will eliminate all attempts to re-configure
  429. serial. It will just use the serial settings as they were left by the
  430. bootloader:
  431. diff --git a/arch/xtensa/src/common/xtensa.h b/arch/xtensa/src/common/xtensa.h
  432. index 422ec0b..8707d7c 100644
  433. --- a/arch/xtensa/src/common/xtensa.h
  434. +++ b/arch/xtensa/src/common/xtensa.h
  435. @@ -60,7 +60,7 @@
  436. #undef CONFIG_SUPPRESS_INTERRUPTS /* DEFINED: Do not enable interrupts */
  437. #undef CONFIG_SUPPRESS_TIMER_INTS /* DEFINED: No timer */
  438. #undef CONFIG_SUPPRESS_SERIAL_INTS /* DEFINED: Console will poll */
  439. -#undef CONFIG_SUPPRESS_UART_CONFIG /* DEFINED: Do not reconfigure UART */
  440. +#define CONFIG_SUPPRESS_UART_CONFIG 1 /* DEFINED: Do not reconfigure UART */
  441. #define CONFIG_SUPPRESS_CLOCK_CONFIG 1 /* DEFINED: Do not reconfigure clocking */
  442. #undef CONFIG_DUMP_ON_EXIT /* DEFINED: Dump task state on exit */
  443. Start OpenOCD:
  444. cd ../openocde-esp32
  445. cp ../nuttx/configs/esp32-core/scripts/esp32.cfg .
  446. sudo ./src/openocd -s ./tcl/ -f tcl/interface/ftdi/olimex-arm-usb-ocd.cfg -f ./esp32.cfg
  447. Start GDB and load code:
  448. cd ../nuttx
  449. xtensa-esp32-elf-gdb -ex 'target remote localhost:3333' nuttx
  450. (gdb) load nuttx
  451. (gdb) mon reg pc [value report by load for entry point]
  452. (gdb) s
  453. Single stepping works fine for me as do breakpoints:
  454. Breakpoint 1, xtensa_timer_initialize () at chip/esp32_timerisr.c:172
  455. 72 {
  456. (gdb) n
  457. esp32.cpu0: Target halted, pc=0x400835BF
  458. 187 g_tick_divisor = divisor;
  459. (gdb) ...
  460. Configurations
  461. ==============
  462. Common Configuration Information
  463. --------------------------------
  464. Each ESP32 core configuration is maintained in sub-directories and
  465. can be selected as follow:
  466. cd tools
  467. ./configure.sh esp32-core/<subdir>
  468. cd -
  469. make oldconfig
  470. Before building, make sure the PATH environment variable includes the
  471. correct path to the directory than holds your toolchain binaries.
  472. If this is a Windows native build, then configure.bat should be used
  473. instead of configure.sh:
  474. configure.bat esp32-core\<subdir>
  475. And then build NuttX by simply typing the following. At the conclusion of
  476. the make, the nuttx binary will reside in an ELF file called, simply,
  477. nuttx.
  478. make oldconfig
  479. make
  480. The <subdir> that is provided above as an argument to the
  481. tools/configure.sh must be is one of the directories listed below.
  482. NOTES:
  483. 1. These configurations use the mconf-based configuration tool. To
  484. change any of these configurations using that tool, you should:
  485. a. Build and install the kconfig-mconf tool. See nuttx/README.txt
  486. see additional README.txt files in the NuttX tools repository.
  487. b. Execute 'make menuconfig' in nuttx/ in order to start the
  488. reconfiguration process.
  489. 2. Unless stated otherwise, all configurations generate console
  490. output on UART0 (see the "Serial Console" section above).
  491. 3. By default, these configurations assume a 40MHz crystal on-
  492. board:
  493. CONFIG_ESP32CORE_XTAL_40MZ=y
  494. # CONFIG_ESP32CORE_XTAL_26MHz is not set
  495. 4. Default configurations are set to run from FLASH. You will need
  496. to set CONFIG_ESP32CORE_RUN_IRAM=y for now (see the " Executing
  497. and Debugging from FLASH and IRAM" section above).
  498. To select this option, do 'make menuconfig'. Then you can find
  499. the selection under the "Board Selection" menu as "Run from IRAM".
  500. Configuration sub-directories
  501. -----------------------------
  502. nsh:
  503. Configures the NuttShell (nsh) located at apps/examples/nsh.
  504. NOTES:
  505. 1. Uses the CP2102 USB/Serial converter for the serial console.
  506. 2. I have only tested this in IRAM with UART reconfiguration disabled.
  507. See "Sample Debug Steps". In that case, NuttX is started via GDB.
  508. It has, however, been reported to me that this configuration also
  509. runs when written to address 0x1000 of FLASH with the esptool.py
  510. (as described above). Then NuttX is started via the second level
  511. bootloader. I cannot vouch for that since I have never tried it.
  512. 3. There are open clocking issues. Currently clock configuration
  513. logic is disabled because I don't have the technical information
  514. to provide that logic -- hopefully that is coming. As a
  515. consequence, whatever clock setup was left when NuttX started is
  516. used. For the case of execution out of IRAM with GDB, the
  517. settings in configs/esp32-core/include/board.h work. To check
  518. the timing, I use a stop watch and:
  519. nsh> sleep 60
  520. If the timing is correct in the board.h header file, the value
  521. timed with the stop watch should be about 60 seconds. If not,
  522. change the frequency in the board.h header file.
  523. smp:
  524. Another NSH configuration, similar to nsh, but also enables
  525. SMP operation. It differs from the nsh configuration only in these
  526. addtional settings:
  527. SMP is enabled:
  528. CONFIG_SMP=y
  529. CONFIG_SMP_IDLETHREAD_STACKSIZE=3072
  530. CONFIG_SMP_NCPUS=2
  531. CONFIG_SPINLOCK=y
  532. The apps/examples/smp test is included:
  533. CONFIG_EXAMPLES_SMP=y
  534. CONFIG_EXAMPLES_SMP_NBARRIER_THREADS=8
  535. CONFIG_EXAMPLES_SMP_PRIORITY=100
  536. CONFIG_EXAMPLES_SMP_STACKSIZE=2048
  537. NOTES:
  538. 1. See NOTES for the nsh configuration.
  539. ostest:
  540. This is the NuttX test at apps/examples/ostest that is run against all new
  541. architecture ports to assure a correct implementation of the OS. The default
  542. version is for a single CPU but can be modified for an SMP test by adding:
  543. CONFIG_SMP=y
  544. CONFIG_SMP_IDLETHREAD_STACKSIZE=2048
  545. CONFIG_SMP_NCPUS=2
  546. CONFIG_SPINLOCK=y
  547. NOTES:
  548. 1. See NOTES for the nsh configuration.
  549. 2. 2016-12-23: Test appears to be fully functional in the single CPU mode.
  550. 3. 2016-12-24: But when SMP is enabled, there is a consistent, repeatable
  551. crash in the waitpid() test. At the time of the crash, there is
  552. extensive memory corruption and a user exception occurrs (cause=28).
  553. Things to Do
  554. ============
  555. 1. There is no support for an interrupt stack yet.
  556. 2. There is no clock intialization logic in place. This depends on logic in
  557. Expressif libriaries. The board comes up using that basic 40 Mhz crystal
  558. for clocking. Getting to 80 MHz will require clocking initialization in
  559. esp32_clockconfig.c.
  560. 3. I did not implement the lazy co-processor save logic supported by Xtensa.
  561. That logic works like this:
  562. a. CPENABLE is set to zero on each context switch, disabling all co-
  563. processors.
  564. b. If/when the task attempts to use the disabled co-processor, an
  565. exception occurs
  566. c. The co-processor exception handler re-enables the co-processor.
  567. Instead, the NuttX logic saves and restores CPENABLE on each context
  568. switch. This has disadvantages in that (1) co-processor context will
  569. be saved and restored even if the co-processor was never used, and (2)
  570. tasks must explicitly enable and disable co-processors.
  571. 4. Currently the Xtensa port copies register state save information from
  572. the stack into the TCB. A more efficient alternative would be to just
  573. save a pointer to a register state save area in the TCB. This would
  574. add some complexity to signal handling and also also the
  575. up_initialstate(). But the performance improvement might be worth
  576. the effort.
  577. 5. See SMP-related issues above
  578. 6. See OpenOCD for the ESP32 above
  579. 7. Currently will not boot unless serial port initialization is disabled.
  580. This will use the serial port settings as left by the preceding
  581. bootloader:
  582. diff --git a/arch/xtensa/src/common/xtensa.h b/arch/xtensa/src/common/xtensa.h
  583. index 422ec0b..8707d7c 100644
  584. --- a/arch/xtensa/src/common/xtensa.h
  585. +++ b/arch/xtensa/src/common/xtensa.h
  586. @@ -60,7 +60,7 @@
  587. #undef CONFIG_SUPPRESS_INTERRUPTS /* DEFINED: Do not enable interrupts */
  588. #undef CONFIG_SUPPRESS_TIMER_INTS /* DEFINED: No timer */
  589. #undef CONFIG_SUPPRESS_SERIAL_INTS /* DEFINED: Console will poll */
  590. -#undef CONFIG_SUPPRESS_UART_CONFIG /* DEFINED: Do not reconfigure UART */
  591. +#define CONFIG_SUPPRESS_UART_CONFIG 1 /* DEFINED: Do not reconfigure UART */
  592. #define CONFIG_SUPPRESS_CLOCK_CONFIG 1 /* DEFINED: Do not reconfigure clocking */
  593. #undef CONFIG_DUMP_ON_EXIT /* DEFINED: Dump task state on exit */
  594. I have not debugged this in detail, but this appears to be an issue with the
  595. impelentation of esp32_configgpio() and/or gpio_matrix_out() when called from
  596. the setup logic in arch/xtensa/src/esp32/esp32_serial.c. I am not inclined
  597. to invest a lot in driver debug until the clock configuration is finalized.
  598. UPDATE: This may have been fixed with PR 457:
  599. https://bitbucket.org/nuttx/nuttx/pull-requests/457/
  600. fix-esp32-gpio-enable-reg-and-default-uart/diff
  601. That has not yet been verified.