Using J-Link with ESP-IDF and gdbgui for debugging ESP32 applications
Gurajapu Raja Sumant
Embedded systems software developer using C/C++ for products such as PTC HVAC,EV chargers, etc. ISO26262,UDS, OBD.
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:
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.
领英推荐
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"
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:
idf.py gdbgui
This will open up a new connection at 127.0.0.1:5000
This is how you get the debugging session started. The same can be integrated with eclipse IDE as well.
Delivering world-class Electronics Engineering solutions leveraging deep industry expertise ??
1 年Good read. Will give it a go.