Try to use esp-prog: "GDB connection rejected"

I am trying to use the esp-prog to debug with PlatformIO. I got the debug sketch compiled and uploaded with the esp-prog, but as soon as I will open Run->Start Debugging, after a few seconds I get this output in the debug console:

Processing az-delivery-devkit-v4 (platform: espressif32; board: az-delivery-devkit-v4; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/az-delivery-devkit-v4.html
PLATFORM: Espressif 32 (2.0.0) > AZ-Delivery ESP-32 Dev Kit C V4
HARDWARE: ESP32 240MHz, 520KB RAM, 16MB 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-arduinoespressif32 3.10004.201016 (1.0.4)
 - tool-esptoolpy 1.20600.0 (2.6.0)
 - tool-openocd-esp32 1.1000.20190709 (10.0)
 - toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ deep+, Compatibility ~ soft
Found 43 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <SimpleButton>
|   |-- <Wire> 1.0.1
|-- <Adafruit GFX Library> 1.10.0
|   |-- <Adafruit BusIO> 1.4.1
|   |   |-- <Wire> 1.0.1
|   |   |-- <SPI> 1.0
|   |-- <Wire> 1.0.1
|   |-- <SPI> 1.0
|-- <Adafruit SSD1306> 2.3.1
|   |-- <Adafruit GFX Library> 1.10.0
|   |   |-- <Adafruit BusIO> 1.4.1
|   |   |   |-- <Wire> 1.0.1
|   |   |   |-- <SPI> 1.0
|   |   |-- <Wire> 1.0.1
|   |   |-- <SPI> 1.0
|   |-- <SPI> 1.0
|   |-- <Wire> 1.0.1
|-- <Adafruit BusIO> 1.4.1
|   |-- <Wire> 1.0.1
|   |-- <SPI> 1.0
|-- <Ticker> 3.1.5
|-- <ArduinoOTE> 1.0
|   |-- <Ethernet> 2.0.0+sha.c9399a9
|   |   |-- <SPI> 1.0
|   |-- <Update> 1.0
|   |-- <ESPmDNS> 1.0
|   |   |-- <WiFi> 1.0
|-- <AsyncTCP> 1.1.1
|-- <Ethernet> 2.0.0+sha.c9399a9
|   |-- <SPI> 1.0
|-- <WiFi> 1.0
|-- <ModbusUnified> 0.0.1
|   |-- <AsyncTCP> 1.1.1
|   |-- <Ethernet> 2.0.0+sha.c9399a9
|   |   |-- <SPI> 1.0
|   |-- <WiFi> 1.0
Building in debug mode
Compiling .pio\build\az-delivery-devkit-v4\src\main.cpp.o
Linking .pio\build\az-delivery-devkit-v4\firmware.elf
Retrieving maximum program size .pio\build\az-delivery-devkit-v4\firmware.elf
Checking size .pio\build\az-delivery-devkit-v4\firmware.elf
Building .pio\build\az-delivery-devkit-v4\firmware.bin
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   7.4% (used 39504 bytes from 532480 bytes)
Flash: [=====     ]  54.9% (used 718978 bytes from 1310720 bytes)
esptool.py v2.6
========================= [SUCCESS] Took 16.38 seconds =========================
Reading symbols from c:\Users\Micha\Documents\PlatformIO\Projects\Unibridge\.pio\build\az-delivery-devkit-v4\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-20190708 (2019-07-08-11:04)
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
esp32 interrupt mask on
Info : tcl server disabled
Info : telnet server disabled
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 : Target halted. PRO_CPU: PC=0x40090064 (active)    APP_CPU: PC=0x40000400
Info : accepting 'gdb' connection from pipe
Error: No symbols for FreeRTOS
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Error: timed out while waiting for target halted / 4 - 2
Info : Target halted. PRO_CPU: PC=0x40090058 (active)    APP_CPU: PC=0x40000400
Error: xtensa_wait_algorithm: not halted 0, pc 0x40090058, ps 0x60025
Error: Failed to wait algorithm (-302)!
Error: Algorithm run failed (-302)!
Error: Failed to run flasher stub (-302)!
Warn : Failed to get flash mappings (-302)!
Error: Target is already running an algorithm
Error: Failed to start algorithm (-4)!
Error: Algorithm run failed (-4)!
Error: Failed to run flasher stub (-4)!
Error: Target is already running an algorithm
Error: Failed to start algorithm (-4)!
Error: Algorithm run failed (-4)!
Error: Failed to run flasher stub (-4)!
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
Error: error during select: Unknown error
Warn : Flash driver of esp32.flash does not support free_driver_priv()
Warn : Flash driver of irom does not support free_driver_priv()
Warn : Flash driver of drom does not support free_driver_priv()
.pioinit:11: Error in sourced command file:
Remote communication error.  Target disconnected.: No error.

plus an error pop-up:
2020-10-24 16_22_43-Window

I have no clue what may be causing this and how to get around it…

Things to try:

  1. Lowering the adapter speed (you’re running at 20MHz now): Modify esp-wroom-32.cfg as seen in ESP32 + J-link debugger does not start - #12 by Yourigh
  2. Select the correct flash voltage as seen in Esp-prog debugging on a Mac - no device found - #29 by maxgerhardt
  3. Manually update the C:\Users\<user>\.platformio\packages\tool-openocd-esp32 files (while keeping the package.json intact) as noted in Update openocd · Issue #413 · platformio/platform-espressif32 · GitHub. The last 3 ESP32 debuging issues were solved by that.

Uh, that was fast - you are living here, aren’t you? :wink:

I downloaded openocd-esp32-win32-0.10.0-esp32-20200709.zip. Where am I supposed to put the enclosed files? In another thread you mentioned C:\Users\<user>\packages\... - would that not require a .pio before packages?

[Update]

  • installed openocd in .pio\packages. The installed version is obviously used, as seen in the Debug output. No change, unfortunately.
  • changed clock speed to 5000 in esp-wroom-32.cfg. This is also indicated in the debug log. No change as well.
  • The voltage was already on 3.3V.

The error log

Info : clock speed 5000 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 : Target halted. CPU0: PC=0x40090060 (active)
Info : Target halted. CPU1: PC=0x40000400 
Info : accepting 'gdb' connection from pipe
Error: No symbols for FreeRTOS
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Error: timed out while waiting for target halted / 4 - 2
Info : cpu0: Target halted, PC=0x40090065, debug_reason=00000000
Error: xtensa_wait_algorithm: not halted 0, pc 0x40090065, ps 0x60025
Error: Failed to wait algorithm (-302)!

to me looks like the hardware is working, even halting, but the debugger does not get the info?

And what happens when using 1.8V? I guess in openocd-esp32/tcl/board/esp-wroom-32.cfg at master · espressif/openocd-esp32 · GitHub.

Is this the exact board you have? With 100% sure an ESP-WROOM-32 module on it?

Other things / quirks are listed in Tips and Quirks - ESP32 - — ESP-IDF Programming Guide latest documentation, like “Do not use JTAG pins in firmware” etc.

Another thing to look at would be:

  • ESP32 board must be powered separately from the debugger
  • replace wires with shorter / different ones

The board is exactly the named one and definitely has a WROOM32 on it. Power is separate and the wires are about 15cm in length. The JTAG pins are not used by the firmware.
The debug firmware is uploaded with JTAG already and open-ocd is recognizing the board correctly, as it seems.

Full platformio.ini? Is debug_init_break = tbreak setup contained it per Low-cost ESP32 In-circuit Debugging | by Manuel Bl. | Medium?

Here we go:

[env]
platform = espressif32
board = az-delivery-devkit-v4
framework = arduino
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
board_build.partitions = default.csv
debug_tool = esp-prog
debug_init_break = tbreak setup
upload_protocol = esp-prog

[env:az-delivery-devkit-v4]
lib_ldf_mode = deep+
lib_deps =
  AsyncTCP
  Ethernet=https://github.com/maxgerhardt/Ethernet.git
# build_flags = -DCORE_DEBUG_LEVEL=7

After powering up today I got a bit further somehow. Did not change a bit?!?
But now I cannot get the debugged program to continue - c and continue commands will show up in the debug console, but no reaction whatsoever:

Processing az-delivery-devkit-v4 (platform: espressif32; board: az-delivery-devkit-v4; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/az-delivery-devkit-v4.html
PLATFORM: Espressif 32 (2.0.0) > AZ-Delivery ESP-32 Dev Kit C V4
HARDWARE: ESP32 240MHz, 520KB RAM, 16MB 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-arduinoespressif32 3.10004.201016 (1.0.4)
 - tool-esptoolpy 1.20600.0 (2.6.0)
 - tool-openocd-esp32 1.1000.20190709 (10.0)
 - toolchain-xtensa32 2.50200.80 (5.2.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ deep+, Compatibility ~ soft
Found 43 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <SimpleButton>
|   |-- <Wire> 1.0.1
|-- <Adafruit GFX Library> 1.10.0
|   |-- <Adafruit BusIO> 1.4.1
|   |   |-- <Wire> 1.0.1
|   |   |-- <SPI> 1.0
|   |-- <Wire> 1.0.1
|   |-- <SPI> 1.0
|-- <Adafruit SSD1306> 2.3.1
|   |-- <Adafruit GFX Library> 1.10.0
|   |   |-- <Adafruit BusIO> 1.4.1
|   |   |   |-- <Wire> 1.0.1
|   |   |   |-- <SPI> 1.0
|   |   |-- <Wire> 1.0.1
|   |   |-- <SPI> 1.0
|   |-- <SPI> 1.0
|   |-- <Wire> 1.0.1
|-- <Adafruit BusIO> 1.4.1
|   |-- <Wire> 1.0.1
|   |-- <SPI> 1.0
|-- <Ticker> 3.1.5
|-- <ArduinoOTE> 1.0
|   |-- <Ethernet> 2.0.0+sha.c9399a9
|   |   |-- <SPI> 1.0
|   |-- <Update> 1.0
|   |-- <ESPmDNS> 1.0
|   |   |-- <WiFi> 1.0
|-- <AsyncTCP> 1.1.1
|-- <Ethernet> 2.0.0+sha.c9399a9
|   |-- <SPI> 1.0
|-- <WiFi> 1.0
|-- <ModbusUnified> 0.0.1
|   |-- <AsyncTCP> 1.1.1
|   |-- <Ethernet> 2.0.0+sha.c9399a9
|   |   |-- <SPI> 1.0
|   |-- <WiFi> 1.0
Building in debug mode
Compiling .pio\build\az-delivery-devkit-v4\src\main.cpp.o
Linking .pio\build\az-delivery-devkit-v4\firmware.elf
Building .pio\build\az-delivery-devkit-v4\firmware.bin
Retrieving maximum program size .pio\build\az-delivery-devkit-v4\firmware.elf
Checking size .pio\build\az-delivery-devkit-v4\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   7.4% (used 39504 bytes from 532480 bytes)
Flash: [=====     ]  54.9% (used 718978 bytes from 1310720 bytes)
esptool.py v2.6
========================= [SUCCESS] Took 16.17 seconds =========================
Reading symbols from c:\Users\Micha\Documents\PlatformIO\Projects\Unibridge\.pio\build\az-delivery-devkit-v4\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-20200709 (2020-07-09-08:54)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 20000 kHz

WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release.
Info : Configured 2 cores
adapter speed: 5000 kHz

Info : tcl server disabled
Info : telnet server disabled
Info : clock speed 5000 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 : accepting 'gdb' connection from pipe
Error: No symbols for FreeRTOS
Info : Target halted. CPU0: PC=0x40140636 (active)
Info : Target halted. CPU1: PC=0x40140636
Info : cpu0: Target halted, PC=0x40091856, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 153 KB
Info : Flash mapping 1: 0x40018 -> 0x400d0018, 454 KB
Info : cpu0: Target halted, PC=0x40091856, debug_reason=00000001
Info : Auto-detected flash bank 'esp32.flash' size 4096 KB
Info : Using flash bank 'esp32.flash' size 4096 KB
Info : cpu0: Target halted, PC=0x40091856, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 153 KB
Info : Flash mapping 1: 0x40018 -> 0x400d0018, 454 KB
Info : Using flash bank 'esp32.irom' size 456 KB
Info : cpu0: Target halted, PC=0x40091856, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 153 KB
Info : Flash mapping 1: 0x40018 -> 0x400d0018, 454 KB
Info : Using flash bank 'esp32.drom' size 156 KB
0x40140636 in wdevProcessRxSucDataAll ()
Error: Too large number of threads 1073465900!
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)
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)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
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.
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
** Programming Started **
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449
** Programming Started **
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449
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)
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)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
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.
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
** Programming Started **
** Programming Started **
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449
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)
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)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
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.
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
** Programming Started **
** Programming Started **
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449
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)
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)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
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.
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
** Programming Started **
** Programming Started **
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449
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)
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)
Info : cpu0: Debug controller 0 was reset.
Info : cpu0: Core 0 was reset.
cpu0: Debug controller 0 was reset.
cpu0: Core 0 was reset.
Info : cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
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.
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Info : Target halted. CPU0: PC=0x40000400 (active)
Info : Target halted. CPU1: PC=0x40000400
Target halted. CPU0: PC=0x40000400 (active)
Target halted. CPU1: PC=0x40000400
Temporary breakpoint 1 at 0x400d129c: file src\main.cpp, line 107.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak setup`
PlatformIO: More configuration options -> http://bit.ly/pio-debug
Note: automatically using hardware breakpoints for read-only addresses.
Info : cpu0: Detected debug stubs @ 3ffc1e78
cpu0: Detected debug stubs @ 3ffc1e78
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.
esp32: Debug controller 0 was reset.
esp32: Core 0 was reset.
esp32: Debug controller 1 was reset.
esp32: Core 1 was reset.
Info : cpu0: Detected debug stubs @ 3ffc1e78
cpu0: Detected debug stubs @ 3ffc1e78

There is another breakpoint in setup() at line 143, that the program can not skip. What makes me wonder is this line:

Error: Too large number of threads 1073465900!

At that time there should be two threads running only - the main task and a WiFi server task.

And this does not look right either:

at file "embedded:startup.tcl", line 449
embedded:startup.tcl:449: Error: ** Programming Failed **
in procedure 'program_esp32'
in procedure 'program_esp' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp32.cfg", line 64
in procedure 'program_error' called at file "C:/Users/Micha/.platformio/packages/tool-openocd-esp32/share/openocd/scripts/target/esp_common.cfg", line 106
at file "embedded:startup.tcl", line 449

Have you tried lowering the speed setting in openocd-esp32/tcl/interface/ftdi/esp32_devkitj_v1.cfg at master · espressif/openocd-esp32 · GitHub to an even lower value, like 1000 / 500 kHz?

Besides that I only really have these final recommendations:

  • have no other breakpoints set manually in the GUI. The tbreak setup will auto-halt at setup.
  • try on an absolute minimal blinky project instead of a complex one
  • open as issue in Issues · espressif/openocd-esp32 · GitHub for help
  • try in a Linux, e.g. Ubuntu, virtual machine with USB device passed-through
    • and the same update to the tool-openocd-esp32 toolchain [or even: compile current one from source, since even that release is from June 2020]

Okay, I am giving up for now. I tried with 1000 kHz with no visible difference.

I may try the blink example, but what would that help, even if it will work? I need to debug my program, that unfortunately is a bit more complicated than blink…

Is the openocd community active enough to care about issues?

I’ve experienced a similar debugger behavior in the past. The problem was that I had misread a pin name on the silk screen and configured a pin that is wired to the flash…

Debugging an MCU involves many pieces that can go wrong. So I really recommend you try uploading and debugging with a blink sketch first and rule out as many problems as possible.

Initially, you will need upload the blink sketch without ESP-Prog.

1 Like

I am involved in a discussion on Github now regarding this issue. It looks like there is something fishy in general for PlatformIO invoking open-ocd, as I am not the only one experiencing these symptoms.

  • the open-ocd guys are recommending to use program_esp instead of program_esp32 (like main.py does it at the moment)
  • the problems seem to gather around open-ocd being unable to upload the debug sketch

This: ESP32-Pico-V3 fails to upload/debug using esp-prog - #20 by ivankravets
was the solution for me as well.

Hi, I just want to say that this thread and the responses were KEY to me figuring out a days long problem with debug attachment on my ESP32-S2-WROOM DevKit!

Especially comments from manuelbl, thank you!

For what it’s worth, based on the above and having similar issues with a fairly complex and multi-core application, here is what worked for me on my rig (PlatformIO, Arduino framework, c++, Windows 11).

  1. Per other’s comments, make damn sure you have wired everything correctly. For me, having longer jumpers didn’t really seem to be an issue btw.
  2. Indeed it appears that if you wire up the “wrong” GPIO in your application, you may get the dreaded Target is already running an algorithm Failed to start algorithm (-4)!
    And it doesn’t have anything to do with the wiring, the “algorithm” appears to be a s/w use of the pins.
    I proved this by commenting out and then in again a RTOS task that included GPIOs (for my rig it was one of 5, 18, 19, 25, 32 and/or 33 that was causing the problem) and then recompiling and restarting the debug process. Note that the above pins I used were not RX/TX or JTAG pins. Basically an undocumented problem if you ask me.
  3. I seemed to run into problems when I had breakpoints declared (especially more than 1) before debugging started. When I simply deleted all my breakpoints but specified
    debug_init_break = tbreak setup
    in my plaformio.ini, things worked better
  4. This is one that I can’t prove but strongly suspect: make sure you have uploaded code changes to flash via Upload before hitting the F5 - Debug start. On my rig it does not appear that starting debug actually uploaded the compiled .ELF file to the ESP32 and I think the images being out of sync caused issues early in my research.

Again, for me this was a long trial and error thing. And if I had to pick one fix to focus on it was #2 above.

Hope this helps someone else.