Esp-prog debugger cannot start or read any flash from ESP32 jtag

Problem Summery
I am using an ESP32-S2 board (devkitM-1U) [uses the ‘saola’ board def] with a esp-prog debugger board and I cannot seem to get the two working together. It seems that the esp-prog detects the esp32s2, halts it correctly, but then cannot read any form of flash memory from it. I admit that I am new to the concepts of JTAG, but I am to presume (put simply) that it is a communication interface and the debugger needs the memory mapped before the program starts to be able to set watches or pretty much do anything.

Enviroment:
Windows 10 pro x64 bit.
VScode 1.56.2
PlatformIO core 5.1.1
PlatformIO home 3.3.4
esp framework version in the debug log. It is latest as of 5/20/21

Troubleshooting attempts:
I have followed the standard steps from the espressif website and even followed the popular referenced video tutorial on youtube (I forget the authors name). I have the FTDI VCP Drivers installed, along with the Zadig WinUSB drivers on both interface 0 and 1 (debugger/programmer channels). I restarted the computer to ensure the drivers were initializing correctly. The S2 revision of the board has different JTAG pins and so I made sure to find and connect them all (GPIO 39-42). I verified these connections multiple times with the online documentation. The jumpers on the esp prog are set to 5v for both boards (prog/esp).

The Test:
For the test, I wanted to run the debugger on my program. The program compiles and runs correctly, but there is a pointer variable that is being reset and I cannot source the problem for it. Hence, the debugger would help here.

I heard that inserting breakpoints in app_main() can be finicky or cause problems, so instead, I put a breakpoint a bit deeper in the source where other stuff is happening. Regardless of where I put it though, this does not seem to matter much if the esp-prog cannot read the chip’s flash memory.

platformio.ini:

[env:esp32-s2-saola-1]
platform = espressif32
board = esp32-s2-saola-1
framework = espidf
monitor_speed = 115200
upload_port = COM4

debug_tool = esp-prog

This is the Debug Console output when run:

Processing esp32-s2-saola-1 (platform: espressif32; board: esp32-s2-saola-1; framework: espidf)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-s2-saola-1.html
PLATFORM: Espressif 32 (3.2.0) > Espressif ESP32-S2-Saola-1
HARDWARE: ESP32S2 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) 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-espidf 3.40200.210118 (4.2.0)
 - tool-cmake 3.16.4
 - tool-esptoolpy 1.30000.201119 (3.0.0)
 - tool-idf 1.0.1
 - tool-mconf 1.4060000.20190628 (406.0.0)
 - tool-ninja 1.9.0
 - toolchain-esp32s2ulp 1.22851.191205 (2.28.51)
 - toolchain-xtensa32s2 1.80400.210211 (8.4.0)
Reading CMake configuration...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 1 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <StepperDriver>
Building in debug mode
Generating project linker script .pio\build\esp32-s2-saola-1\esp32s2.project.ld
Linking .pio\build\esp32-s2-saola-1\firmware.elf
Retrieving maximum program size .pio\build\esp32-s2-saola-1\firmware.elf
Checking size .pio\build\esp32-s2-saola-1\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   2.9% (used 9648 bytes from 327680 bytes)
Flash: [=         ]  14.1% (used 147722 bytes from 1048576 bytes)
========================= [SUCCESS] Took 28.60 seconds =========================
Reading symbols from C:\Users\admin\Documents\Github\C++\ESP32-S2-Saola\ESP32_S2_Saola1\.pio\build\esp32-s2-saola-1\firmware.elf...
done.
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = esp-prog
PlatformIO: Initializing remote target...
Open On-Chip Debugger  v0.10.0-esp32-20201202 (2020-12-02-17:38)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 20000 kHz

Info : FreeRTOS creation
adapter speed: 5000 kHz

