Using J-Link with ESP-IDF and gdbgui for debugging ESP32 applications

Using J-Link with ESP-IDF and gdbgui for debugging ESP32 applications

For folks who want to get started with ESP-IDF and debugging, there might be some common issues that you might face in the path of setting it up.

I have found that there are a few resources to get started like:

https://dzone.com/articles/eclipse-jtag-debugging-the-esp32-with-a-segger-j-l

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/jtag-debugging/using-debugger.html#jtag-debugging-using-debugger-command-line

etc.

These are very good resources to start with. However things got complicated for me to be able to properly get it working.

Firstly, locate where openocd is installed.

In ubuntu, you can check it this way:

raja@raja-IdeaPad-Gaming-3-15IMH05:~/esp32DevelopmentToolChain/esp-idf/projects/EnergyMeter$ whereis openocd
openocd: /usr/bin/openocd /usr/share/openocd /home/raja/.espressif/tools/openocd-esp32/v0.10.0-esp32-20210902/openocd-esp32/bin/openocd /usr/share/man/man1/openocd.1.gz /usr/share/info/openocd.info.gz /usr/share/info/openocd.info-1.gz /usr/share/info/openocd.info-2.gz        

I have found out that scripts could be found in the location:

raja@raja-IdeaPad-Gaming-3-15IMH05:~/.espressif/tools/openocd-esp32/v0.10.0-esp32-20210902/openocd-esp32/share/openocd/scripts$ ls
bitsbytes.tcl  board  chip  cpld  cpu  esp-config.json  fpga  interface  mem_helper.tcl  memory.tcl  mmr_helpers.tcl  target  test  tools        

Now, edit the esp-wroom-32.cfg file as follows:

raja@raja-IdeaPad-Gaming-3-15IMH05:~/.espressif/tools/openocd-esp32/v0.10.0-esp32-20210902/openocd-esp32/share/openocd/scripts/board$ cat esp-wroom-32.cfg 
echo "WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release."
set ESP32_FLASH_VOLTAGE 3.3
adapter_khz 1000
source [find target/esp32.cfg]        

I added adapter_khz to 1000. This is necessary to slow down the the default speed of 20khz.


No alt text provided for this image

I made the connections as per the above wiring diagram.

Then I compiled the code using idf.py build and flashed it via J-LINK as follows:

openocd -f interface/jlink.cfg -f board/esp-wroom-32.cfg -c "program_esp32 build/EnergyMeter.bin 0x10000 verify"        
No alt text provided for this image


Some blogs mention exit after verify – for ex: openocd -f interface/jlink.cfg -f board/esp-wroom-32.cfg -c “program_esp32 build/EnergyMeter.bin 0x10000 verify exit” [DO NOT DO THIS IF YOU INTEND TO START DEBUGGING!]


It seems that the exit at the end closes the port 3333. We want it to continue running. Hence skip exit if you want to start debugging as well.

In a new session, open the gdbgui as follows:

No alt text provided for this image


idf.py gdbgui        

This will open up a new connection at 127.0.0.1:5000

No alt text provided for this image

This is how you get the debugging session started. The same can be integrated with eclipse IDE as well.

Syed Shigarf Mashaam

Delivering world-class Electronics Engineering solutions leveraging deep industry expertise ??

1 年

Good read. Will give it a go.

要查看或添加评论,请登录

Gurajapu Raja Sumant的更多文章

社区洞察

其他会员也浏览了