esp32jtag

ESP32 debugging using ESP32-S3 dev board


I am trying to get ESP32 debugging working using a ESP-PROG board together with an ESP32-S3 dev board.

I am using VSCode with IDF ver 5.3. I have tried following a few guides and videos but they are a little different and some are out of date.

So far:

I have connected up the JTAG interface pins from the debug board to the ESP32-S3 as follows.

Debug board                  ESP32-S3
TDI --------------------------GPIO41 pin 41
TDO ------------------------GPIO40 pin 40
TCK-------------------------GPIO39 pin 39
TMS-------------------------GPIO42 pin 42
VJTAG----------------------3v3

I used Zadig to update my drivers for the dual RS-232 0

Windows device manager shows: Under Ports (COM & LPT) USB Serial CH343 (COM19) USB Serial Port (COM20)

and under USB Devices DUAL RS232-HS

In a terminal I run:

PS ...> openocd --version
Open On-Chip Debugger v0.12.0-esp32-20240318 (2024-03-18-18:26)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html

But when I run:

PS ...>openocd -f board/esp32s3-builtin.cfg
Open On-Chip Debugger v0.12.0-esp32-20240318 (2024-03-18-18:26)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselecting 'jtag'
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: esp_usb_jtag: could not find or open device!
C:\Users\micha\.espressif\tools\openocd-esp32\v0.12.0-esp32-20240318/openocd-esp32/share/openocd/scripts/target/esp_common.cfg:9: Error:
at file "C:\Users\micha\.espressif\tools\openocd-esp32\v0.12.0-esp32-20240318/openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 9

I just found a note stating: Use the ESP-IDF Debug Adapter

DEPRECATED NOTICE: We are deprecating the use of our ESP-IDF Debug Adapter in favor of using the Eclipse CDT GDB Adapter. It will removed from extension in the future major release.

I burned the STRAP_JTAG_SEL fuse as follows:

python -m espefuse -p com19 burn_efuse STRAP_JTAG_SEL 1
espefuse.py v4.8.dev4
Connecting...
Failed to get PID of a device on com19, using standard reset sequence.
.
Detecting chip type... ESP32-S3

=== Run "burn_efuse" command ===
The efuses to burn:
  from BLOCK0
     - STRAP_JTAG_SEL

Burning efuses:

    - 'STRAP_JTAG_SEL' (Set this bit to enable selection between usb_to_jtag and pad_to_jtag through strapping gpio10 when both reg_dis_usb_jtag and reg_dis_pad_jtag 
are equal to 0) 0b0 -> 0b1


Check all blocks for burn...
idx, BLOCK_NAME,          Conclusion
[00] BLOCK0               is not empty
        (written ): 0x0000000000000100000000000000d1f50001000000000000
        (to write): 0x000000000000000001000000000000000000000000000000
        (coding scheme = NONE)
.
This is an irreversible operation!
Type 'BURN' (all capitals) to continue.
BURN
BURN BLOCK0  - OK (all write block bits are set)
Reading updated efuses...
Checking efuses...
Successful

=================================================================

I put aside the ESP-Prog board for now and switched to the ESP32-S3 integrated JTag.

I have connected it and can run:

openocd -f board/esp32s3-builtin.cfg
Open On-Chip Debugger v0.12.0-esp32-20240318 (2024-03-18-18:26)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselecting 'jtag'
Info : esp_usb_jtag: VID set to 0x303a and PID to 0x1001
Info : esp_usb_jtag: capabilities descriptor set to 0x2000
Info : Listening on port 6666 for tcl connections   
Info : Listening on port 4444 for telnet connections
Info : esp_usb_jtag: serial (48:CA:43:9B:54:C0)
Info : esp_usb_jtag: Device found. Base speed 40000KHz, div range 1 to 255
Info : clock speed 40000 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] Examination succeed
Info : [esp32s3.cpu1] Examination succeed
Info : starting gdb server for esp32s3.cpu0 on 3333
Info : Listening on port 3333 for gdb connections  
Info : [esp32s3.cpu0] Debug controller was reset.
Info : [esp32s3.cpu0] Core was reset.
Info : [esp32s3.cpu1] Debug controller was reset.
Info : [esp32s3.cpu1] Core was reset.
Info : [esp32s3.cpu0] Target halted, PC=0x4037ABDE, debug_reason=00000000
Info : [esp32s3.cpu0] Reset cause (1) - (Power on reset)
Info : [esp32s3.cpu1] Target halted, PC=0x4037ABDE, debug_reason=00000000
Info : [esp32s3.cpu1] Reset cause (1) - (Power on reset)

I can't find Espressif docs covering use in VSCode (only Eclipse) so I thought I should start with Command Line following: https://docs.espressif.com/projects/esp-idf/en/stable/esp32s3/api-guides/jtag-debugging/using-debugger.html#jtag-debugging-using-debugger-command-line

xtensa-esp32s3-elf-gdb -x gdbinit build/blink.elf
GNU gdb (esp-gdb) 14.2_20240403
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-w64-mingw32 --target=xtensa-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from build/blink.elf...

warning: could not convert 'main' from the host encoding (CP1252) to UTF-32.
This normally should not happen, please file a bug report.
gdbinit: No such file or directory.
(gdb) 

Solution

  • Fuses for JTAG

    Note that you don't need an external ESP-Prog, ESP32S3 has a built in USB-JTAG interface which it uses by default. Cut open a standard USB cable and connect it to the pins listed in this article.

    If you really wish to use ESP-Prog for debugging, you need to re-route the JTAG interface (as it's routed to USB-JTAG by default). This is a permanent change and cannot be reverted.

    espefuse --port COM19 burn_efuse DIS_USB_JTAG
    

    Alternatively you can also leave it configurable by GPIO3 if you burn fuse STRAP_JTAG_SEL instead.

    See this page for details: https://docs.espressif.com/projects/esp-idf/en/v5.3/esp32s3/api-guides/jtag-debugging/configure-other-jtag.html

    OpenOCD configuration

    The debug configuration board/esp32s3-builtin.cfg that you've chosen describes the "built-in" USB-JTAG interface which you just disabled. If you're using an ESP-Prog, you need to pick its configuration instead. The directory espressif/bin/tools/openocd-esp32/v0.12.0-esp32-20230921/openocd-esp32/share/openocd/scripts/board holds a file esp32s3-ftdi.cfg which describes itself as:

    # Example OpenOCD configuration file for ESP32-S3 connected via ESP-Prog.
    #
    # For example, OpenOCD can be started for ESP32-S3 debugging on
    #
    #   openocd -f board/esp32s3-ftdi.cfg
    #
    
    # Source the JTAG interface configuration file
    source [find interface/ftdi/esp32_devkitj_v1.cfg]
    # Source the ESP32-S3 configuration file
    source [find target/esp32s3.cfg]
    

    So try that instead.