How to debug¶
The extension offers several options for debugging your application. The default option is to use the recommended nRF Debug tool included with the extension.
Special conditions for debugging apply to applications for multi-core Systems on Chip and devices with readback protection.
Note
Ubuntu users with nRF Connect SDK v1.7.0 need to install the libcurses5 package for debugging to work properly. Run the following command:
sudo apt install libncurses5
How to enable debugging¶
To enable the full set of debugging options for your nRF Connect SDK application, check Enable debug options when you are setting up a build configuration.
When you add a build configuration with this option checked, the following options are automatically set:
Option | Description |
---|---|
CONFIG_DEBUG_OPTIMIZATIONS |
This option limits the optimizations made by the compiler to only those that do not impact debugging. |
CONFIG_DEBUG_THREAD_INFO |
This option adds additional information to the thread object so that the debugger can discover the threads. This will work for any debugger. Additional threads appear in the Call Stack View. |
Enabling the debugging options will affect the application's memory usage.
How to enable debugging after building¶
If you forgot to enable the full set of debugging options during the build configuration step, complete the following steps:
- Right-click the build configuration. The drop-down menu appears.
- Click Edit Build Configuration.
- On the Edit Build Configuration screen, check Enable debug options.
- Click Build Configuration. The build configuration is rebuilt with the debug options enabled.
Note
There is a known issue where debugging may not work if you enable debug options when generating the build configuration. This seems to happen with simple sample applications, such as Blinky. Samples that use threads still seem to work with Enable debug options checked.
To work around this issue, generate the build configuration with Enable debug options unchecked. If this does not resolve the issue, instead of starting the debug session by clicking the Debug Application icon, start debugging by using Run -> Start Debugging or by pressing F5.
How to start debugging with nRF Debug¶
nRF Debug comes integrated with the extension and is meant for debugging applications compatible with the nRF Connect SDK. There are two default options to start debugging with nRF Debug:
- Click on Debug in the Actions View. The debugging toolbar appears at the top of the screen to let you control the debugging process. You also gain access to Debugging Views and the extension-exclusive nRF Debug Panel View.
- Click on Run and Debug from the Activity Bar if you have added a debugging launch configuration.
For more information about general debugging, visit the VS Code debugging documentation for additional information.
How to start debugging with Ozone¶
Alongside the Debug option, the Actions View includes the Debug with Ozone button. This option allows you to start debugging with SEGGER Ozone, the J-Link multi-platform debugger and performance analyzer.
If you have Ozone installed, click the button to start debugging.
How to add Ozone debugging option¶
The option for debugging with Ozone might not be visible in the Actions View. To add it to the View, complete the following steps:
- Make sure you have SEGGER Ozone installed.
- Run
nRF Connect: Debug with Ozone
through the Command Palette. VS Code will notify you that no Ozone is found. - Click Configure path... to provide the path to the Ozone executable file.
- Restart VS Code.
After restart, the Debug with Ozone button will appear in the Actions View.
How to debug applications for a multi-core System on Chip¶
If you are using a multi-core System on Chip (SoC) and want to debug the firmware on all cores simultaneously, you need to set up separate debugging sessions. If you want to debug a one-core SoC or only debug the application core firmware, a single debugging session is enough.
To debug an SoC that contains an application core and a network core:
- Set up two separate debug sessions to debug the firmware running on the application core and on the network core, respectively.
- Once both sessions are established, execute the code on the application core.
The startup code releases the
NETWORK.FORCEOFF
signal to start the network core and allocates the necessary GPIO pins for it. - Start code execution on the network core in the other debug session.
If you want to reset the network core while debugging, make sure to first reset the application core and execute the code.
How to recover a device with readback protection¶
When attempting to debug a device that has readback protection enabled, the debugger may time out with no explanation. The solution is to recover the device using the following steps:
- Use one of the following options to reset the device:
- Run the
nRF Connect: Recover Board
command. - Click the Recover icon in the Connected Devices View.
- Run the
- Once the device has been reset, restart the debugger.