This document provides a guide to installing OpenOCD for ESP32-S2 and debugging using GDB. The document is structured as follows:
Introduction to the purpose of this guide.
- How it Works?
Description how ESP32-S2, JTAG interface, OpenOCD and GDB are interconnected and working together to enable debugging of ESP32-S2.
- Selecting JTAG Adapter
What are the criteria and options to select JTAG adapter hardware.
- Setup of OpenOCD
Procedure to install OpenOCD and verify that it is installed.
- Configuring ESP32-S2 Target
Configuration of OpenOCD software and set up JTAG adapter hardware that will make together a debugging target.
- Launching Debugger
- Debugging Examples
- Building OpenOCD from Sources
- Tips and Quirks
This section provides collection of tips and quirks related JTAG debugging of ESP32-S2 with OpenOCD and GDB.
Espressif has ported OpenOCD to support the ESP32-S2 processor and the multicore FreeRTOS, which will be the foundation of most ESP32-S2 apps, and has written some tools to help with features OpenOCD does not support natively.
This document provides a guide to installing OpenOCD for ESP32-S2 and debugging using GDB under Linux, Windows and MacOS. Except for OS specific installation procedures, the s/w user interface and use procedures are the same across all supported operating systems.
Screenshots presented in this document have been made for Eclipse Neon 3 running on Ubuntu 16.04 LTS. There may be some small differences in what a particular user interface looks like, depending on whether you are using Windows, MacOS or Linux and / or a different release of Eclipse.
How it Works?¶
The key software and hardware to perform debugging of ESP32-S2 with OpenOCD over JTAG (Joint Test Action Group) interface is presented below and includes xtensa-esp32s2-elf-gdb debugger, OpenOCD on chip debugger and JTAG adapter connected to ESP32-S2 target.
Under “Application Loading and Monitoring” there is another software and hardware to compile, build and flash application to ESP32-S2, as well as to provide means to monitor diagnostic messages from ESP32-S2.
Debugging using JTAG and application loading / monitoring is integrated under the Eclipse environment, to provide quick and easy transition from writing, compiling and loading the code to debugging, back to writing the code, and so on. All the software is available for Windows, Linux and MacOS platforms.
If the ESP-S2-Kaluga-1 is used, then connection from PC to ESP32-S2 is done effectively with a single USB cable. This is made possible by the FT2232H chip, which provides two USB channels, one for JTAG and the one for UART connection.
Depending on user preferences, both debugger and idf.py build can be operated directly from terminal/command line, instead from Eclipse.
Selecting JTAG Adapter¶
The quickest and most convenient way to start with JTAG debugging is by using ESP-S2-Kaluga-1. Each version of this development board has JTAG interface already built in. No need for an external JTAG adapter and extra wiring / cable to connect JTAG to ESP32-S2. ESP-S2-Kaluga-1 is using FT2232H JTAG interface operating at 20 MHz clock speed, which is difficult to achieve with an external adapter.
If you decide to use separate JTAG adapter, look for one that is compatible with both the voltage levels on the ESP32-S2 as well as with the OpenOCD software. The JTAG port on the ESP32-S2 is an industry-standard JTAG port which lacks (and does not need) the TRST pin. The JTAG I/O pins all are powered from the VDD_3P3_RTC pin (which normally would be powered by a 3.3 V rail) so the JTAG adapter needs to be able to work with JTAG pins in that voltage range.
On the software side, OpenOCD supports a fair amount of JTAG adapters. See http://openocd.org/doc/html/Debug-Adapter-Hardware.html for an (unfortunately slightly incomplete) list of the adapters OpenOCD works with. This page lists SWD-compatible adapters as well; take note that the ESP32-S2 does not support SWD. JTAG adapters that are hardcoded to a specific product line, e.g. ST-LINK debugging adapters for STM32 families, will not work.
The minimal signalling to get a working JTAG connection are TDI, TDO, TCK, TMS and GND. Some JTAG debuggers also need a connection from the ESP32-S2 power line to a line called e.g. Vtar to set the working voltage. SRST can optionally be connected to the CH_PD of the ESP32-S2, although for now, support in OpenOCD for that line is pretty minimal.
ESP-Prog is an example for using an external board for debugging by connecting it to the JTAG pins of ESP32-S2.
Setup of OpenOCD¶
If you have already set up ESP-IDF with CMake build system according to the Getting Started Guide, then OpenOCD is already installed. After setting up the environment in your terminal, you should be able to run OpenOCD. Check this by executing the following command:
The output should be as follows (although the version may be more recent than listed here):
Open On-Chip Debugger v0.10.0-esp32-20190708 (2019-07-08-11:04)
Licensed under GNU GPL v2
For bug reports, read
You may also verify that OpenOCD knows where its configuration scripts are located by printing the value of
OPENOCD_SCRIPTS environment variable, by typing
echo $OPENOCD_SCRIPTS (for Linux and macOS) or
echo %OPENOCD_SCRIPTS% (for Windows). If a valid path is printed, then OpenOCD is set up correctly.
If any of these steps do not work, please go back to the setting up the tools section of the Getting Started Guide.
It is also possible to build OpenOCD from source. Please refer to Building OpenOCD from Sources section for details.
Configuring ESP32-S2 Target¶
Once OpenOCD is installed, move to configuring ESP32-S2 target (i.e ESP32-S2 board with JTAG interface). You will do it in the following three steps:
Configure and connect JTAG interface
Upload application for debugging
Configure and connect JTAG interface¶
This step depends on JTAG and ESP32-S2 board you are using - see the two cases described below.
Once target is configured and connected to computer, you are ready to launch OpenOCD.
Open a terminal and set it up for using the ESP-IDF as described in the setting up the environment section of the Getting Started Guide. Then run OpenOCD (this command works on Windows, Linux, and macOS):
openocd -f board/esp32s2-kaluga-1.cfg
The files provided after
-f above are specific for ESP32-S2-Kaluga-1 board. You may need to provide different files depending on used hardware. For guidance see Configuration of OpenOCD for specific target.
board/esp32c3-ftdi.cfg can be used for a custom board with an FT2232H or FT232H chip used for JTAG connection,
or with ESP-Prog.
You should now see similar output (this log is for ESP32-S2-Kaluga-1 board):
user-name@computer-name:~/esp/esp-idf$ openocd -f board/esp32s2-kaluga-1.cfg
Open On-Chip Debugger v0.10.0-esp32-20200420 (2020-04-20-16:15)
Licensed under GNU GPL v2
For bug reports, read
adapter speed: 20000 kHz
force hard breakpoints
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 20000 kHz
Info : JTAG tap: esp32s2.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32s2: Debug controller was reset (pwrstat=0x5F, after clear 0x0F).
Info : esp32s2: Core was reset (pwrstat=0x5F, after clear 0x0F).
If there is an error indicating permission problems, please see the “Permissions delegation” bit in the OpenOCD README file in
In case there is an error finding configuration files, e.g.
Can't find board/esp32s2-kaluga-1.cfg, check
OPENOCD_SCRIPTSenvironment variable is set correctly. This variable is used by OpenOCD to look for the files specified after
-f. See Setup of OpenOCD section for details. Also check if the file is indeed under provided path.
If you see JTAG errors (…all ones/…all zeroes) please check your connections, whether no other signals are connected to JTAG besides ESP32-S2’s pins, and see if everything is powered on.
Upload application for debugging¶
Build and upload your application to ESP32-S2 as usual, see Step 8. Build the Project.
Another option is to write application image to flash using OpenOCD via JTAG with commands like this:
openocd -f board/esp32s2-kaluga-1.cfg -c "program_esp filename.bin 0x10000 verify exit"
OpenOCD flashing command
program_esp has the following format:
program_esp <image_file> <offset> [verify] [reset] [exit]
image_file- Path to program image file.
offset- Offset in flash bank to write image.
verify- Optional. Verify flash contents after writing.
reset- Optional. Reset target after programing.
exit- Optional. Finally exit OpenOCD.
You are now ready to start application debugging. Follow steps described in section below.
The toolchain for ESP32-S2 features GNU Debugger, in short GDB. It is available with other toolchain programs under filename: xtensa-esp32s2-elf-gdb. GDB can be called and operated directly from command line in a terminal. Another option is to call it from within IDE (like Eclipse, Visual Studio Code, etc.) and operate indirectly with help of GUI instead of typing commands in a terminal.
Both options of using debugger are discussed under links below.
This section is intended for users not familiar with GDB. It presents example debugging session from Eclipse using simple application available under get-started/blink and covers the following debugging actions:
Similar debugging actions are provided using GDB from Command Line.
Before proceeding to examples, set up your ESP32-S2 target and load it with get-started/blink.
Building OpenOCD from Sources¶
Please refer to separate documents listed below, that describe build process.
The examples of invoking OpenOCD in this document assume using pre-built binary distribution described in section Setup of OpenOCD.
To use binaries build locally from sources, change the path to OpenOCD executable to
src/openocd and set the
OPENOCD_SCRIPTS environment variable so that OpenOCD can find the configuration files. For Linux and macOS:
Example of invoking OpenOCD build locally from sources, for Linux and macOS:
src/openocd -f board/esp32s2-kaluga-1.cfg
src\openocd -f board/esp32s2-kaluga-1.cfg
Tips and Quirks¶
This section provides collection of links to all tips and quirks referred to from various parts of this guide.
- Tips and Quirks
- Breakpoints and watchpoints available
- What else should I know about breakpoints?
- Flash Mappings vs SW Flash Breakpoints
- Why stepping with “next” does not bypass subroutine calls?
- Support options for OpenOCD at compile time
- FreeRTOS support
- Optimize JTAG speed
- What is the meaning of debugger’s startup commands?
- Configuration of OpenOCD for specific target
- How debugger resets ESP32-S2?
- Do not use JTAG pins for something else
- JTAG with Flash Encryption or Secure Boot
- Reporting issues with OpenOCD / GDB