Open bobh opened 2 years ago
The USB Debugging interface is described in 21.3 of https://www.espressif.com/sites/default ... #iomuxgpio Mostly it's blah, blah, blah but of interest: ... which may happen in Light Sleep. Additionally, the USB serial/JTAG Controller (as well as the attached RISC-V CPU) will be entirely powered down in Deep Sleep mode. If a device needs to be debugged in either of these two modes, it may be preferable to use an external JTAG debugger and serial interface instead.
More information: Espressif implements an integrated USB Serial/JTAG Controller per risc-v debug specification 0.13. Which the SiFive HiFive board, which PlatformIO supports, may also implement as it also supports USB debugging. Also, the additional USB connector I show is not strictly necessary as the DevKit supports changing the orientation of two 0 ohm resistors to switch from UART to GPIO18/19. However the SMD parts are small and the rework difficult for students.
Is there any news on this? Or any ideas on how this support can be added?
No. Not that I’m aware of. I’ve been using the latest esp_idf and gdb/OCD.
gotcha. @maxgerhardt, any input from your side on what would need to be done and how to get started?
Can someone show the OpenOCD and GDB invocations for connecting to the debug probe opened by the C3 board? Does the C3 board has to have a special sketch running that exposes that USB device?
according to espressif no:
USB console feature can be enabled using CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG option in menuconfig tool (see CONFIG_ESP_CONSOLE_UART).
I have no expertise in this area, but i have a devkit on hand and if you guide me I can try collect any info you need.
Well as a first step you should try and create an ESP-IDF project with PlatformIO for the ESP32-C3 that enables this option (CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
) and check if a JTAG-y looking USB device appears on your computer. (Let's not do this in Arduino-ESP32 because it has that option disabled).
Per https://github.com/platformio/platform-espressif32/blob/d93c9ef8f661106604c6b5e333b296ddb3dbc8eb/boards/esp32-c3-devkitm-1.json#L19-L21 the board supports ESP-IDF in this platform version here. Can you create a standard ESP-IDF blinky project as in https://github.com/platformio/platform-espressif32/tree/develop/examples/espidf-blink and enable the above option in the menuconfig and compile & flash that and see what USB devices appear?
On Mar 8, 2022, at 10:30 AM, Maximilian Gerhardt @.***> wrote:
Can someone show the OpenOCD and GDB invocations for connecting to the debug probe opened by the C3 board? Does the C3 board has to have a special sketch running that exposes that USB device?
No special sketch. This is on a Mac but probably the same as Linux Three command line windows are used. Don’t ssh.
Hardware: https://dspobjects.com/2021/10/20/esp32-c3-dev-kit-in-circuit-debugging/ https://dspobjects.com/2021/10/20/esp32-c3-dev-kit-in-circuit-debugging/
C3 — S3 similar Window #1 openocd server get_idf /Users/bobh/.espressif/tools/openocd-esp32/v0.10.0-esp32-20210902/openocd-esp32/bin/openocd -f board/esp32c3-builtin.cfg
+++++++++++++++ Open On-Chip Debugger v0.10.0-esp32-20210902 (2021-09-02-09:38) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : only one transport option; autoselect 'jtag' Warn : Transport "jtag" was already selected Info : Listening on port 6666 for tcl connections Info : Listening on port 4444 for telnet connections Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255 Info : clock speed 40000 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 : [0] Found 8 triggers Info : Listening on port 3333 for gdb connections +++++++++++++++
This is how you kill the server when it crashes: lsof -i :6666
Window #2 build/flash application cd ~/esp/blink get_idf idf.py set-target esp32c3 ls /dev/tty* idf.py -p /dev/ttyACM0 build monitor ++++++++++++++++++++++++++++++ Info : Hart 0 unexpectedly reset Info : Hart 0 unexpectedly reset Info : accepting 'gdb' connection on tcp/3333 Warn : No symbols for FreeRTOS! Info : Flash mapping 0: 0x10020 -> 0x3c020020, 30 KB Info : Flash mapping 1: 0x20020 -> 0x42000020, 95 KB Info : Auto-detected flash bank 'esp32c3.flash' size 4096 KB Info : Using flash bank 'esp32c3.flash' size 4096 KB Info : Flash mapping 0: 0x10020 -> 0x3c020020, 30 KB Info : Flash mapping 1: 0x20020 -> 0x42000020, 95 KB Info : Using flash bank 'esp32c3.irom' size 96 KB Info : Flash mapping 0: 0x10020 -> 0x3c020020, 30 KB Info : Flash mapping 1: 0x20020 -> 0x42000020, 95 KB Info : Using flash bank 'esp32c3.drom' size 32 KB Info : JTAG tap: esp32c3.cpu tap/device found: 0x00005c25 (mfg: 0x612 (Espressif Systems), part: 0x0005, ver: 0x0)
Window #3 run gdb prepare gdbinit file cd ~/esp/blink get_idf xtensa-esp32-elf-gdb -x gdbinit build/blink.elf
Reading symbols from build/blink.elf... 0x403ce000 in ?? () Hardware assisted breakpoint 1 at 0x420053da: file ../main/blink_example_main.c, line 74. [New Thread 1070139412] [New Thread 1070134560] [Switching to Thread 1070139068]
Thread 1 hit Temporary breakpoint 1, app_main () at ../main/blink_example_main.c:74
--Type
Why was this issue closed? Did I overlook a solution somewhere?
Sorry. Was closing another issue.
ESP32C3 + Arduino debugging in PlatformIO has been achieved with some workarounds in this thread: https://community.platformio.org/t/esp32c3-debugging/26940/46?u=maxgerhardt
Basically, put the board in DFU bootloader mode, Use https://zadig.akeo.ie/ to load libusbK driveres for the "USB JTAG/serial debug unit (interface 2)" device, add
debug_tool = custom
debug_server =
debug_port = localhost:3333
debug_init_break = break loop
to your platformio.ini
, upload the firmware once as normal, then in a new CLI, do pio upgrade --dev
and pio pkg exec -p tool-openocd-esp32 -c "openocd -f board/esp32c3-builtin.cfg"
to start the OpenOCD server, then in the left Debug panel in VSCode chose the "PIO Debug (without upload)" option and start it. At least that's how I understand it.
@maxgerhardt Thank you for your attention. I will mark this issue as closed.
thanks @maxgerhardt for the hint!
But to be honest I would not consider this problem to be fixed/resolved just because there is a (hacky or at least manual) workaround. I understand that this might reduce priority to fix this issue properly but should we not keep this issue open? What do you think?
Indeed a cleaner fix would be to have it supported out-of-the-box here. Reopen? :D
Reopened. lol I’ve moved on but someone might benefit. bobh
This issue deals specifically with ESP32-C3-DevKitM-1 board but boards such as the M5STAMP C3U are appearing without the USB download chip. C3’s USB CDC is enabled by esp-idf’s menuconfig or the Arduino IDE tools menu item. But I haven’t gotten OCD/GDB working with that board yet. So I no hurry. ;-)
I have been having this issue all weekend using VScode trying to debug ESP32C3 Devkit v2.
OS: Windows 11
Here is the log from my openOCD launch attempt.
Open On-Chip Debugger v0.11.0-esp32-20211220 (2021-12-20-15:43)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
User : 13 3 options.c:63 configuration_output_handler(): debug_level: 3
User : 14 8 options.c:63 configuration_output_handler():
Debug: 15 11 options.c:244 add_default_dirs(): bindir=/builds/idf/openocd-esp32/_build/../openocd-esp32/bin
Debug: 16 16 options.c:245 add_default_dirs(): pkgdatadir=/builds/idf/openocd-esp32/_build/../openocd-esp32/share/openocd
Debug: 17 22 options.c:246 add_default_dirs(): exepath=C:/Espressif/tools/openocd-esp32/v0.11.0-esp32-20211220/openocd-esp32/bin
Debug: 18 31 options.c:247 add_default_dirs(): bin2data=../share/openocd
Debug: 19 35 configuration.c:42 add_script_search_dir(): adding C:\Espressif\tools\openocd-esp32\v0.11.0-esp32-20211220/openocd-esp32/share/openocd/scripts
Debug: 20 45 configuration.c:42 add_script_search_dir(): adding C:/Users/leksy/AppData/Roaming/OpenOCD
Debug: 21 53 configuration.c:42 add_script_search_dir(): adding C:/Espressif/tools/openocd-esp32/v0.11.0-esp32-20211220/openocd-esp32/bin/../share/openocd/site
Debug: 22 67 configuration.c:42 add_script_search_dir(): adding C:/Espressif/tools/openocd-esp32/v0.11.0-esp32-20211220/openocd-esp32/bin/../share/openocd/scripts
Debug: 23 77 configuration.c:97 find_file(): found C:\Espressif\tools\openocd-esp32\v0.11.0-esp32-20211220/openocd-esp32/share/openocd/scripts/board/esp32c3-builtin.cfg
Debug: 24 86 configuration.c:97 find_file(): found C:\Espressif\tools\openocd-esp32\v0.11.0-esp32-20211220/openocd-esp32/share/openocd/scripts/interface/esp_usb_jtag.cfg
Debug: 25 95 command.c:146 script_debug(): command - adapter driver esp_usb_jtag
Info : 27 101 transport.c:117 allow_transports(): only one transport option; autoselect 'jtag'
Debug: 28 106 command.c:146 script_debug(): command - espusbjtag vid_pid 0x303a 0x1001
Info : 30 110 esp_usb_jtag.c:899 esp_usb_jtag_vid_pid(): esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Debug: 31 118 command.c:146 script_debug(): command - espusbjtag caps_descriptor 0x2000
Info : 33 125 esp_usb_jtag.c:912 esp_usb_jtag_caps_descriptor(): esp_usb_jtag: capabilities descriptor set to 0x2000
Debug: 34 133 command.c:146 script_debug(): command - adapter speed 40000
Debug: 36 136 core.c:1822 jtag_config_khz(): handle jtag khz
Debug: 37 139 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 38 144 core.c:1785 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 39 151 configuration.c:97 find_file(): found C:\Espressif\tools\openocd-esp32\v0.11.0-esp32-20211220/openocd-esp32/share/openocd/scripts/target/esp32c3.cfg
Debug: 40 160 command.c:146 script_debug(): command - transport select jtag
Warn : 41 164 transport.c:286 jim_transport_select(): Transport "jtag" was already selected
Debug: 42 169 configuration.c:97 find_file(): found C:\Espressif\tools\openocd-esp32\v0.11.0-esp32-20211220/openocd-esp32/share/openocd/scripts/bitsbytes.tcl
Debug: 43 176 configuration.c:97 find_file(): found C:\Espressif\tools\openocd-esp32\v0.11.0-esp32-20211220/openocd-esp32/share/openocd/scripts/memory.tcl
Debug: 44 187 configuration.c:97 find_file(): found C:\Espressif\tools\openocd-esp32\v0.11.0-esp32-20211220/openocd-esp32/share/openocd/scripts/mmr_helpers.tcl
Debug: 45 195 configuration.c:97 find_file(): found C:\Espressif\tools\openocd-esp32\v0.11.0-esp32-20211220/openocd-esp32/share/openocd/scripts/target/esp_common.cfg
Debug: 46 204 command.c:146 script_debug(): command - add_help_text program_esp write an image to flash, address is only required for binary images. verify, reset, exit, compress, restore_clock are optional
Debug: 48 219 command.c:1115 help_add_command(): added 'program_esp' help text
Debug: 49 225 command.c:146 script_debug(): command - add_usage_text program_esp [address] [verify] [reset] [exit] [compress] [restore_clock]
Debug: 51 234 command.c:1141 help_add_command(): added 'program_esp' usage text
Debug: 52 238 command.c:146 script_debug(): command - add_help_text program_esp_bins write all the images at address specified in flasher_args.json generated while building idf project
Debug: 54 249 command.c:1115 help_add_command(): added 'program_esp_bins' help text
Debug: 55 253 command.c:146 script_debug(): command - add_usage_text program_esp_bins
Debug: 77 387 command.c:146 script_debug(): command - esp32c3 configure -event examine-end
arm semihosting enable arm semihosting_resexit enable
Debug: 78 405 command.c:146 script_debug(): command - esp32c3 configure -event gdb-attach
halt if { [esp32c3_memprot_is_enabled] } {
echo "Memory protection is enabled. Reset target to disable it..." reset halt }
riscv maskisr steponly
Debug: 79 448 command.c:146 script_debug(): command - esp32c3 configure -work-area-phys 0x40380000 -work-area-virt 0x40380000 -work-area-size 0x4000 -work-area-backup 1 Debug: 80 464 target.c:2218 target_free_all_working_areas_restore(): freeing all working areas Debug: 81 473 target.c:2218 target_free_all_working_areas_restore(): freeing all working areas Debug: 82 484 target.c:2218 target_free_all_working_areas_restore(): freeing all working areas Debug: 83 494 target.c:2218 target_free_all_working_areas_restore(): freeing all working areas Debug: 84 504 command.c:146 script_debug(): command - esp32c3 configure -alt-work-area-phys 0x3FC84000 -alt-work-area-virt 0x3FC84000 -alt-work-area-size 0x20000 -alt-work-area-backup 1 Debug: 85 519 target.c:2218 target_free_all_working_areas_restore(): freeing all working areas Debug: 86 527 target.c:2218 target_free_all_working_areas_restore(): freeing all working areas Debug: 87 533 target.c:2218 target_free_all_working_areas_restore(): freeing all working areas Debug: 88 544 target.c:2218 target_free_all_working_areas_restore(): freeing all working areas Debug: 89 552 command.c:146 script_debug(): command - flash bank esp32c3.flash esp32c3 0x0 0 0 0 esp32c3 Debug: 92 561 command.c:376 register_command(): command 'esp' is already registered in '' context Debug: 93 568 tcl.c:1319 handle_flash_bank_command(): 'esp32c3' driver usage field missing Debug: 94 576 command.c:146 script_debug(): command - flash bank esp32c3.irom esp32c3 0x0 0 0 0 esp32c3 Debug: 96 584 command.c:376 register_command(): command 'esp' is already registered in '' context Debug: 97 592 command.c:376 register_command(): command 'appimage_offset' is already registered in 'esp' context Debug: 98 601 command.c:376 register_command(): command 'compression' is already registered in 'esp' context Debug: 99 608 command.c:376 register_command(): command 'verify_bank_hash' is already registered in 'esp' context Debug: 100 614 command.c:376 register_command(): command 'flash_stub_clock_boost' is already registered in 'esp' context Debug: 101 623 tcl.c:1319 handle_flash_bank_command(): 'esp32c3' driver usage field missing Debug: 102 630 command.c:146 script_debug(): command - flash bank esp32c3.drom esp32c3 0x0 0 0 0 esp32c3 Debug: 104 640 command.c:376 register_command(): command 'esp' is already registered in '' context Debug: 105 648 command.c:376 register_command(): command 'appimage_offset' is already registered in 'esp' context Debug: 106 660 command.c:376 register_command(): command 'compression' is already registered in 'esp' context Debug: 107 666 command.c:376 register_command(): command 'verify_bank_hash' is already registered in 'esp' context Debug: 108 674 command.c:376 register_command(): command 'flash_stub_clock_boost' is already registered in 'esp' context Debug: 109 685 tcl.c:1319 handle_flash_bank_command(): 'esp32c3' driver usage field missing Debug: 110 696 command.c:146 script_debug(): command - riscv set_reset_timeout_sec 2 Debug: 112 704 command.c:146 script_debug(): command - riscv set_command_timeout_sec 5 Debug: 114 710 command.c:146 script_debug(): command - riscv set_prefer_sba on Info : 116 720 server.c:312 add_service(): Listening on port 6666 for tcl connections Info : 117 727 server.c:312 add_service(): Listening on port 4444 for telnet connections Debug: 118 750 command.c:146 script_debug(): command - init Debug: 120 758 command.c:146 script_debug(): command - target init Debug: 122 763 command.c:146 script_debug(): command - target names Debug: 123 770 command.c:146 script_debug(): command - esp32c3 cget -event gdb-flash-erase-start Debug: 124 780 command.c:146 script_debug(): command - esp32c3 configure -event gdb-flash-erase-start reset init Debug: 125 787 command.c:146 script_debug(): command - esp32c3 cget -event gdb-flash-write-end Debug: 126 795 command.c:146 script_debug(): command - esp32c3 configure -event gdb-flash-write-end reset halt Debug: 127 802 command.c:146 script_debug(): command - esp32c3 cget -event gdb-attach Debug: 128 811 target.c:1661 handle_target_init_command(): Initializing targets... Debug: 129 817 esp32c3.c:125 esp32c3_init_target(): enter Debug: 130 839 semihosting_common.c:100 semihosting_common_init(): Error: 131 883 esp_usb_jtag.c:662 esp_usb_jtag_init(): esp_usb_jtag: could not find or open device! Debug: 132 891 command.c:629 run_command(): Command 'init' failed with error code -4 User : 133 896 command.c:694 command_run_line(): Debug: 134 902 riscv.c:483 riscv_deinit_target(): riscv_deinit_target() Debug: 135 909 riscv-013.c:1543 deinit_target(): riscv_deinit_target() Debug: 136 918 target.c:2218 target_free_all_working_areas_restore(): freeing all working areas
@maxgerhardt i tried some of your suggestions but at least on macos, I havent been lucky to get a openocd response yet this is my ini file:
[env:esp32-s3-devkitc-1]
platform = espressif32
framework = arduino
build_type = debug
build_unflags =
-D ARDUINO_USB_MODE=1
build_flags =
-D ARDUINO_USB_MODE=0
-D ARDUINO_USB_CDC_ON_BOOT=0
-D ARDUINO_USB_MSC_ON_BOOT=0
-D ARDUINO_USB_DFU_ON_BOOT=0
upload_protocol = esptool
debug_tool = esp-builtin
debug_server =
$PLATFORMIO_CORE_DIR/packages/tool-openocd-esp32/bin/openocd
-f
$PLATFORMIO_CORE_DIR/packages/tool-openocd-esp32/share/openocd/scripts/board/esp32s3-builtin.cfg
debug_init_break = tbreak setup
board = esp32-s3-devkitc-1
monitor_speed = 115200
board_build.partitions = partitions_workaround.csv
board_build.f_cpu = 240000000L
board_build.arduino.memory_type = qio_opi
board_build.flash_freq = 80m
board_upload.flash_size = 16MB
board_build.flash_mode = dio
board_build.boot = qio
board_build.flash_type = qio
board_build.psram_type = opi
board_build.memory_type = qio_opi
board_build.boot_freq = 80m
upload_port = /dev/tty.w
upload_speed = 460800
lib_extra_dirs = ~/Documents/Arduino/libraries
I heard that for ESP32-S3 the same steps should apply, but I havent been lucky yet, is there a project already provisioned to run as debug?
Well as a first step you should try and create an ESP-IDF project with PlatformIO for the ESP32-C3 that enables this option (
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
) and check if a JTAG-y looking USB device appears on your computer. (Let's not do this in Arduino-ESP32 because it has that option disabled).Per
the board supports ESP-IDF in this platform version here. Can you create a standard ESP-IDF blinky project as in https://github.com/platformio/platform-espressif32/tree/develop/examples/espidf-blink and enable the above option in the menuconfig and compile & flash that and see what USB devices appear?
You sir, are one of my new favorite people. Yesterday I spent all day debugging with print statements... Today we have a debugger working :)
PlatformIO documentation: "Espressif ESP32-C3-DevKitM-1 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."
Actually, the ESP32-C3-DevKitM-1 has a built-in USB debugger. Wire in a USB breakout such as Digi-Key 1568-1958-ND per the diagram GPIO18 D- GPIO19 D+ VCC and GND. Leave the on-board USB connector unused. This works on Ubuntu 20, VSCode and with manually installing the Espressif tools. Actually, I’m not sure how is works. But Flashing, openocd debug and all work.
But not with PlatformIO
My example of protoboard wiring: https://dspobjects.com/2021/10/20/esp32-c3-dev-kit-in-circuit-debugging/ Espressif Documentation: https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-guides/usb-serial-jtag-console.html