In the previous article, we have learnt how to install the IDE. We will now use an example provided by the nRF5 SDK. We should be able to directly build the example found in the SDK, but I don’t like this method because we often need to make some changes and I like to keep the SDK in a pristine state. In this post, we will use the blinky example for the nRF52840DK (pca10056) found in nRF5 SDK 17.1.0. The procedure is almost the same for the other examples and boards.
Firstly we need to create our new project like this:
- Open the menu File -> New -> Project…
- Select the “C Project” found in “C/C++” and goto Next
- Set the project name, we will use blinky
- Set the project type as “Makefile project/Empty project”
- Set the Toolchains as “Arm Cross GCC” and goto Next
- Keep the default configuration and goto Next
- Keep the “xPack GNU Arm Embedded GCC (arm-none-eabi-gcc)” and goto Finish
We now need to copy the files from the SDK:
- Copy nrf5_sdk_17.1.0_ddde560\examples\peripheral\blinky\main.c into the root of our project
- Copy nrf5_sdk_17.1.0_ddde560\examples\peripheral\blinky\pca10056\blank\config\sdk_config.h into config folder of our project
- Copy nrf5_sdk_17.1.0_ddde560\examples\peripheral\blinky\pca10056\blank\armgcc\*.* into the root of our project
We need to adapt the makefile to our folder structure:
- Open makefile from the project explorer
- Change the SDK path:
SDK_ROOT := ../nrf5_sdk_17.1.0_ddde560
- Change the project path:
PROJ_DIR := .
- Change the config path from
We can now build our project.
Access SDK from our project
For easier development, we should be able to access to the SDK directly from the project explorer, for this we define a variable representing the SDK path.
- Open the menu Project -> Properties
- On the left, goto the Resource -> Linked Resources
- Press the “New…” button
- Set the name as
- Set the location as
- Press the “OK” and the “Apply and Close” buttons
We now create a folder linking to the SDK.
- Open the menu File -> New -> Folder
- Press the “Advanced >>” button
- Select “Link to alternate location”
- Press the “Variables…” button
- Select “nRF_SDK_LOC” and press “OK” and “Finish”
From the editor, we can now click on a SDK function while pressing Ctrl. The result? The corresponding declaration will open.
For easier debugging experience, we can install the CMSIS packs that allows visualization of processor registers.
- On the icon bar, click on the CMSIS packs
- Select the “nRF52 Series” from “Nordic Semiconductor”
- Right click on “nRF_DeviceFamilyPack” and install it
We now need to use this pack with our project.
- Open menu Project -> properties
- On the left, goto the C/C++ Build -> Settings
- Select the Devices tab
- Set the device selection to Devices/Nordic Semiconductor/nRF52 Series/nRF52840_xxAA
- Press the “Apply and Close” button
- Open the menu Run -> Debug Configurations…
- Double click on “GDB SEGGER J-Link Debugging”
- Check that C/C++ Application is set to “_build\nrf52840_xxaa.out” (it should be set if the project was build)
- Select the “Debugger” tab
- Set the Device name to “nrf52840_xxaa”
- Press “Apply” and “Close” buttons
- Launch the debug by clicking the debug button
In our blinky example, we have the file config/sdk_config.h that contain more than 3000 lines for configuring the SDK. That’s a lot of configuration for our basic example. Instead we can use the default configuration and only put the overrides in a header file. This simplifies also the porting to another version of the SDK that can have differences in the configuration definitions.
- Replace the sdk_config.h with an empty file (except the multiple inclusion guard) named app_config.h
- Open the makefile
- Add to the INC_FOLDERS
CFLAGS += -DUSE_APP_CONFIG
Our blinky example now works with the default configuration, more complex example will need to add definition into the app_config.h.