XIAO ESP32C3 debugging

I am trying to debug XIAO ESP32C3, and I face the Error: Failed to get flash maps (4294967295)!

My PC under Linux is connected directly to XIAO ESP32C3 via USB cable, I am not using any external JTAG adapter.

1/ I successfully upload my program to the target
I use default configuration for platformio.ini :
[env:seeed_xiao_esp32c3]
platform = espressif32
board = seeed_xiao_esp32c3
framework = arduino

2/ I do not succeed to start debugger, OpenOCD fails to get flash maps

Content of platformio.ini :
[env:seeed_xiao_esp32c3]
platform = espressif32
board = seeed_xiao_esp32c3
framework = arduino
debug_tool = custom
debug_server =
$PLATFORMIO_CORE_DIR/packages/tool-openocd-esp32/bin/openocd
-f
$PLATFORMIO_CORE_DIR/packages/tool-openocd-esp32/share/openocd/scripts/board/esp32c3-builtin.cfg

Reading symbols from /home/xxx/Documents/PlatformIO/Projects/ESP32-C3-LED/.pio/build/seeed_xiao_esp32c3/firmware.elf…
PlatformIO Unified Debugger → Redirecting...
PlatformIO: debug_tool = custom
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
OpenOCD: Bug Reporting
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
Warn : Transport “jtag” was already selected
adapter speed: 5000 kHz

Info : tcl server disabled
Info : telnet server disabled
Info : esp_usb_jtag: serial (D4:F9:8D:03:EF:80)
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
Info : clock speed 5000 kHz
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : datacount=2 progbufsize=16
Info : Examined RISC-V core; found 1 harts
Info : hart 0: XLEN=32, misa=0x40101104
Info : starting gdb server for esp32c3 on pipe
Info : accepting ‘gdb’ connection from pipe
Memory protection is enabled. Reset target to disable it…
Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Info : Reset cause (3) - (Software core reset)
Warn : No symbols for FreeRTOS!
Info : [esp32c3] Found 8 triggers
Error: Failed to get flash maps (4294967295)!
Warn : Failed to get flash mappings (-4)!
Error: Failed to get flash size!
Error: Failed to get flash size!
Error: Failed to probe flash, size 0 KB
Error: auto_probe failed
Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use ‘gdb_memory_map disable’.
Error: attempted ‘gdb’ connection rejected

I see in the documentation: “Seeed Studio XIAO ESP32C3 does not have on-board debug probe and IS NOT READY for debugging. You will need to use/buy one of external probe listed below.” I am not sure to understand this information since ESP32C3 has on-board debugging facilities since v0.3.

I am using PlatformIO 6.1.9

adding the option gdb_memory_map disable to OpenOCD seems to work.
Here is the content of platformio.ini that works :
[env:seeed_xiao_esp32c3]
platform = espressif32
board = seeed_xiao_esp32c3
framework = arduino
debug_tool = esp-builtin
debug_init_break = tbreak setup
debug_server =
$PLATFORMIO_CORE_DIR/packages/tool-openocd-esp32/bin/openocd
-f
$PLATFORMIO_CORE_DIR/packages/tool-openocd-esp32/share/openocd/scripts/board/esp32c3-builtin.cfg
-c
gdb_memory_map disable

I couldn’t, neither debug nor upload, here

debug_level: 1

adapter speed: 40000 kHz

Warn : Transport “jtag” was already selected
adapter speed: 5000 kHz

Error: esp_usb_jtag: could not find or open device!
** OpenOCD init failed **
shutdown command invoked

Error: Unsupported xlen: -1
Error: Unknown target arch!
*** [upload] Error 1

platformio.ini:

build_type = debug ; release

debug_tool = esp-builtin

debug_init_break = tbreak setup

debug_server =

${platformio.packages_dir}/tool-openocd-esp32/bin/openocd -f

${platformio.packages_dir}/tool-openocd-esp32/share/openocd/scripts/board/esp32c3-builtin.cfg -c gdb_memory_map disable

Does not work 100%, GDB does not work very well (I face issues to setup breakpoints and to do step by step)…

In the command line version that I detail in my tutorial, I found that instead of using command “gdb_memory_map disable”, it is better to use command “set ESP_FLASH_SIZE 0”.
But I am not able to use this command properly in platformio.ini file…

Help would be appreciated :slight_smile:

I finally succeeded to make it run!

Using “gdb_memory_map disable” or " set ESP_FLASH_SIZE 0" commands are not very efficient workarounds.

Solution is to set pin GPIO8 at HIGH state during boot…

I explain all steps in my tutorial

1 Like