ESP32c3 debugging

If I press continue, it says running by the call stack but the led isn’t blinking

EDIT: I was still in DFU mode. I’ll try again

It seems stuck within a small amount of code there it seems. Possibly a bootloader? Does the program still run as normal when you upload it regularly?

I was in DFU mode, I’ll try again

As soon as I take it out of DFU mode, I get the following in the debug console
image

I think it might be easier to do this with devkit C3. I have the breakout boards for the USB connections

@maxgerhardt Thanks for all your help! Could not have gotten this far without your valuable knowledge. It’s definitely in the right direction and it’s almost working! I’m going to take a break, wire up a devkit with a USB breakout directly to pins 18 and 19 to see if there’s any difference. I’ll keep you posted on the progress and I’m sure I’ll be asking you a few more questions in the next few days regarding this.

1 Like

It’s working now. I had to upload normally first, then restart the chip out of DFU, then use debug without uploading because taking the chip out of DFU disconnects the debug interface just enough to break the connection to openOCD
This is with the C3 mini board

This is with interface 2 (the debug interface, using libusbK) installed with zadig2.7
Running openocd in a separate cmd window. I tried inside platformio again and got the GDB error msgbox.

1 Like

I think this is something the Arduino-ESP32 framework has to add so that the JTAG device is still available when the regular firmware runs…

By means of adding debug_load_mode = manual? Can you show your full platformio.ini?

And great work by the way!

In the debug console, I keep getting
Cannot execute this command without a live selected thread.

Does that have something to do with debug_load_mode = manual?

Here’s my platformio.ini

[platformio]
workspace_dir = c:\.pio

default_envs = c3_mini



[env:c3_mini]
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
framework = arduino
platform_packages = espressif/toolchain-riscv32-esp @ 8.4.0+2021r1
                    platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.2
                    platformio/tool-esptoolpy 
                    ; platformio/tool-esptoolpy @ ~1.30100
                    tool-openocd-esp32 
               
monitor_speed = 115200
board = esp32dev
board_build.mcu = esp32c3
board_build.partitions = my_2_large_otas.csv
;board_build.variant = esp32c3
board_build.variant = lolin_c3_mini
board_build.f_cpu = 160000000L
board_build.f_flash = 80000000L
board_build.flash_mode = dio
board_build.arduino.ldscript = esp32c3_out.ld

debug_tool = custom
debug_server = 
;    pio
;    pkg
;    exec
;    -p
;    tool-openocd-esp32
;    -c
;    "openocd -c "adapter_khz 500" -f board/esp32c3-builtin.cfg"
debug_port = localhost:3333
debug_init_break = break loop

; remove old build flags
build_unflags =
  -DARDUINO_ESP32_DEV
  -DARDUINO_VARIANT="esp32"

; inject new ones 
build_flags =
  -DARDUINO_ESP32C3_DEV
  ;-DARDUINO_VARIANT="esp32c3"  
  -DARDUINO_VARIANT="lolin_c3_mini"  
  -'D USE_DEBUG = 1'
   -DCORE_DEBUG_LEVEL=0  
  
;  -DBOARD_HAS_PSRAM

;lib_extra_dirs = ../CustomLibraries 
  • I manually added the Lolin board from the current platform-espressif32.git
1 Like

Maybe try thread 1 or info threads to see which threads are available.

Umm, I don’t see anywhere to select a thread? Is in a menu somewhere?

By means of adding debug_load_mode = manual?
No, just by using the drop down button PIO Debug(without uploading)

I thought you wanted me to put that in the platformio.ini, sorry misunderstood

You have to pause execution I think.

It works good now. I took the debug_load_mode = manual
out of the platformio.ini

I just upload normally, get out of DFU mode and start the application. Start the openocd server. Then run the debug PIO Debug (without uploading) option in the dropdown list.

Everything is working great. Can step into and out of the blink, peek at variables… etc

Thank you so much for your help!! This is going to be a huge benefit for me. I really like the esp32c3 chips, they are so stable as far as WiFi and TCP connections so having the debug working in platformio is just awesome!

