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”:
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”:
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:
Configure as shown:
Set a name
Share through VCS to share this with other CLion users of your project
Select the flash_bl_merge_<target> target
Select your executable
Set Download executable to None
Set ‘target remote’ args to “tcp:localhost:2331”
Set GDB Server to “/usr/local/bin/JLinkGDBServer”
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:
You can also view the state of peripherals on the device when debugging. When debugging click the "Peripherals" tab and click "Load .svd file":
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: