Here at Electronut Labs, we work extensively on Bluetooth Low Energy technology, and we have chosen Nordic Semiconductors nRF5x series boards for developing our products.
We really like Visual Studio Code editor for development. Their UI is very modern and slick, and they provide nice extensions which will make your coding tasks easier. I am going to talk about one useful extension for debugging here – Cortex Debug – which adds debugging support for ARM Cortex-M Microcontrollers.
Cortex Debug on Visual Studio Code is very fast and efficient. I will show you how to set it up, and this setup is going to work with any nRF5x development boards. Later, I am going to show you how to debug on our nRF5x breakout board hackaBLE and program it using Bumpy, our SWD programmer.
Before talking about debugging, we will set c/c++ configuration settings which will make coding and debugging very convinient. After adding c/c++ configuration settings you can directly go to a function definition by just clicking on it. Click on view from the menu and select c/cpp edit configurations and it will open c_cpp_properties.json file then write this congiguration settings as shown below(note: I’ve only added path for linux machine, you can add your own paths depending on your machine).
For example, if you right click on ble_stack_init() and select go to definition
You will directly go to the function definition.
This configuration settings will reduce your time as well as effort while you are debugging.
Setting up Cortex Debug configuration in VSCode
Debugging ble_app_hrs example from nRF5 SDK.
Before setting up Cortex Debug you need to install the following:
- ARM GCC Toolchain provides arm-none-eabi-gdb related tools.
- J-Link Software tools provides J-Link GDB server for J-Link based debggers.
Then you will need the following extensions.
- Install C/C++ Extension.
- Install Intellisense.
- Install Cortex Debug
The installation screens are shown below.
After this last step is to set configuration properties in launch settings. Go to debug menu and click add configurations. Now you can see launch.json file. Now edit this file and add the following.
Your launch.json file should look like this.
Now, you are all set to debug your project. Go to Debug menu in Visual Studio code and select start debugging. you will see a small tab menu will appear, like this.
If you hover over the menu you will see it will allow you to step through, step into, step out, restart and stop the debugging. You also see three windows in the left for variable, stack and watch, this will keep track of all the variables currently present in the scope, the program stack.
As you can see it is very fast and easy to use.
Debugging hackaBLE using Bumpy
I would like to briefly introduce our products hackaBLE and Bumpy before proceding further.
hackaBLE is a tiny (~ 18 mm x 28 mm) Open Source Nordic nRF52832 based BLE development board you can embed in your BLE projects.
Bumpy is an inexpensive Open Source blackmagic probe compatible SWD debugger designed to be used with ARM GDB. It supports many platforms, but was primarily designed for use with our Nordic Semiconductor nRF BLE boards.
Setting up Cortex Debug configurations for Bumpy
Since Bumpy is blackmagic probe based SWD debugger you need to set its specific launch settings. Here’s what you need to write in launch.json file for configuring debugging in VS Code.
As you can see most of the configuration properties are same as before, except the ones specific for blackmagic probe debugger. And, now you use Bumpy to debug on your project.
In this article we saw how you can easily set up and configure Cortex Debug Extention in Visual Studio Code. We also showed you how to debug using Bumpy, our blackmagic SWD programmer. Hope you find this article helpful.
I want to thank Tavish from Electronut Labs for suggesting us to use Cortex Debug.
- Cortex Debug Project by marcelball.