Debugging

This code is getting pretty complicated to be testing with print statements. Since the code runs on a Real time operating system (Zephyr) the processor with be doing a lot of context switches (jumping to different parts of code) it can be difficult to diagnose an issue without a debugger, sometimes even with a debugger :) A print statement badly placed can actually cause a fault. This is why you will need a debugger board if you want to dig deeper into any microcontroller project.

I am using a JLink. The education edition to be more specific which is free for open source use. Full size debugger or mini will work. You should also be able to use a Blackmagic probe and possibly others, but I will not cover that here. The EDU(cation) edition is very well priced and can be found from your favorite electronics suppliers. If you want to work with closed source you cannot use the EDU, and should purchase the full blown version.

Download and install Jlink Software and Docs Package. Follow install guide

Wiring

To wire the debugger to the Nano 33 BLE you will need to solder 5 small wires onto the back of the Nano 33 BLE. Following these guides.

Be sure to firmly secure the wires on the bottom

Highly suggested to use some hot glue and firmly secure the wires that are soldered onto the bottom. I glued the bottom and the bread board at the tie-wrap. Since you are constantly rotating the board around it's pretty easy to rip the small traces off the bottom. This is how my first Nano died.

Debugging using Visual Studio Code, Cortex-Debug and West

Be sure you have Jlink software and Cortex-Debug extension installed in vscode. Some tasks and launch tasks have been setup for some boards in firmware/src/headtracker.code-workspace file. You can use them as a guide to modify or add new ones.

"cortex-debug.JLinkGDBServerPath": "C:/Program Files/SEGGER/JLink",

is set properly.

The pre-launch task is set to compile the code in debug mode before launch continues. After it's successfully build it will upload the code and run.

Debugging with an ESP-PROG via OCD

TO BE COMPLETED On start it always breaks at the code entry point, void main(). Click the Blue play icon to continue execution.

You can add breakpoints wherever you wish, place the red breakpoint dot beside the line to break at.

When the code goes to execute this line it will pause, you can inspect variables, etc.

If your this far through the guide you probably already have an idea how a debugger works! Happy coding. Be sure to create pull requests and submit your changes. Happy coding!

Last updated