Re: Using Eclipse with OpenOCD to build and debug ESP32
Posted: Tue Apr 25, 2017 2:35 pm
These are our OSX Setup instructions. We use an FTDI Debugger, but they should work with others. Note the need to manually flash the device before debug.
Debugger Setup
==============
For debug we use the JTAG, OpenOCD and GDB.
The JTAG Hardware is a C232HM-DDHSL-0 although any FTDI compatible 3.3V USB->Serial converter should work.
I explored the use of the standard OpenOCD/GDB pipe technique, but couldn't get it to work.
There is an Eclipse plugin for ARM which works with the ESP32. So that's what I used.
Note that we run from Flash as this version of doesn't not have the ability to run from RAM. So you'll need to "make flash" before doing a debug run. To do this you'll need to disconnect the debugger from its USB port. Don't ask me why. You just do. The other implication of this is that you can only use Hardware Breakpoints of which the ESP32 has two. SIngle stepping uses these BPs and seems to work fine (if slowly)
Note that application code runs on CPU0. You cannot "see" threads on CPU1 via this setup (They appear on different GDB Ports)
OpenOCD
=======
You will need to build openocd-esp32 from this github repository:
https://github.com/espressif/openocd-esp32
Clone it to your home directory.
I used the readme.OSX instructions and built and installed it using Brew.
You will need two ESP32 config files to make openocd work.
Confusingly, they are both called ESP32.cfg
You will find one of them in the "Docs" directory of ESP-IDF. This is the one that openocd uses as a command-line script. It should be copied to the top level of openocd-esp32.
Check that openocd works by doing this:
($YOUR_HOME)/openocd-esp32/src/openocd -s ($YOUR_HOME)/openocd-esp32/tcl -f ($YOURHOME)/openocd-esp32/esp32.cfg
You should see something like:
Open On-Chip Debugger 0.10.0-dev-g90071eb8 (2017-04-18-10:23)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
adapter speed: 200 kHz
force hard breakpoints
Info : clock speed 200 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32.cpu0: Target halted, pc=0x400DBFE8
Eclipse
=======
You will want the CDT Build of Eclipse NEON
https://eclipse.org/cdt/
Once you have installed it, you need the GNU ARM toolkit.
However, before you can install it you will need to modify the security settings of your JVM. You will get this error:
http://gnuarmeclipse.github.io/blog/201 ... all-issue/
Download these 3 files:
http://www.oracle.com/technetwork/java/ ... 33166.html
(2 .jars and a readme)
Look for a directory lib/security under your Java Home directory. Depending oin where and how your JVM executes it may appear in a number of different places.
I did this:
find / -name security
Which identified a couple of likely candidates, and I copied the files into each of them in turn until it worked. There is probably a more scientific approach than this.
Update: Try this directory first: /Library/Java/JavaVirtualMachines/**< jdk_version_of_your_pc >**/Contents/Home/jre/lib/security
You can now go to Eclipse Marketplace and download GNU ARM Eclipse toolkit. Strangely, it seems to need reinstalling every now and again. It tells you when.
Eclipse Debugger Setup
======================
Go to the Debug Configuration Tab (Under "Run")
Create a new GDB OpenOCD Debugging Instance.
Main Tab
Application
($YOUR_HOME)/RPK/build/RPK.elf
Debugger Tab
Tick "Start OpenOCD Locally"
OpenOCD Executable is ($YOUR_HOME)/openocd-esp32/src/openocd
GDB Port is 3333 (This is for CPU0/PRO_CPU for CPU1/APP_CPU use 3334)
Config Options "-s ($YOUR_HOME)/openocd-esp32/tcl -f $(YOUR_HOME)/openocd-esp32/esp32.cfg"
Tick "Allocate Console for OpenOCD"
GDB Client:
Executable is "($YOUR_HOME)/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb"
Startup Tab
Tick "Initial Reset"
Type: init
Tick "Load Symbols"
Use Project Binary "($YOUR_HOME/RPK/build/rpk.elf"
Tick "Pre Run/Restart reset" (Type = halt)
Tick "Set Breakpoint" (breakpoint = app_main)
MenuConfig
==========
Under Components/ESP32-Specific
Make sure Exception/Panic Handlers are JTAG/OCD Aware
(You don't need to disable watchdogs. GDB handles this)
Under Components/FreeRTOS
Make sure "Stop Program on Scheduler start when JTAG/OCD is detected" is enabled.
It gives you an extra break point to step through but it seems to crash without it
And thats it. Simple eh?
Debugger Setup
==============
For debug we use the JTAG, OpenOCD and GDB.
The JTAG Hardware is a C232HM-DDHSL-0 although any FTDI compatible 3.3V USB->Serial converter should work.
I explored the use of the standard OpenOCD/GDB pipe technique, but couldn't get it to work.
There is an Eclipse plugin for ARM which works with the ESP32. So that's what I used.
Note that we run from Flash as this version of doesn't not have the ability to run from RAM. So you'll need to "make flash" before doing a debug run. To do this you'll need to disconnect the debugger from its USB port. Don't ask me why. You just do. The other implication of this is that you can only use Hardware Breakpoints of which the ESP32 has two. SIngle stepping uses these BPs and seems to work fine (if slowly)
Note that application code runs on CPU0. You cannot "see" threads on CPU1 via this setup (They appear on different GDB Ports)
OpenOCD
=======
You will need to build openocd-esp32 from this github repository:
https://github.com/espressif/openocd-esp32
Clone it to your home directory.
I used the readme.OSX instructions and built and installed it using Brew.
You will need two ESP32 config files to make openocd work.
Confusingly, they are both called ESP32.cfg
You will find one of them in the "Docs" directory of ESP-IDF. This is the one that openocd uses as a command-line script. It should be copied to the top level of openocd-esp32.
Check that openocd works by doing this:
($YOUR_HOME)/openocd-esp32/src/openocd -s ($YOUR_HOME)/openocd-esp32/tcl -f ($YOURHOME)/openocd-esp32/esp32.cfg
You should see something like:
Open On-Chip Debugger 0.10.0-dev-g90071eb8 (2017-04-18-10:23)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
adapter speed: 200 kHz
force hard breakpoints
Info : clock speed 200 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32.cpu0: Target halted, pc=0x400DBFE8
Eclipse
=======
You will want the CDT Build of Eclipse NEON
https://eclipse.org/cdt/
Once you have installed it, you need the GNU ARM toolkit.
However, before you can install it you will need to modify the security settings of your JVM. You will get this error:
http://gnuarmeclipse.github.io/blog/201 ... all-issue/
Download these 3 files:
http://www.oracle.com/technetwork/java/ ... 33166.html
(2 .jars and a readme)
Look for a directory lib/security under your Java Home directory. Depending oin where and how your JVM executes it may appear in a number of different places.
I did this:
find / -name security
Which identified a couple of likely candidates, and I copied the files into each of them in turn until it worked. There is probably a more scientific approach than this.
Update: Try this directory first: /Library/Java/JavaVirtualMachines/**< jdk_version_of_your_pc >**/Contents/Home/jre/lib/security
You can now go to Eclipse Marketplace and download GNU ARM Eclipse toolkit. Strangely, it seems to need reinstalling every now and again. It tells you when.
Eclipse Debugger Setup
======================
Go to the Debug Configuration Tab (Under "Run")
Create a new GDB OpenOCD Debugging Instance.
Main Tab
Application
($YOUR_HOME)/RPK/build/RPK.elf
Debugger Tab
Tick "Start OpenOCD Locally"
OpenOCD Executable is ($YOUR_HOME)/openocd-esp32/src/openocd
GDB Port is 3333 (This is for CPU0/PRO_CPU for CPU1/APP_CPU use 3334)
Config Options "-s ($YOUR_HOME)/openocd-esp32/tcl -f $(YOUR_HOME)/openocd-esp32/esp32.cfg"
Tick "Allocate Console for OpenOCD"
GDB Client:
Executable is "($YOUR_HOME)/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb"
Startup Tab
Tick "Initial Reset"
Type: init
Tick "Load Symbols"
Use Project Binary "($YOUR_HOME/RPK/build/rpk.elf"
Tick "Pre Run/Restart reset" (Type = halt)
Tick "Set Breakpoint" (breakpoint = app_main)
MenuConfig
==========
Under Components/ESP32-Specific
Make sure Exception/Panic Handlers are JTAG/OCD Aware
(You don't need to disable watchdogs. GDB handles this)
Under Components/FreeRTOS
Make sure "Stop Program on Scheduler start when JTAG/OCD is detected" is enabled.
It gives you an extra break point to step through but it seems to crash without it
And thats it. Simple eh?