Info : tcl server disabled
Info : telnet server disabled
Info : clock speed 5000 kHz
Info : JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Core was reset.
Info : accepting 'gdb' connection from pipe
Warn : No symbols for FreeRTOS!
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Target halted, PC=0x40016102, debug_reason=00000000
Info : Detected ESP32-S2 chip
Info : esp32s2: Target halted, PC=0x400314BA, debug_reason=00000001
Warn : Empty flash mapping!
Warn : Failed to get flash mappings (0)!
Info : esp32s2: Target halted, PC=0x400314BA, debug_reason=00000001
Info : esp32s2: Target halted, PC=0x400314BA, debug_reason=00000001
Info : Auto-detected flash bank 'esp32s2.flash' size 4096 KB
Info : Using flash bank 'esp32s2.flash' size 4096 KB
Info : esp32s2: Target halted, PC=0x400314BA, debug_reason=00000001
Warn : Empty flash mapping!
Warn : Failed to get flash mappings (0)!
Info : esp32s2: Target halted, PC=0x400314BA, debug_reason=00000001
Info : Using flash bank 'esp32s2.irom' size 0 KB
Info : esp32s2: Target halted, PC=0x400314BA, debug_reason=00000001
Warn : Empty flash mapping!
Warn : Failed to get flash mappings (0)!
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Core was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Core was reset.
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Core was reset.
Info : esp32s2: Debug controller was reset.
Error: Target not examined yet
Error: Failed to wait algorithm (-4)!
Error: Target not examined yet
Error: failed to restore 28 bytes of working area at address 0x400314a4
Error: Target not examined yet
Error: failed to restore 1024 bytes of working area at address 0x3ffe007c
Error: Target not examined yet
Error: failed to restore 5284 bytes of working area at address 0x40030000
Error: Target not examined yet
Error: failed to restore 124 bytes of working area at address 0x3ffe0000
Error: Algorithm run failed (-4)!
Error: Failed to run flasher stub (-4)!
Info : Using flash bank 'esp32s2.drom' size 0 KB
0x400314a4 in ?? ()
Warn : Target not HALTED!
Error: Target not examined yet
Error: Could not read FreeRTOS thread count from target!
Error: Target not examined yet
Info : JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Debug controller was reset.
JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Core was reset.
esp32s2: Debug controller was reset.
esp32s2: Core was reset.
Info : esp32s2: Target halted, PC=0x40016102, debug_reason=00000000
esp32s2: Target halted, PC=0x40016102, debug_reason=00000000
Info : esp32s2: Debug controller was reset.
Info : esp32s2: Core was reset.
Info : esp32s2: Target halted, PC=0x40012734, debug_reason=00000000
esp32s2: Debug controller was reset.
esp32s2: Core was reset.
esp32s2: Target halted, PC=0x40012734, debug_reason=00000000
Info : esp32s2: Core was reset.
esp32s2: Core was reset.
Info : esp32s2: Target halted, PC=0x40000400, debug_reason=00000000
esp32s2: Target halted, PC=0x40000400, debug_reason=00000000
** Programming Started **
** Programming Started **
Info : esp32s2: Target halted, PC=0x400314BA, debug_reason=00000001
esp32s2: Target halted, PC=0x400314BA, debug_reason=00000001
Info : esp32s2: Target halted, PC=0x400314BA, debug_reason=00000001
esp32s2: Target halted, PC=0x400314BA, debug_reason=00000001
** Programming Finished **
** Verify Started **
** Programming Finished **
** Verify Started **
Info : esp32s2: Target halted, PC=0x400314BA, debug_reason=00000001
esp32s2: Target halted, PC=0x400314BA, debug_reason=00000001
** Verified OK **
** Verified OK **
.pioinit:12: Error in sourced command file:
Remote communication error.  Target disconnected.: Success.

Does a lower JTAG clock make a difference? Write

debug_speed = 1000

(docs) to use 1000kHz.

If that does not make a difference, open an issue at https://github.com/platformio/platform-espressif32/.It’s clear that that is not a wiring issue since it can read JTAG tap: esp32s2.cpu tap/device found: 0x120034e5 but still something may wrong, maybe in OpenOCD or the way it’s invoked.

Actually, yes. This fixed it.

It seems strange that lowering the speed from whatever the default is resolved the issue. I would think that the default configuration for a probe such as the esp-prog would be set at something more stable.

By default does it run at the speed of the microcontrollers baud rate? I notice that the drivers you need to install actually have settings within the windows driver menu in the device manager. If I remember correctly, it was set to 9600.

So 1khz works, but it is actually very slow when stepping over code. What do you think is safe/stable to run at if I were to attempt something higher?

Edit: it seems that even at 1khz it is sometimes hit-or-miss. I may have to reinitialize debugging because for some reason it does not insert the first hardware breakpoint in app_main() due to some memory not being available or something. I’ve read reports of this with other esp32-s2 boards as well and debugging with this method can be finicky for some reason.

I don’t necessarily need it to stop in app_main or use a hardware breakpoint. Is there a way to bypass the debugger from stopping there by default?

1 Like