Using CLion for Nordic nRF52 projects

Previously we have used nRF5-cmake-scripts to create a CMake project for Nordic nRF52. CLion is a great IDE for developing C and C++ CMake projects, and can also be used to debug the firmware.

First, follow the steps to create a nRF5-cmake-scripts project. When the project is opened in CLion, there is very little left to do.

We need to add a toolchain to use the ARM debugger client. In CLion preferences > Build, Execution, Deployment, create a new toolchain named arm-none-eabi and set the Debugger to “arm-none-eabi-gdb”:

 
Screenshot 2020-01-04 at 22.39.30.png
 

Then we need to use that toolchain for our CMake profile, in CLion preferences > Build, Execution, Deployment > CMake set the Toolchain to “arm-none-eabi”:

 
Screenshot 2020-01-04 at 22.39.40.png
 

Then we just need to create a build configuration. On the top right of the CLion window, click the configuration drop down and “Edit Configurations”. Then Add a new “Embedded GDB Server” configuration:

 
Screenshot 2020-01-04 at 22.40.03.png
 

Configure as shown:

 
Screenshot 2020-01-05 at 11.12.18.png
 
  1. Set a name

  2. Share through VCS to share this with other CLion users of your project

  3. Select the flash_bl_merge_<target> target

  4. Select your executable

  5. Set Download executable to None

  6. Set ‘target remote’ args to “tcp:localhost:2331”

  7. Set GDB Server to “/usr/local/bin/JLinkGDBServer”

  8. Set GDB Server args to “-device nrf52 -strict -timeout 0 -nogui -if swd -speed 1000 -endian little -s“

All done! Now you can build this target, which will build the firmware, bootloader, flash to the softdevice, or you can debug. When debugging, if your breakpoint is not hit when the debugger starts, just press the reset button and continue:

 
Screenshot 2020-01-05 at 11.20.07.png
 

You can also view the state of peripherals on the device when debugging. When debugging click the "Peripherals" tab and click "Load .svd file":

 
6.loadsvd.png
 

Browse to toolchains/nRF5/nRF5_SDK_16.0.0_98a08e2/modules/nrfx/mdk and select the .svd file for your hardware (for nRF52832 use nrf52.svd), then select the peripherals you want to monitor. When the debugger is paused you will then be able to inspect the values of peripheral registers:

 
7.peripherals.png
 
NickComment