I edited the platformio.ini above to reflect I took out the debug load = manual part.

If there’s anything I can do to help get it going without the external server, just let me know and I’d be glad to try stuff out for you.

Thanks again!!

Some more info, maybe it will help someone:
I got it to work inside platformio by:
Downloading the latest openocd from Release v0.11.0-esp32-20211220 · espressif/openocd-esp32 · GitHub (go to the bottom where they’re zipped for your OS)
extract the zip and replace the [bin] and [share] folders that are in .platformio/packages/tool-openocd-esp32/
Leave the other files and folders in the tool-openocd-esp32 be. Just replace those two folders with the ones in the download.

In platformio.ini

[env:c3_mini]
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
framework = arduino
platform_packages = espressif/toolchain-riscv32-esp @ 8.4.0+2021r1
                    platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.2
                    platformio/tool-esptoolpy 
                    ; platformio/tool-esptoolpy @ ~1.30100
                    tool-openocd-esp32
               
monitor_speed = 115200
board = esp32dev
board_build.mcu = esp32c3
board_build.partitions = my_2_large_otas.csv
;board_build.variant = esp32c3
board_build.variant = lolin_c3_mini
board_build.f_cpu = 160000000L
board_build.f_flash = 80000000L
board_build.flash_mode = dio
board_build.arduino.ldscript = esp32c3_out.ld


debug_server =
  ${platformio.packages_dir}/tool-openocd-esp32/bin/openocd
  -f
  ${platformio.packages_dir}/tool-openocd-esp32/share/openocd/scripts/board/esp32c3-builtin.cfg
  

; remove old build flags
build_unflags =
  -DARDUINO_ESP32_DEV
  -DARDUINO_VARIANT="esp32"

; inject new ones 
build_flags =
  -DARDUINO_ESP32C3_DEV
  ;-DARDUINO_VARIANT="esp32c3"  
  -DARDUINO_VARIANT="lolin_c3_mini"  
  -'D USE_DEBUG = 1'
   -DCORE_DEBUG_LEVEL=0  

The section with debug_server is all you need to add your own INI along with the openocd in the packages section
I didn’t use the debug_port or debug_tool options. I believe it defaults to the localhost:3333 when you start openOCD within platformio

I just upload code as usual, then select PIO Debug (without uploading) in the toolbar.

If you try to use PIO Debug it first tries to upload the code but the debugger has already attached itself to the debug interface and then when the chip reverts out of download mode to execution mode the debugger gets detached and you get errors.
Info : Hart 0 unexpectedly reset
Hart 0 unexpectedly reset

Once this disconnection of the debug interface when switching modes is resolved, It’ll be better. For now this is working good and I want to thank @maxgerhardt for taking a lot of time to walk me through this.

I found this thread in relation to esp-idf debugging of esp32-c3
but the problem is inherent to the esp32 jtag device
did you find a way to interface with the inbuilt debugger without running in dfu mode?
it only works for me like so but it is not usefull.

Sadly I don’t even have an ESP32-C3. My “high level” impression is that the activation of the JTAG device during normal firmware runs may be actiavted with some menuconfig option.

If something is not working as seamless as it should, please open an issue in GitHub - platformio/platform-espressif32: Espressif 32: development platform for PlatformIO for help.

Seriously.
This was exactly
What i was missing
I cannot believe i didn’t check to verify the jtag is on.
You dear sir have my deepest thanks
You have no idea how much time I’ve wasted to this forgetfulness!

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: 40000 kHz

Warn : Transport “jtag” was already selected
adapter speed: 5000 kHz

Error: libusb_get_string_descriptor_ascii() failed with -9
** OpenOCD init failed **
shutdown command invoked

*** [upload] Error 1
Using ESP32 S3 C1 devkit, using USB port for Uploading.

This is my Platform.ini file
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; Redirecting...

[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino

monitor_speed = 115200
lib_deps = Wire
upload_port = COM62
upload_protocol = esp-builtin
debug_tool = esp-builtin

build_flags =
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1

could anyone help me with this