JTAG-Debugging with ESP32-WROOM-32UE

I have been using PlatformIO for a while now to program and debug ESP32-WROOM-32U chips. As the programmer/debugger I am using the official ESP-Prog by espressif, which always worked great for me. However, I have recently started experimenting with ESP32-WROOM-32UE chips, which are now recommended by espressif for new projects. Flashing still works great through PlatformIO, but I can’t get the debugger to work anymore. I’m always seeing these two error messages:

error

In the console, I’m getting the following output (with the first 7 lines repeating a couple hundred times):

Error: xtensa_poll: Target failure
Error: xtensa_poll: Target failure
Error: xtensa_poll: Target failure
Error: xtensa_poll: Target failure
xtensa_poll: Target failure
xtensa_poll: Target failure
xtensa_poll: Target failure
.pioinit:13: Error in sourced command file:
Remote communication error. Target disconnected.: No error.

I don’t think there is anything wrong with my electrical connections, because the two U-chip works fine - just the UE doesn’t. And both chips should have an identical pinout, according to espressif. Could it be my platform.ini? I have set up the project like this:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
debug_tool = esp-prog
debug_init_break =
upload_port = COM4
monitor_speed = 115200
board_build.partitions = noota_3g.csv

I would be super grateful for any tips on how to get the debugger to work with the new chip!

Can you manually connect to the chip by using the latest esp32 openocd version (Release v0.10.0-esp32-20200709 · espressif/openocd-esp32 · GitHub) on the commandline?

I just tried that and it worked just fine. These are the commands that I have used:

Terminal 1: openocd -f board/esp32-wrover-kit-3.3v.cfg
Terminal 2: xtensa-esp32-elf-gdb -x gdbinit “.pio/build/esp32dev/firmware.elf”

The connection is established as expected and the debugger halts at a temporary breakpoint. It still does not work throuhg PlatformIO, though.

Weird that the config for a wrover kit works for ESP32-WROOM-32UE. Anways since you have selected board = esp32dev, the used openocd config file will be

Which may not be what you want. You can set board = esp-wrover-kit since that will give you

(or board_debug.openocd_board = esp32-wrover.cfg may work too).

To get openocd to use the 3.3V flash voltage you will have to edit the cfg file in C:\Users\<user>\.platformio\packages\tool-openocd-esp32\share\openocd\scripts\board\esp32-wrover.cfg yourself at the lines

# Tell OpenOCD which SPI flash voltage is used by the board (3.3 or 1.8)
# The TDI pin of ESP32 is also a bootstrap pin that selects the voltage the SPI flash
# chip runs at. When a hard reset happens (e.g. because someone switches the board off
# and on) the ESP32 will use the current TDI value as the bootstrap value because the
# JTAG adapter overrides the pull-up or pull-down resistor that is supposed to do the
# bootstrapping. These lines basically set the idle value of the TDI line to a
# specified value, therefore reducing the chance of a bad bootup due to a bad flash
# voltage greatly.
# This option defaults to 3.3, if not set. To override the default, uncomment
# the following line:
set ESP32_FLASH_VOLTAGE 1.8

which should be changed to 3.3.

If that still doesn’t work, it may really need the newest openocd version. In such a case you can try and replace the files locally in your C:\Users\<user>\.platformio\packages\tool-openocd-esp32 folder with updated binaries and scripts and see if that works out (while changing the to-be-used config file via openocd_board)

Unfortunately, that still didn’t do the trick - still the same symptoms. This is my platform.ini configuration after my tests:

[env:esp32dev]
platform = espressif32
board = esp32dev
board_debug.openocd_board = esp32-wrover-kit-3.3v.cfg
framework = arduino
debug_tool = esp-prog
debug_init_break =
upload_port = COM4
monitor_speed = 115200
board_build.partitions = noota_3g.csv

Changing the board-parameter to “esp-wrover-kit” does not seem to make any difference. I have tried replaced the entire OpenOCD package (and even the xtensa-packages) in the .platformio directory, but that didn’t help either. But I noticed that in the new OpenOCD release, the esp-wroom-32.cfg has been marked as deprecated, which further irritates me…

Well then let’s just do a quick sanity check. Start openocd in a seperate shell and wait for it to be connected to the chip.

Then for the platformio.ini do

[env:esp32dev]
platform = espressif32
board = esp32dev
board_debug.openocd_board = esp32-wrover-kit-3.3v.cfg
framework = arduino
debug_tool = custom
debug_port = localhost:3333
upload_port = COM4
monitor_speed = 115200
board_build.partitions = noota_3g.csv

Can PlatformIO then connected to the already opened gdbserver made by openocd?

Kind of. It does connect, but then I’m greeted with an error message in PlatformIO: “Function “main” not defined”. GDB also throws an error: “Programming Failed”.

This is the gdb server log:

