Cannot run debugger on ESP32-C6

Hello,

i’m struggling with the built-in debugger of ESP32-C6 with PlatformIO in VSCode.

Building a project and uploading it to my ESP32-C6 on my own pcb works fine with PlatformIO in VSCode but debugging fails with the following error code
GDB failed

Debugging using the ESP-IDF via command line like this post descibed it Using Debugger - ESP32-C6 - — ESP-IDF Programming Guide latest documentation works fine.

Why does the debugging session fails from PlatformIO? Or is there no debug support for the ESP32-C6 from PlatformIO so far?

Debugging the ESP32-C6 should be similiar to the S3 and C3 with debug_tool = esp-builtin. So you should have a look at How to use JTAG built-in debugger of the ESP32-S3 in PLATFORMIO and check the basics, e.g. that you see a “USB Jtag/serial debug unit” in your device manager and that you load WinUSB drivers for that using Zadig. Otherwise OpenOCD won’t be able to access it all.

Also, more detailed error messages should be in the “Debug Console” tab in VSCode.

It can also be the case that PlatformIO has not yet updated its Espressif32 OpenOCD packages yet, making it incapable of communicating with the ESP32C6 target. That would need bug report filing in Issues · platformio/platform-espressif32 · GitHub. The current one is 6 months old (PlatformIO Registry).

1 Like

I think the problem is the used version of OpenOCD.

When i debug in VSCode the OpenOCD version 11 is used and when i do openocd --version in ESP-IDF directly it use the version 12. ESP32-C6 support was addet in version 12 of OpenOCD.

But how can i change to version 12 in PlatformIO?

Add

platform_packages =
   tool-openocd-esp32@~2.1200.0

to the platformio.ini to make it use the OpenOCD v0.12 version. Does it fare better?

1 Like

After adding your code to platformio.ini and the following code to esp32-c6-devkitc-1.json

"debug": {
    "openocd_board": "esp32c6-builtin.cfg"
  },

The ESP32-C6 device is found but the debugging also fails. With this error log

Warn : No symbols for FreeRTOS!
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Error: Algorithm timed out after 40001 ms.
Info : [esp32c6] Halt cause (5) - (PMP Load access fault)
Error: ra = 0x408012a2
Error: sp = 0x40804700
Error: gp = ...
...
Error: t6 = 0x0
Error: pc = 0x40800000
Error: mstatus = 0x1800
Error: mepc = 0x40800000
Error: mcause = 0x5
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: Failed to run flasher stub (-4)!
Error: Target is already running an algorithm
Error: Failed to start algorithm (-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
.pioinit:11: Error in sourced command file:
Remote communication error.  Target disconnected.: No error.

I think it’s still not the right OpenOCD version, PlatformIO probably has the 20230419 version when it needs 20230921?

You can try and copy over the correct OpenOCD version to C:\Users\<user>\.platformio\packages\tool-openocd-esp32 (while keeping the package.json untouched), sourced from either your working ESP-IDF’s OpenOCD version or Releases · espressif/openocd-esp32 · GitHub.

1 Like

With this version it works before in ESP-IDF but unfortunately it’s broken and ESP-IDF throw the same error like PlatformIO now…

Need to have another try tomorrow.

For all having this problem in the future…

I tested it with the same version of OpenOCD and GNU gdb (esp-gdb) in PlatformIO and directly in ESP-IDF. I run into the same error code.

After reinstalling the full version of ESP-IDF + Driver and watching the following video series https://www.youtube.com/@YuriR/videos i got my ESP-IDF working. I posted my necessary codes from .vscode folder here https://www.esp32.com/viewtopic.php?f=12&t=36501&sid=c7f0bae5598bc5921283c3b280b4b5ba to get it working on ESP32-C6.

After all it was also possible for me to create and build a project in PlatformIO and debug the {project}.elf file via the ESP-IDF and the debugging session will start. But i will use the ESP-IDF directly because it’s easier until the ESP32-C6 is fully compatible by PlatformIO.

1 Like

I’ve opened an issue with the developers at https://github.com/platformio/platform-espressif32/issues/1224 to get it tracked in PlatformIO, otherwise this entire conversation will be lost to the winds.

1 Like