Arduino Nano ESP32 Debugging Breakpoints

According to the Arduino Docs, it is possible to debug the Nano ESP32 (contrary to PlatformIO Docs) without any other hardware. I’ve managed to get it into debug mode using the jump GND > B1 + RST trick using the following config:

upload_protocol = esptool
debug_tool = esp-builtin

Unfortunately, it doesn’t seem to stop on any breakpoints, including the esp32/main.cpp mentioned in the log (below).

Using ‘pause’ does work, but seems to show a random callstack:

Any ideas what is going wrong?

Log:

Open On-Chip Debugger  v0.11.0-esp32-20220706 (2022-07-06-15:48)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
adapter speed: 40000 kHz

Warn : Transport "jtag" was already selected
adapter speed: 5000 kHz

Info : tcl server disabled
Info : telnet server disabled
Info : esp_usb_jtag: serial (74:4D:BD:7D:37:F4)
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
Info : clock speed 5000 kHz
Info : JTAG tap: esp32s3.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32s3.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : starting gdb server for esp32s3.cpu0 on pipe
Info : accepting 'gdb' connection from pipe
Info : [esp32s3.cpu0] Target halted, PC=0x40041A76, debug_reason=00000000
Info : Set GDB target to 'esp32s3.cpu0'
Info : [esp32s3.cpu1] Target halted, PC=0x40043A3B, debug_reason=00000000
Warn : No symbols for FreeRTOS!
Info : [esp32s3.cpu0] Target halted, PC=0x403B2482, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3c060020, 132 KB
Info : Flash mapping 1: 0x40020 -> 0x42000020, 355 KB
Info : [esp32s3.cpu0] Target halted, PC=0x403B2482, debug_reason=00000001
Info : Auto-detected flash bank 'esp32s3.cpu0.flash' size 16384 KB
Info : Using flash bank 'esp32s3.cpu0.flash' size 16384 KB
Info : [esp32s3.cpu0] Target halted, PC=0x403B2482, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3c060020, 132 KB
Info : Flash mapping 1: 0x40020 -> 0x42000020, 355 KB
Info : Using flash bank 'esp32s3.cpu0.irom' size 356 KB
Info : [esp32s3.cpu0] Target halted, PC=0x403B2482, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3c060020, 132 KB
Info : Flash mapping 1: 0x40020 -> 0x42000020, 355 KB
Info : Using flash bank 'esp32s3.cpu0.drom' size 136 KB
Info : New GDB Connection: 1, Target esp32s3.cpu0, state: halted
0x40041a76 in ?? ()
Error: FreeRTOS maximum used priority is unreasonably big, not proceeding: 130
Info : JTAG tap: esp32s3.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32s3.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
[esp32s3.cpu0] Debug controller was reset.
[esp32s3.cpu0] Core was reset.
Info : [esp32s3.cpu0] Target halted, PC=0x500000EF, debug_reason=00000000
[esp32s3.cpu0] Target halted, PC=0x500000EF, debug_reason=00000000
Info : [esp32s3.cpu1] requesting target halt and executing a soft reset
Info : [esp32s3.cpu0] Core was reset.
[esp32s3.cpu1] requesting target halt and executing a soft reset
[esp32s3.cpu0] Core was reset.
Info : [esp32s3.cpu0] Target halted, PC=0x40000400, debug_reason=00000000
Info : [esp32s3.cpu1] Debug controller was reset.
Info : [esp32s3.cpu1] Core was reset.
[esp32s3.cpu0] Target halted, PC=0x40000400, debug_reason=00000000
[esp32s3.cpu1] Debug controller was reset.
[esp32s3.cpu1] Core was reset.
Info : [esp32s3.cpu1] Target halted, PC=0x40000400, debug_reason=00000000
[esp32s3.cpu1] Target halted, PC=0x40000400, debug_reason=00000000
Hardware assisted breakpoint 1 at 0x42009b7c: file C:/Users/DanielSiviter/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp, line 56.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = thb app_main`
PlatformIO: More configuration options -> https://bit.ly/pio-debug
Note: automatically using hardware breakpoints for read-only addresses.

So since B1 is just GPIO0

it seems you’re just rebooting it into UART / Bootloader mode. So it won’t run the firmware, but bootloader code. These addresses in the callstack when you halt the debugger, 0x40041a76, that’s identified by the ESP32-S3 datasheet as being inside the “Internal ROM 1”.

Flash memory (where your firmware lives) would be in the instruction bus address range 0x4200_0000 to 0x43FF_FFFF.

Do you keep the B1 connected to GND all the time or only once to reboot into bootloader mode where the USB/JTAG controller is available? I think if PlatformIO / OpenOCD connects to the chip, uploads the firmware and triggers a CPU reset, the CPU will then run the bootloader again instead of the firmware, because B1 ↔ GND is still there. You should remove B1 ↔ GND connection again after the board was rebooted into bootloader mode.

To to clarify, steps:

  1. Connect B1>GND,
  2. Press RST,
  3. Remove B1>GND,
  4. USB now identifies as USB/JTAG USB port,
  5. Launch Debug with upload,
  6. It performs upload then the above log is shown.

I’ve not got the board in front of me at the moment, but I’ll put an expanded log when I do.

1 Like

As promised. Below is the log up until it stops at a stable state following the above steps.

Processing arduino_nano_esp32 (platform: espressif32; board: arduino_nano_esp32; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/arduino_nano_esp32.html
PLATFORM: Espressif 32 (6.9.0) > Arduino Nano ESP32
HARDWARE: ESP32S3 240MHz, 320KB RAM, 16MB Flash
DEBUG: Current (esp-builtin) External (cmsis-dap, dfu, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20017.241212+sha.dcc1105b
 - tool-dfuutil-arduino @ 1.11.0
 - tool-esptoolpy @ 1.40501.0 (4.5.1)
 - tool-mkfatfs @ 2.0.1
 - tool-mklittlefs @ 1.203.210628 (2.3)
 - tool-mkspiffs @ 2.230.0 (2.30)
 - tool-openocd-esp32 @ 2.1100.20220706 (11.0)
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 35 compatible libraries
Scanning dependencies...
Dependency Graph
|-- STM32duino ST25DV @ 2.1.2
|-- st25ftm @ 1.7.0
|-- Wire @ 2.0.0
Building in debug mode
Retrieving maximum program size .pio\build\arduino_nano_esp32\firmware.elf
Checking size .pio\build\arduino_nano_esp32\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  11.7% (used 38492 bytes from 327680 bytes)
Flash: [==        ]  18.3% (used 574901 bytes from 3145728 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, dfu, esp-bridge, esp-builtin, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: COM20
Uploading .pio\build\arduino_nano_esp32\firmware.bin
esptool.py v4.5.1
Serial port COM20
Connecting...
Chip is ESP32-S3 (revision v0.2)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 74:4d:bd:7d:37:f4
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00003fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x0009cfff...
Compressed 15104 bytes to 10429...
Writing at 0x00000000... (100 %)
Wrote 15104 bytes (10429 compressed) at 0x00000000 in 0.2 seconds (effective 491.2 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 158...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (158 compressed) at 0x00008000 in 0.0 seconds (effective 557.7 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 719.8 kbit/s)...
Hash of data verified.
Compressed 575264 bytes to 302951...
Writing at 0x00010000... (5 %)
Writing at 0x0001b715... (10 %)
Writing at 0x0002c714... (15 %)
Writing at 0x00037f15... (21 %)
Writing at 0x0003d625... (26 %)
Writing at 0x00043578... (31 %)
Writing at 0x0004929c... (36 %)
Writing at 0x0004eb0c... (42 %)
Writing at 0x00054144... (47 %)
Writing at 0x0005947d... (52 %)
Writing at 0x0005e774... (57 %)
Writing at 0x000654d1... (63 %)
Writing at 0x0006de42... (68 %)
Writing at 0x000753cc... (73 %)
Writing at 0x0007b6b1... (78 %)
Writing at 0x00081a08... (84 %)
Writing at 0x000895c8... (89 %)
Writing at 0x00092129... (94 %)
Writing at 0x000999f8... (100 %)
Wrote 575264 bytes (302951 compressed) at 0x00010000 in 4.1 seconds (effective 1122.5 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
========================= [SUCCESS] Took 14.00 seconds =========================

Environment         Status    Duration
------------------  --------  ------------
arduino_nano_esp32  SUCCESS   00:00:14.002
========================= 1 succeeded in 00:00:14.002 =========================
undefinedC:\Users\DanielSiviter\.platformio\packages\toolchain-xtensa-esp32s3\bin\xtensa-esp32s3-elf-gdb.exe: warning: Couldn't determine a path for the index cache directory.
Reading symbols from C:\Users\DanielSiviter\Develop\myapp\.pio\build\arduino_nano_esp32\firmware.elf...
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = esp-builtin
PlatformIO: Initializing remote target...
Open On-Chip Debugger  v0.11.0-esp32-20220706 (2022-07-06-15:48)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
adapter speed: 40000 kHz

Warn : Transport "jtag" was already selected
adapter speed: 5000 kHz

Info : tcl server disabled
Info : telnet server disabled
Info : esp_usb_jtag: serial (74:4D:BD:7D:37:F4)
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
Info : clock speed 5000 kHz
Info : JTAG tap: esp32s3.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32s3.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : [esp32s3.cpu0] Debug controller was reset.
Info : [esp32s3.cpu0] Core was reset.
Error: Unexpected OCD_ID = 00000000
Error: Unexpected OCD_ID = 00000000
Error: Unexpected OCD_ID = 00000000
Error: Unexpected OCD_ID = 00000000
Warn : target esp32s3.cpu1 examination failed
Error: Unexpected OCD_ID = 00000000
Error: Unexpected OCD_ID = 00000000
Info : starting gdb server for esp32s3.cpu0 on pipe
Info : accepting 'gdb' connection from pipe
Info : [esp32s3.cpu0] Target halted, PC=0x40041A76, debug_reason=00000000
Info : Set GDB target to 'esp32s3.cpu0'
Warn : No symbols for FreeRTOS!
Info : [esp32s3.cpu0] Target halted, PC=0x403B2482, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3c060020, 132 KB
Info : Flash mapping 1: 0x40020 -> 0x42000020, 356 KB
Info : [esp32s3.cpu0] Target halted, PC=0x403B2482, debug_reason=00000001
Info : Auto-detected flash bank 'esp32s3.cpu0.flash' size 16384 KB
Info : Using flash bank 'esp32s3.cpu0.flash' size 16384 KB
Info : [esp32s3.cpu0] Target halted, PC=0x403B2482, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3c060020, 132 KB
Info : Flash mapping 1: 0x40020 -> 0x42000020, 356 KB
Info : Using flash bank 'esp32s3.cpu0.irom' size 360 KB
Info : [esp32s3.cpu0] Target halted, PC=0x403B2482, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3c060020, 132 KB
Info : Flash mapping 1: 0x40020 -> 0x42000020, 356 KB
Info : Using flash bank 'esp32s3.cpu0.drom' size 136 KB
Info : New GDB Connection: 1, Target esp32s3.cpu0, state: halted
0x40041a76 in ?? ()
Error: FreeRTOS maximum used priority is unreasonably big, not proceeding: 130
Info : JTAG tap: esp32s3.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32s3.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32s3.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32s3.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Error: Unexpected OCD_ID = 00000000
Info : [esp32s3.cpu0] requesting target halt and executing a soft reset
Unexpected OCD_ID = 00000000
[esp32s3.cpu0] requesting target halt and executing a soft reset
Info : [esp32s3.cpu0] Debug controller was reset.
Info : [esp32s3.cpu0] Core was reset.
[esp32s3.cpu0] Debug controller was reset.
[esp32s3.cpu0] Core was reset.
Info : [esp32s3.cpu0] Target halted, PC=0x500000EF, debug_reason=00000000
[esp32s3.cpu0] Target halted, PC=0x500000EF, debug_reason=00000000
Info : [esp32s3.cpu1] requesting target halt and executing a soft reset
Error: Target not examined yet
Info : [esp32s3.cpu0] Core was reset.
[esp32s3.cpu1] requesting target halt and executing a soft reset
Target not examined yet
[esp32s3.cpu0] Core was reset.
Info : [esp32s3.cpu0] Target halted, PC=0x40000400, debug_reason=00000000
Info : [esp32s3.cpu1] Debug controller was reset.
Info : [esp32s3.cpu1] Core was reset.
[esp32s3.cpu0] Target halted, PC=0x40000400, debug_reason=00000000
[esp32s3.cpu1] Debug controller was reset.
[esp32s3.cpu1] Core was reset.
Info : [esp32s3.cpu1] Target halted, PC=0x40000400, debug_reason=00000000
[esp32s3.cpu1] Target halted, PC=0x40000400, debug_reason=00000000
Hardware assisted breakpoint 1 at 0x42009ea4: file C:/Users/DanielSiviter/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp, line 56.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = thb app_main`
PlatformIO: More configuration options -> https://bit.ly/pio-debug
Note: automatically using hardware breakpoints for read-only addresses.

The log states it should run till thb app_main but that does not seem to happen. The device is still showing ‘purple’ LED. I cannot get debug to launch in any other way.

Having got some assistance in the Arduino community it seems a physical press of the RESET button was is required and the USB still identifies as USB JTAG/serial debug unit after compiling with ‘Debug mode (Hardware CDC)’. So after some searching, I found this after adding this and restarting debugging… Voilà!

So, to help others, use the following config:

[env]
framework = arduino
platform = espressif32
board = arduino_nano_esp32
upload_protocol = esptool
debug_tool = esp-builtin
build_flags =
	-D ARDUINO_USB_MODE=1
	-D ARDUINO_USB_CDC_ON_BOOT=1

Then reset using B1+GND, then run debug. An extra physical press of RESET wasn’t needed.