ESP32 Debugging ESP-Prog libusb_open() fails

Hello,
I inherited a project based on ESP32 developed with VScode IDE, Platformio with Arduino libraries. This platform is new for me.
My predecessors used the console for debugging. I am trying to exploit the Jtag ESP-Prog.
After a long fight I was able to debug a very basic led-blinking application, but when I switch to the project I have to work to, I get the errors below.

I understand the problem involves the flash structure but I have no idea about how to solve this.

The firmware is flashed in this way:
boot_app0.bin @0xe000
bootloader_dio_80m.bin @0x1000
application.partitions.bin @0x8000
application.bin @0x10000
application_web.bin @0x290000

the project uses a default.csv file as follow:

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x140000,
app1,     app,  ota_1,   0x150000,0x140000,
spiffs,   data, spiffs,  0x290000,0x170000,

When I try to debug the app I get the following error:

Reading symbols from C:\Workspace\ESP32\App\.pio\build\esp32doit-devkit-v1\firmware.elf...
done.
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = esp-prog
PlatformIO: Initializing remote target...
Open On-Chip Debugger  v0.10.0-esp32-20210721 (2021-07-21-13:35)
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 : 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 : esp32.cpu0: Debug controller was reset.
Info : esp32.cpu0: Core was reset.
Info : accepting 'gdb' connection from pipe
Warn : No symbols for FreeRTOS!
Info : esp32.cpu0: Debug controller was reset.
Info : esp32.cpu0: Target halted, PC=0x40007BA1, debug_reason=00000000
Info : Set GDB target to 'esp32.cpu0'
Info : esp32.cpu0: Target halted, PC=0x400928DA, debug_reason=00000001
Error: Failed to get flash maps (4294967290)!
Warn : Failed to get flash mappings (-4)!
Info : esp32.cpu0: Target halted, PC=0x400928DA, debug_reason=00000001
Info : esp32.cpu0: Target halted, PC=0x400928DA, debug_reason=00000001
Info : Auto-detected flash bank 'esp32.cpu0.flash' size 4096 KB
Info : Using flash bank 'esp32.cpu0.flash' size 4096 KB
Info : esp32.cpu0: Target halted, PC=0x400928DA, debug_reason=00000001
Error: Failed to get flash maps (4294967290)!
Warn : Failed to get flash mappings (-4)!
Info : esp32.cpu0: Target halted, PC=0x400928DA, debug_reason=00000001
Info : Using flash bank 'esp32.cpu0.irom' size 0 KB
Info : esp32.cpu0: Target halted, PC=0x400928DA, debug_reason=00000001
Error: Failed to get flash maps (4294967290)!
Warn : Failed to get flash mappings (-4)!
Info : esp32.cpu0: Target halted, PC=0x400928DA, debug_reason=00000001
Info : Using flash bank 'esp32.cpu0.drom' size 0 KB
Info : New GDB Connection: 1, Target esp32.cpu0, state: halted
0x40007ba1 in ?? ()
Loading section .flash.rodata, size 0x46cf4 lma 0x3f400020
Error: Too large number of threads 952509207!
Warn : address 0x3f400020 not writable
Warn : address 0x3f401020 not writable
.pioinit:12: Error in sourced command file:
Load failed
  1. So all connections are now per https://medium.com/@manuel.bl/low-cost-esp32-in-circuit-debugging-dbbee39e508b and debugging a blinky application worked?
  2. Does your target firmware use deep-sleep modes or the GPIO pins assigned to JTAG?

Thank you for the very fast reply, Maximilian.

  1. So all connections are now per Low-cost ESP32 In-circuit Debugging | by Manuel Bl. | Medium and debugging a blinky application worked?

Exactly, JTAG program load and debugging the blinking app, works.

  1. Does your target firmware use deep-sleep modes or the GPIO pins assigned to JTAG?

On the same HW of the blinky application, I am trying to debug the target application. It doesn’t use deep sleep but this app uses some GPIO assigned to jtag. My thinking was that these pins are assigned only after the setup() so, if I place a breakpoint on the beginning of setup() function, this should work. Am I wrong?

