Youcan create a new tool-openocd-esp32 package (new bin/ and share/ versions, package.json with incremented version number) and upload it to a repo or ZIP somewhere. You can then use the per-project directive platform_packages = tool-openocd-esp32 @ (docs) to override the openocd package for the project.
Similar to probe-rs, OpenOCD doesn't have support for the Xtensa architecture. However, Espressif does maintain a fork of OpenOCD under espressif/openocd-esp32 which has support for Espressif's chips.
Once installed, it's as simple as running openocd with the correct arguments. For chips with the built-in USB-JTAG-SERIAL peripheral, there is normally a config file that will work out of the box, for example on the ESP32-C3:
Sometimes you may need to debug each core individually in GDB or with VSCode. In this case, change set ESP_RTOS none to set ESP_RTOS hwthread. This will make each core appear as a hardware thread in GDB. This is not currently documented in Espressif official documentation but in OpenOCD docs: -and-OpenOCD.html
All embedded memory, external memory and peripherals are located on thedata bus and/or the instruction bus of these CPUs. With some minorexceptions, the address mapping of two CPUs is symmetric, meaning theyuse the same addresses to access the same memory. Multiple peripherals inthe system can access embedded memory via DMA.
ESP32 requires a bootloader to be flashed as well as a set of FLASH partitions. This is only needed the first time(or any time you which to modify either of these). An easy way is to use prebuilt binaries for NuttX from here. In there you will find instructions to rebuild these if necessary.Once you downloaded both binaries, you can flash them by adding an ESPTOOL_BINDIR parameter, pointing to the directory where these binaries were downloaded:
Then look at the README and the docs/INSTALL.txt files in theopenocd-esp32 directory for further instructions. There areaseparate README files for Linux/Cygwin, macOS, and Windows. Hereis what I ended up doing (under Linux):
OpenOCD should now be ready to accept gdb connections. If you havecompiled the ESP32 toolchain using Crosstool-NG, or if you havedownloaded a precompiled toolchain from the Espressif website, youshould already have xtensa-esp32-elf-gdb, a version of gdb that canbe used for this
The documentation indicates that you need to use an external JTAGlike the TIAO USB Multi-protocol Adapter and the Flyswatter2.The instructions at =381 showuse of an FTDI C232HM-DDHSL-0 USB 2.0 high speed to MPSSE cable.
The first step converts an ELF image into an ESP32-compatible binaryimage format, and the second step flashes it (along with bootloader image andpartition table binary.)The offset for the partition table may vary, depending on ESP-IDFconfiguration, CONFIG_PARTITION_TABLE_OFFSET, which is by default 0x8000as of writing this.
The argument before app.bin (0x1000) indicates the offset in flash where binarywill be written. ROM bootloader expects to find an application (or second stagebootloader) image at offset 0x1000, so we are writing the binary there.
Instead, the NuttX logic saves and restores CPENABLE on each contextswitch. This has disadvantages in that (1) co-processor context willbe saved and restored even if the co-processor was never used, and (2)tasks must explicitly enable and disable co-processors.
Currently the Xtensa port copies register state save information fromthe stack into the TCB. A more efficient alternative would be to justsave a pointer to a register state save area in the TCB. This wouldadd some complexity to signal handling and also also theup_initialstate(). But the performance improvement might be worththe effort.
3a8082e126