2.1. Debugging with OpenOCD and GDB

This tutorial will use HelloWorld as an example. But this will work for any application you build.

2.1.1. Prerequisites

The official supported JTAG probes for the SJOne board is the SEGGER J-LINK mini EDU. Any other J-Link device will work with no modifications to the sjone.cfg file. Otherwise, change the interface/source to the appropriate adapter.

2.1.2. Step 0: Installing OpenOCD

OpenOCD was installed when you ran the initial ./setup script if you are running Linux or WSL. If you are running OS X, install manually.

2.1.3. Step 1: Solder JTAG Headers to SJOne

Do as the title says if you haven’t already.

2.1.5. Step 3: Run OpenOCD

Run:

# If you used make install
openocd -f ./tools/OpenOCD/sjone.cfg

Tip

Successful output is the following:

Info : clock speed 100 kHz
Info : JTAG tap: lpc17xx.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd.), part: 0xba00, ver: 0x4)
Info : lpc17xx.cpu: hardware has 6 breakpoints, 4 watchpoints

Error

If you see the following message:

Error: JTAG-DP STICKY ERROR
Info : DAP transaction stalled (WAIT) - slowing down
Error: Timeout during WAIT recovery
Error: Debug regions are unpowered, an unexpected reset might have happened

Then the SJOne board is being held in a RESET state. To fix this, either by power cycling the SJOne board or by deassert the RTS and DTR signals through GTKTerm.

Error

If you see your terminal get spammed with this:

Error: JTAG-DP STICKY ERROR
Error: Invalid ACK (7) in DAP response
Error: JTAG-DP STICKY ERROR
Error: Could not initialize the debug port

Then its a good chance that one of your pins is not connected.

2.1.6. Step 5: Run GDB

Open another terminal and run the following command in the firmware/default/ folder.

arm-none-eabi-gdb -ex "target remote :3333" bin/firmware.elf

Tip

You can run arm-none-eabi-gdb without arguments and use the following gdb commands file bin/firmware.elf then target remote :3333 in the gdb command line interface to get the same effect as the above command.

At this point the SJOne board has been halted. You should be able to add breakpoints to the program at this point and step through the code.

At this point you will not see any source code. Do the following in the gdb command line interface:

>>> break main
>>> continue

Tip

Don’t use the typical “run” command to start the code. It is already started in the firmware. Also, run does not exist when using target remote :3333 to OpenOCD. It exists with target extended-remote :3333, but causes issues… just don’t use it OK.

At this point you should see the source code of your main.cpp show up. Now you can step through your code and set breakpoints using step, next, finish and continue, break, etc.

For a gdb cheat sheet, see this PDF:

Error

If your board keeps restarting, this is due to the Watchdog not getting fed. Although, this shouldn’t happen if you ran step 0 correctly. If you do a build spotless and build your project again with the -d flag, and this still does not work, then as a last resort, go into the lpc_sys.c file and comment out the enable_watch_dog() function call.