# Debugging (Depreciated)

{% hint style="warning" %}
This Guide is no longer valid as of Apr 7, 2024. Please see the debugging page under Firmware using West
{% endhint %}

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.

![JLink EDU - Full Size](https://content.gitbook.com/content/qUNtKMqCh2mewM9XembF/blobs/uZIVlpsHwQMSeYPA7Ua2/image.png)

![JLink Edu - Mini](https://content.gitbook.com/content/qUNtKMqCh2mewM9XembF/blobs/u1jep2k5bPicguJTFltZ/image.png)

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

{% embed url="<https://www.segger.com/downloads/jlink/?%253F%253F%253F>" %}

## 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.&#x20;

![EDU Full Size. IOT shown, but is the same connections as BLE version.](https://content.gitbook.com/content/qUNtKMqCh2mewM9XembF/blobs/zAprdYAH0zNWAzAgZDeq/image.png)

![EDU Mini Connection](https://content.gitbook.com/content/qUNtKMqCh2mewM9XembF/blobs/EEtpGV2B7a1nCXz5xrwk/image.png)

### 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.

![](https://content.gitbook.com/content/qUNtKMqCh2mewM9XembF/blobs/aHE0QemrXArfMLEvAKME/image.png)

## VSCode Debugging

![](https://content.gitbook.com/content/qUNtKMqCh2mewM9XembF/blobs/dx7NOwEWzwX6yY9bLig3/image.png)

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.

![](https://content.gitbook.com/content/qUNtKMqCh2mewM9XembF/blobs/ei1RagstsZWZJ3sawLVR/image.png)

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

![](https://content.gitbook.com/content/qUNtKMqCh2mewM9XembF/blobs/b6CAmAAcknRh44ASs7B1/image.png)

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

{% hint style="info" %}
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.
{% endhint %}

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!
