ESP32 with esp-prog. Uploading works, debugging fails

I’m trying to debug a simple program, but starting the debugger from PlatformIO/VSC fails.

Host: Windows 10, VSC 1.76.2, PIO home 3.4.3, PIO Core 6.1.7a4
Target ESP32-CAM, esp-prog debugger

Platformio.ini:

[env:esp32cam]
platform = espressif32
board = esp32cam
framework = espidf
debug_tool = esp-prog
upload_protocol = esp-prog

Uploading works:

CURRENT: upload_protocol = esp-prog
Uploading .pio\build\esp32cam\firmware.bin
Open On-Chip Debugger v0.11.0-esp32-20220706 (2022-07-06-15:48)
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
debug_level: 1

adapter speed: 20000 kHz

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

Error: libusb_open() failed with LIBUSB_ERROR_NOT_SUPPORTED
** Programming Started **
** Programming Finished in 3670 ms **
** Verify Started **
** Verify OK **
** Programming Started **
** Programming Finished in 1299 ms **
** Verify Started **
** Verify OK **
** Programming Started **
** Programming Finished in 894 ms **
** Verify Started **
** Verify OK **
shutdown command invoked
============================== [SUCCESS] Took 35.64 seconds ==============================

Debugging fails:>

Info : starting gdb server for esp32.cpu0 on pipe

Info : accepting ‘gdb’ connection from pipe

Error: Target not examined yet

Error executing event gdb-attach on target esp32.cpu0:

Warn : No symbols for FreeRTOS!

Error: Target not halted

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

.pioinit:11: Error in sourced command file:

Remote communication error. Target disconnected.: Success.

The program:

#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <esp_log.h>

void app_main()
{
while(1){
ESP_LOGI(“MAIN”, “Hello Worlds”);
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}

The board is connected to a 3A lab power supply, so I’m not concerned about the 5V dipping.
Uploading works (I verified this by changing the message in main.c, and verifying the output changed), so I do not suspect the wiring either.

Except the PlatformIO.ini and main.c files, I didn’t edit anything in the project, its a plain “Create new Project” from PlatformIO.

There are a bunch of error messages in the debugging output, but I cannot really make anything of it. Who has a clue what’s going wrong here?

What’s the output before that?

Apperently I lost some output in the copy-paste.
Here is the full debugging output again

undefinedC:\Users\steven.platformio\packages\toolchain-xtensa-esp32\bin\xtensa-esp32-elf-gdb.exe: warning: Couldn’t determine a path for the index cache directory.

Reading symbols from .pio\build\esp32cam\firmware.elf…

PlatformIO Unified Debugger → Redirecting...

PlatformIO: debug_tool = esp-prog

PlatformIO: Initializing remote target…

Open On-Chip Debugger v0.11.0-esp32-20220706 (2022-07-06-15:48)

Licensed under GNU GPL v2

For bug reports, read

OpenOCD: Bug Reporting

adapter speed: 20000 kHz

WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release.

adapter speed: 5000 kHz

Info : tcl server disabled

Info : telnet server disabled

Error: libusb_open() failed with LIBUSB_ERROR_NOT_SUPPORTED

Info : clock speed 5000 kHz

Error: JTAG scan chain interrogation failed: all ones

Error: Check JTAG interface, timings, target power, etc.

Error: Trying to use configured scan chain anyway…

Error: esp32.cpu0: IR capture error; saw 0x1f not 0x01

Warn : Bypassing JTAG setup events due to errors
Error: Unexpected OCD_ID = ffffffff

Warn : target esp32.cpu0 examination failed

Error: Unexpected OCD_ID = ffffffff

Warn : target esp32.cpu1 examination failed

Info : starting gdb server for esp32.cpu0 on pipe

Info : accepting ‘gdb’ connection from pipe

Error: Target not examined yet

Error executing event gdb-attach on target esp32.cpu0:

Warn : No symbols for FreeRTOS!

Error: Target not halted

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

.pioinit:11: Error in sourced command file:

Remote communication error. Target disconnected.: Success.

Weird how it would upload correctly over the ESP-PROG + JTAG but can’t establish the debug session later on. And the firmware you uploaded doesn’t interfere with the JTAG pins in any way.

Can you add debug_speed = 500 in the platformio.ini and retry?

Can you add debug_speed = 500 in the platformio.ini and retry?

Makes no difference…

I have the same issue. I’ve tried different ESP boards, ESP-Prog units, different cables, every speed from default 20,000 down to 100.

Sometimes erasing directly (without ESP-Prog) helps but this is not a solution, and it isn’t even consistent. The project is running a FreeRTOS-based sample project from Micro$oft. No collisions with JTAG pins in any libraries that I can find. The project runs perfectly fine if simply flashed.

It seems like something the ESP is doing while running is not allowing the ESP-Prog to function correctly, and it seems like it’s Espressif’s fault.