Debugging (Depreciated)
Last updated
Last updated
This Guide is no longer valid as of Apr 7, 2024. Please see the debugging page under Firmware using West
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
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.
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.
In platformio.ini set your debug_tool = to the tool you have attached. The git repository code has it pre-set to jlink. Under the Debug tab in VSCode at the top pick - PIO Debug (skip Pre-Debug) this won't try to compile twice every time you start debugging. Compile errors will be listed under debug console tab instead.
To start a debugging session click the green play button beside PIO Debug (skip Pre-Debug) or press F5. Shift-F5 will cancel the session.
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.
Pausing the code will cause issues in some locations. The debugger does not pause the hardware timers on the board, since they continue counting strange results can occur. Using the JLink Ozone debugger does work better if your having issues. It's included when you install the software package from above.
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!