Debugging on ESP32 with OpenOCD and SEGGER J-Link

ESP32 is one of the popular chipsets for Wi-Fi and BLE-based IoT development. ESP32 provides the facility to flash the board via the UART port. However, there is no on-chip debugger available to step debug your program on ESP32. Either you need to buy an ESP Debugger kit or you can use your existing Debugger like J-Link to debug your program. Debugging with J-Link is not explained on official Esperessif Docs. Most Embedded developers have J-Link already available, so it's obvious to use that one instead of purchasing an ESP debugger.

In this post, I'll explain in detail how to use J-Link with ESP32 boards to debug your programs on Ubuntu 20.04 Linux OS.

Please make sure that you have not installed Segger J-Link drivers as we are going to use OpenOCD here.

Before we start the Software part, let's ensure proper hardware connection between J-Link and ESP32 board.

I am using ESP32-S2-WROVER and J-Link Pro for my setup.

ESP32-S2 and J-Link Pro connection

ESP32-S2-WROVER Pin & it's FunctionJ-Link Pin & it's Function
39 (MTCK)TCK
40 (MTDO)TDO
41 (MTDI)TDI
42 (MTMS)TMS
3V3VTRef
GNDGND

Following is the picture of ESP32-S2-WROVER, J-Link 20 Pin header and my setup.











Software Development Environment Setup

In this section, we will focus on setting up the development environment for debugging. I am going to use Eclipse here. However, it is possible to use Visual Studio Code as well.

Follow this guide provided by Espressif to setup Eclipse with ESP-IDF Eclipse plugin.

Once you are done setting up your Eclipse and a sample project, build the project and check its building without errors. After that, let's configure debugger settings for the project so that we can debug the project right from Eclipse.

Debugger setup
  • Right-click on the project, click on Debug As -> Debug configurations.
  • Click on "ESP-IDF GDB OpenOCD Debugging" in left column on Dialog.
  • Click on "New Configuration" Icon on top left corner.
  • You will see that new configuration is filled with default values.
  • Click on the second Debugger tab and modify "Config options:" field with following value.
  • -s ${openocd_path}/share/openocd/scripts -f interface/jlink.cfg -f target/esp32s2.cfg  -c 'adapter_khz 2000'
  • Click on Debug button. Make sure that ESP32 and J-Link are connected to your PC.

You should see in the console log the OpenOCD logs and step debug started in the editor. Enjoy!

Let me know if you face any problems in following these steps. Happy Coding!

Comments

  1. Which version of OpenOCD did you use?

    ReplyDelete
    Replies
    1. Espressif has ported OpenOCD for use with their chipset. I am using v0.10.0-esp32-20200709 version. You can follow steps on Espressif website to compile their ported OpenOCD on your PC and use it.

      Delete
  2. What is the configuration file I need to use on MAC for the JLink to work ?

    ReplyDelete

Post a Comment

Popular posts from this blog

Video Colorspace conversion with ffmpegcolorspace and similar Gstreamer Plugin

Homemade HomeKit supported night light with ESP32