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. Step 0: Installing OpenOCD¶
OpenOCD was installed when you ran the initial ./setup script.
2.1.2. Step 1: Rebuild Application with Debug flag¶
Run:
./build spotless
./build -d HelloWorld
Note
./build spotless will delete all of the files in the obj and bin folder. This is necessary because some files in the lib folder need to be updated with the new -d (debug) flag.
2.1.3. Step 2: Solder JTAG Headers to SJOne¶
Do as the title says if you haven’t already.
2.1.4. Step 3: Connecting BusBlasterv3 to SJOne¶
Connect jumpers from the GND, TRST, TDI, TMS, TCK, and TDO pins on the BusBlasterv3 to the SJOne’s JTAG headers.
Danger
DOUBLE AND TRIPLE CHECK THAT YOUR CONNECTIONS! The SJOne costs $80 and the BusBaster costs $35! Thats $115 down the drain if your burn them out!
2.1.5. Step 4: 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/HelloWorld/HelloWorld.elf
Tip
You can run arm-none-eabi-gdb without arguments and use the following gdb commands
file bin/HelloWorld/HelloWorld.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... kinda started. 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.