OpenOCD/GDB Debugging on ESP32

Hello everyone, I’m trying to debug the ESP32-Ethernet-Kit V1.2 Board using gnrc_networking example.

Flashing and starting RIOT itself with PROGRAMMER=openocd USEMODULE=esp_jtag BOARD=esp32-ethernet-kit-v1_2 make all flash term PORT=/dev/ttyUSB1 works fine.

But when I’m trying to start debugging with PROGRAMMER=openocd USEMODULE=esp_jtag BOARD=esp32-ethernet-kit-v1_2 make debug PORT=/dev/ttyUSB1 it throws this warnings:

Warning: while parsing target description (at line 4): Target description specified unknown architecture "xtensa" Warning: Could not load XML target description; ignoring and just crashes afterwards.

Then I tried to start OpenOCD manually and it throws following errors: Info : [esp32.cpu0] Examination succeed Error: Unexpected OCD_ID = 00000000 Error: [esp32.cpu1] Examination failed

Then I can start GDB and somehow connect to cpu0 to start actual debugging. But then there is always only one thread. Sometimes after connecting, OpenOCD throws error which says something like Couldn't determine the number of threads for FreeRTOS but I cannot always recreate it.

I am newbie here and really confused about it and about cpu0 and cpu1. Is there a way to switch somehow to another target? I feel that I might be missing something.

Does anyone here have any experience in debugging with OpenOCD/GDB or in working with ESP32 and might have any idea how to solve this? I would be really grateful for any clues. Thanks in advance for your support!

I found a bit similar issue with OpenOCD for ESP32 here. Unfortunately it doesn’t provide any solutions. I thought maybe this issue appears in newer versions only.

Then I tried using an older version of OpenOCD, namely v0.11.0-esp32-20211220 which is directly provided by toolchain for ESP32 installed from RIOT. Still getting the same problem with esp32.cpu1 but slightly different message: Warn : target esp32.cpu1 examination failed

Then I am able to start debugging with GDB (GNU gdb (esp-gdb) 11.1_20220318) but OpenOCD starts throwing the following error: Error: Don't have the number of threads in FreeRTOS!

So here’s the way to recreate it:

  1. Activate toolchain: . ../../dist/tools/esptools/export.sh all
  2. Flash an application on board: USEMODULE=esp_jtag BOARD=esp32-ethernet-kit-v1_2 make all flash term PORT=/dev/ttyUSB1
  3. Start OpenOCD: openocd -f /*path-to-openocd*/openocd-esp32/tcl/board/esp32-ethernet-kit-3.3v.cfg
  4. Start GDB with: xtensa-esp32-elf-gdb -x gdbinit bin/esp32-ethernet-kit-v1_2/gnrc_networking.elf

I am confused on how to configure OpenOCD for RIOT-OS/ESP32.

Thank you.

Hi!

First, sorry for the late reply. Working with Espressif’s MCUs is always a bit of a pain, as the tools are not fully upstreamed. Please try it again with the downstream OpenOCD version from Espressif combined with the downstream GDB from them. That should work … most of the time. You sadly will not get the “works out of the box” experience you’ll get with MCUs where the tooling is fully upstreamed with Espressif for now. (But there are people working to get things upstream, so there is still hope.)

The Error: Don't have the number of threads in FreeRTOS! is expected, though: The ESP SDK assumes that FreeRTOS is uses as OS and in fact the WiFI driver is hardwired to the FreeRTOS ABI. This is why the RIOT port to ESP MCUs is emulating FreeRTOS ABIs in order to use WiFi on those MCUs.

The upstream OpenOCD has support for RIOT. It may be that OpenOCD will test for FreeRTOS before RIOT and that the compatibility stuff will cause OpenOCD to assume the FreeRTOS is run instead of RIOT. Maybe try passing configure -rtos RIOT to OpenOCD?

I hope I was able to shed some light. Feel free to ask again if you still have trouble to get it working.