The ESP-Prog has no way of forcing a reset via TRST (not implemented in OpenOCD) so that you could get in a state where the GPIO still have their default JTAG functions and setup() hasn’t been fully executed yet, so that thinking is flawed.

For a quick test, can you comment out every usage of a JTAG pin in the firmware, upload normally via UART and try debugging again?

Thank you Maximilian,
yes, I think you were right and I made a step forward, but the debugger still does not start.

However I will mark this as solved since now I have a different issue.

I disabled the pins used by JTAG and uploaded via UART.

Now I have a new problem. Obviously the first attempt was trying to remove the file “.pioinit” as suggested.

I googled this error but nothing seems to work (PC reboot, build_type = debug, using UART/JTAG to upload, …). The blinking code still works in debug mode.

Reading symbols from C:\Workspace\ESP32\Focuser\.pio\build\esp32doit-devkit-v1\firmware.elf...
done.
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = esp-prog
PlatformIO: Initializing remote target...
Open On-Chip Debugger  v0.10.0-esp32-20210721 (2021-07-21-13:35)
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 : 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 : esp32.cpu0: Debug controller was reset.
Info : esp32.cpu0: Core was reset.
Info : esp32.cpu0: Detected debug stubs @ 3ffc44d0
Info : esp32.cpu1: Debug controller was reset.
Info : esp32.cpu1: Core was reset.
Info : accepting 'gdb' connection from pipe
Warn : No symbols for FreeRTOS!
Info : esp32.cpu0: Target halted, PC=0x4017AFE6, debug_reason=00000000
Info : Set GDB target to 'esp32.cpu0'
Info : esp32.cpu1: Target halted, PC=0x400D3993, debug_reason=00000000
Warn : Not full dbg stub table 1 of 2
Info : esp32.cpu0: Target halted, PC=0x400928DA, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 276 KB
Info : Flash mapping 1: 0x60018 -> 0x400d0018, 688 KB
Info : esp32.cpu0: Target halted, PC=0x400928DA, debug_reason=00000001
Info : Auto-detected flash bank 'esp32.cpu0.flash' size 4096 KB
Info : Using flash bank 'esp32.cpu0.flash' size 4096 KB
Info : esp32.cpu0: Target halted, PC=0x400928DA, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 276 KB
Info : Flash mapping 1: 0x60018 -> 0x400d0018, 688 KB
Info : Using flash bank 'esp32.cpu0.irom' size 692 KB
Info : esp32.cpu0: Target halted, PC=0x400928DA, debug_reason=00000001
Info : Flash mapping 0: 0x10020 -> 0x3f400020, 276 KB
Info : Flash mapping 1: 0x60018 -> 0x400d0018, 688 KB
Info : Using flash bank 'esp32.cpu0.drom' size 280 KB
Info : New GDB Connection: 1, Target esp32.cpu0, state: halted
0x4017afe6 in ?? ()
Loading section .flash.rodata, size 0x46c4c lma 0x3f400020
Warn : address 0x3f446000 not writable
Loading section .dram0.data, size 0x35c0 lma 0x3ffbdb60
.pioinit:12: Error in sourced command file:
Load failed
.pioinit:12: Error in sourced command file:
Load failed
undefined[WinError 32] Impossibile accedere al file. Il file � utilizzato da un altro processo: 'C:\\.platformio\\.cache\\.piodebug-r8dr5jcn\\.pioinit'
Please manually remove the file `C:\.platformio\.cache\.piodebug-r8dr5jcn\.pioinit`
[WinError 145] La directory non � vuota: 'C:\\.platformio\\.cache\\.piodebug-r8dr5jcn'
Please manually remove the file `C:\.platformio\.cache\.piodebug-r8dr5jcn`

mario

I fixed the .pioinit issue above by updating the platform release from

;platform = espressif32@3.0.0
to
platform = espressif32

Now I can debug my target application!!