ESP32 with ESPProg

I am trying to debug the ESP32.

So I have an ESPPRog

and have the programmer side connected to my ESP32 AI Thinker (with the minicamera)

I can upload a program using the ESPProg and the following setting in platformio

[platformio]
default_envs = esp32cam

[env:esp32cam]
upload_port = COM15
platform = https://github.com/platformio/platform-espressif32.git
board = esp32cam
framework = arduino
board_build.partitions = customparts.csv
build_flags = -mfix-esp32-psram-cache-issue
lib_deps = OneButton
monitor_port=COM15
monitor_speed = 115200
debug_tool = esp-prog
debug_init_break = tbreak setup

**upload_protocol = esptool**

So it uploads the program, and I then reset the ESP32 device and remove the Gnd wire connecting to IO0, and the program runs I can see output in the serial monitor.

Now to debug I click on PIO Debug (skip Pre-Debug) ESP32-RTP to debug my project without building and uploading - but I am getting this popup error dialog

[Window Title]
Visual Studio Code

Failed to launch GDB: .pioinit:11: Error in sourced command file:
Remote communication error. Target disconnected.: Success. (from interpreter-exec console “source .pioinit”)

And the output from the debugger is

Reading symbols from x:\3rdRepos\esp32\ESP32-RTSP\.pio\build\esp32cam\firmware.elf...
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = esp-prog
PlatformIO: Initializing remote target...
Open On-Chip Debugger  v0.11.0-esp32-20220411 (2022-04-11-08:48)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 500 kHz

WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release.
DEPRECATED! use 'adapter speed' not 'adapter_khz'
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
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: Debug controller was reset.
Warn : target esp32.cpu1 examination failed
Info : starting gdb server for esp32.cpu0 on pipe
Info : accepting 'gdb' connection from pipe
Error: esp32.cpu0: DSR (80208413) indicates DIR instruction generated an exception!
Info : esp32.cpu0: Target halted, PC=0x4000904C, debug_reason=00000001
Info : Set GDB target to 'esp32.cpu0'
Warn : No symbols for FreeRTOS!
Error: esp32.cpu0: DSR (8000CC13) indicates DIR instruction generated an exception!
Warn : esp32.cpu0: Failed reading 9720 bytes at address 0x40090000
Error: no working area available, can't alloc space for stub code!
Error: Too many flash mappings 10414420! Must be 2.
Warn : Failed to get flash mappings (-4)!
Error: esp32.cpu0: DSR (8000CC13) indicates DIR instruction generated an exception!
Warn : esp32.cpu0: Failed reading 9720 bytes at address 0x40090000
Error: no working area available, can't alloc space for stub code!
Error: Failed to get flash size!
Error: esp32.cpu0: DSR (8000CC13) indicates DIR instruction generated an exception!
Warn : esp32.cpu0: Failed reading 9720 bytes at address 0x40090000
Error: no working area available, can't alloc space for stub code!
Error: Failed to get flash size!
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
.pioinit:11: Error in sourced command file:
Remote communication error.  Target disconnected.: Success.

I read in another post on here the **libusb_open() failed with LIBUSB_ERROR_NOT_SUPPORTED
** is a bug in oprnocd, as its opened the libusb ok to talk to the ESP32 and detect 2 cores etc.

It looks like its using the boards/esp-wroom-32.cfg

And the error is something to do with the flash area ?

Error: esp32.cpu0: DSR (8000CC13) indicates DIR instruction generated an exception!

Warn : esp32.cpu0: Failed reading 9720 bytes at address 0x40090000

Error: no working area available, can’t alloc space for stub code!

Error: Too many flash mappings 10414420! Must be 2.

Warn : Failed to get flash mappings (-4)!

Any help would be most appreciated !! Thanks.

This sounds as if your code reconfigures one or more GPIOs in the range between GPIO12 to GPIO15. If they are used for debugging, they must not be changed.

On the ESP32-CAM, GPIO12 to GPIO15 are also wired to the MicroSD card reader. So you cannot debug your board if you want to use the MicroSD card reader. Debugging should work if you do not use any MicroSD card code.

Thanks for the help - yes I was using Pin 12 for a button. The reason the debugger wasnt working for any programs though was sI didnt have the 5v pins connected on the debugger side of ESPProg - once I swapped that from 3.3 it worked fine, then I removed the pin usage and its got much further.

Now when I start up it stops with a breakpoint and then continues, but I cant add my own breakpoints and have the program hit them and stop for debug. This is the output when I use

PIO Debug (ESP32-RTSP) - so normal program download, and try to start debugger

** Verify Started **
esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
** Programming Finished **
** Verify Started **
Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
** Verified OK **
esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
** Verified OK **
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 : esp32.cpu0: Debug controller was reset.
Info : esp32.cpu0: Core was reset.
esp32.cpu0: Debug controller was reset.
esp32.cpu0: Core was reset.
Info : esp32.cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
Info : esp32.cpu0: Core was reset.
esp32.cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
esp32.cpu0: Core was reset.
Info : esp32.cpu0: Target halted, PC=0x40000400, debug_reason=00000000
Info : esp32.cpu1: Debug controller was reset.
Info : esp32.cpu1: Core was reset.
esp32.cpu0: Target halted, PC=0x40000400, debug_reason=00000000
esp32.cpu1: Debug controller was reset.
esp32.cpu1: Core was reset.
Info : esp32.cpu1: Target halted, PC=0x40000400, debug_reason=00000000
esp32.cpu1: Target halted, PC=0x40000400, debug_reason=00000000
Temporary breakpoint 1 at 0x400d315c: file src/main.cpp, line 32.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak setup`
PlatformIO: More configuration options -> https://bit.ly/pio-debug
Note: automatically using hardware breakpoints for read-only addresses.

I then try to add a breakpoint and get

esp32.cpu0: Target halted, PC=0x4000940C, debug_reason=00000000

But the program hasnt stopped even though it says interupt received and target halted on cpu0

So I pause execution - it stops with these messages

Info : esp32.cpu0: Target halted, PC=0x4000940E, debug_reason=00000000
Info : Set GDB target to 'esp32.cpu0'
esp32.cpu0: Target halted, PC=0x4000940E, debug_reason=00000000
Set GDB target to 'esp32.cpu0'
Info : esp32.cpu1: Target halted, PC=0x400076DD, debug_reason=00000000
esp32.cpu1: Target halted, PC=0x400076DD, debug_reason=00000000
Error: FreeRTOS maximum used priority is unreasonably big, not proceeding: 135

Program
 received signal SIGINT, Interrupt.
Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
0x4000940e in ?? ()

and gives me a unknown source stack trace

??@0x4000940e (Unknown Source:0)
??@0x40008744 (Unknown Source:0)
??@0x40007a27 (Unknown Source:0)
??@0x40000740 (Unknown Source:0)

I add a breakpoint and continue

Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001

But the IDe doesnt show the device as halted - ie no stack trace - “RUNNING” in stack trace window.

Any ideas on this ? Thanks.

It’s difficult to say what’s going on here.

A serious limitation of ESP32 is that it only supports 2 breakpoints, one of which is usually needed for single stepping. If you set more breakpoints, they will be silently ignored.

The unknown source stack trace could indicate that the stack pointer is already corrupted at this point.

1 Like