Open On-Chip Debugger  v0.10.0-esp32-20191114 (2019-11-14-14:19)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
none separate
adapter speed: 20000 kHz
Info : Configured 2 cores
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: type 'esp32' is missing virt2phys
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 20000 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32: Debug controller 0 was reset.
Info : esp32: Core 0 was reset.
Info : esp32: Debug controller 1 was reset.
Info : esp32: Core 1 was reset.
Info : cpu0: Detected debug stubs @ 3ffc0c4c
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
Error: No symbols for FreeRTOS
Info : Target halted. CPU0: PC=0x400E8222 (active)
Info : Target halted. CPU1: PC=0x400E8222
Info : cpu0: Target halted, PC=0x400916EA, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 44 KB
Info : Flash mapping 1: 0x20018 -> 0x400d0018, 97 KB
Info : cpu0: Target halted, PC=0x400916EA, debug_reason=00000001
Info : Auto-detected flash bank 'esp32.flash' size 8192 KB
Info : Using flash bank 'esp32.flash' size 8192 KB
Info : cpu0: Target halted, PC=0x400916EA, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 44 KB
Info : Flash mapping 1: 0x20018 -> 0x400d0018, 97 KB
Info : Using flash bank 'esp32.irom' size 100 KB
Info : cpu0: Target halted, PC=0x400916EA, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 44 KB
Info : Flash mapping 1: 0x20018 -> 0x400d0018, 97 KB
Info : Using flash bank 'esp32.drom' size 48 KB
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
Info : esp32: Core 0 was reset.
Info : esp32: Debug controller 1 was reset.
Info : esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
** Programming Started **
auto erase enabled
embedded:startup.tcl:480: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 480
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
Info : esp32: Core 0 was reset.
Info : esp32: Debug controller 1 was reset.
Info : esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
** Programming Started **
auto erase enabled
embedded:startup.tcl:480: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 480
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
Info : esp32: Core 0 was reset.
Info : esp32: Debug controller 1 was reset.
Info : esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
** Programming Started **
auto erase enabled
embedded:startup.tcl:480: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 480
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
Info : esp32: Core 0 was reset.
Info : esp32: Debug controller 1 was reset.
Info : esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
** Programming Started **
auto erase enabled
embedded:startup.tcl:480: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 480
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
Info : esp32: Core 0 was reset.
Info : esp32: Debug controller 1 was reset.
Info : esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
Info : dropped 'gdb' connection

This is the log I see in the debug console of PlatformIO in VSCode:

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (2.0.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (custom) External (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.10004.200129 (1.0.4)
 - tool-esptoolpy 1.20600.0 (2.6.0)
 - toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 26 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   4.7% (used 15348 bytes from 327680 bytes)
Flash: [==        ]  20.1% (used 211037 bytes from 1048576 bytes)
========================= [SUCCESS] Took 1.31 seconds =========================
Reading symbols from c:\Users\Alex\Development\Assets\iris\debug-test\esp32-debug-test\.pio\build\esp32dev\firmware.elf...
done.
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = custom
PlatformIO: Initializing remote target...
0x400e8222 in String::setLen (this=0x0, len=<optimized out>) at C:\Users\Alex\.platformio\packages\framework-arduinoespressif32\cores\esp32/WString.h:277
277	        inline void setLen(int len) { if (isSSO()) sso.len = len; else ptr.len = len; }
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
** Programming Started **
auto erase enabled
embedded:startup.tcl:480: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 480
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
** Programming Started **
auto erase enabled
embedded:startup.tcl:480: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 480
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
** Programming Started **
auto erase enabled
embedded:startup.tcl:480: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 480
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
** Programming Started **
auto erase enabled
embedded:startup.tcl:480: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Alex/.espressif/tools/openocd-esp32/v0.10.0-esp32-20191114/openocd-esp32/bin/../share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 480
JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
Function "main" not defined.
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal]
PlatformIO: Initialization completed
/builds/idf/crosstool-NG/.build/src/gdb-7.10/gdb/cp-namespace.c:343: internal-error: cp_search_static_and_baseclasses: Assertion `name[prefix_len + 1] == ':'' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session?
(y or n) [answered Y; input not from terminal]

This is a bug, please report it.
  For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.

/builds/idf/crosstool-NG/.build/src/gdb-7.10/gdb/cp-namespace.c:343: internal-error: cp_search_static_and_baseclasses: Assertion `name[prefix_len + 1] == ':'' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB?
(y or n) [answered Y; input not from terminal]

I finally got it to work. @maxgerhardt Turns out you were right all along. Remember when you told me to manually replace OpenOCD with the latest version? When looking through the logs today, I realized that it wasn’t actually executing the new version I had installed. After some experimenting, I found out that it’s not possible to just replace the tool-openocd-esp32 directory (which contains the bin and share directories) with the same directory from the latest GitHub release and rename it, because the GitHub release does not contain the .piopm and package.json files. If these files are missing, PlatformIO will simply replace OpenOCD again with the version that was previously installed. Just replacing the bin and share directories but leaving the remaining files as they were did the trick after all! Awesome!

But one question remains: In PlatformIO, can I somehow specify the OpenOCD version to use? Because I would have to replace the binaries manually on all my machines otherwise…

You can create a new tool-openocd-esp32 package (new bin/ and share/ versions, package.json with incremented version number) and upload it to a repo or ZIP somewhere. You can then use the per-project directive platform_packages = tool-openocd-esp32 @ <link> (docs) to override the openocd package for the project.

I’ve also created Update openocd · Issue #413 · platformio/platform-espressif32 · GitHub as a reminder to update openocd for the platform, so by the next update this is hopefully already included globally.

1 Like