For a research project I am still a part of we are building a device that uses the nRF52832. I wanted to be able to understand the build process, and I also wanted to not be tied down to a proprietary solution (free or non-free). I was still learning how to do building and debugging for embedded systems, and I wanted a full integrated debugging setup, so I went with eclipse.

The nRF52 series uses the nRF SDK in order to develop for its peripherals, as well as interface with the various softdevices that Nordic provides. (A softdevice is just a pre-compiled binary with a header interface that is pre-tested and certified so you don't have to deal with the low level bluetooth stack.)

I'm publishing this here in the hopes that someone, somewhere finds it useful, and as a reference for myself.


You will need to install Eclipse Oxygen (at the time of this writing) - select the CDT C/C++ build environment when you install. Once you have that installed, head over the the Eclipse marketplace, and install the GNU MCU tools. (while you're there you should install the VIM keybindings package as well ;) ) You really only need the ARM cross-compiler and the OpenOCD debugging setups but leaving it at the default options is fine.

You will also need to download the Nordic nRF5 SDK. I would advise downloading the most recent version - Nordic updates these fairly regularly and if you choose an older one it will likely be out of date relatively soon.

Creating the Project

These steps are relatively simple, but it can be frustrating if you miss one of them.

I would advise copying out a template project from the examples directory, as there are a lot of critical things to include that are just already done for you. If you are making a BLE peripheral, there is one present in SDK/examples/ble_peripheral/ble_app_template.

Now you will have to modify the makefile for your particular project. You can find an example makefile/linker script in ble_app_template/pca10040/s132/armgcc. This is for the Nordic pca10040 board, so some things may be incorrect (it depends on which chip you are using). Look around for a suitable one or make your own if you have the knowledge.

You can shuffle around your code and files however you want, there's only a few variables within the makefile that you have to change, the important ones being SDK_ROOT and PROJ_DIR these define the root folders of the SDK and of your project directory, respectively, so they will have to be changed.

You then have to modify the common makefiles. on Windows, and Makefile.posix on a UNIX-like system. These are found in the SDK folder components/toolchain/gcc. These are where you edit your toolchain variables, I also added where to find OpenOCD here. You could do that in the "main" makefile, but it doesn't really matter.

My makefile.posix looks like this:

GNU_INSTALL_ROOT ?= /usr/bin/
GNU_VERSION ?= 4.9.3
GNU_PREFIX ?= arm-none-eabi

OPENOCD_DIR := /usr/local/share/openocd/scripts
OPENOCD_CFG := nrf52-stlink.cfg
OPENOCD_BIN := /usr/local/bin/openocd

You can also use the OpenOCD installed with eclipse, this is just how I had mine set up.

Then you may want to edit the Makefile found in the project directory for your own needs. For example, I added some flashing commands and a clean command to mine, which looks like this:

.PHONY: default help

# Default target - first one defined
default: nrf52832_xxaa

# Print all targets that can be built
    @echo following targets are available:
    @echo       nrf52832_xxaa
    @echo       flash_softdevice
    @echo       sdk_config - starting external tool for editing sdk_config.h
    @echo       flash      - flashing binary

TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc

include $(TEMPLATE_PATH)/Makefile.common

$(foreach target, $(TARGETS), $(call define_target, $(target)))

.PHONY: flash flash_softdevice erase

[... Default targets ...]

SDK_CONFIG_FILE := ../config/sdk_config.h
CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar

.PHONY: openocd_flash 

# Flash the softdevice using OpenOCD
    @echo Using OpenOCD to flash SoftDevice
        -c init -c "reset init" -c halt \
        -c "nrf5 mass_erase" \
        -c "program $(SDK_ROOT)/components/softdevice/s132/hex/s132_nrf52_6.0.0_softdevice.hex verify" \
        -c "program $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex verify" \
        -c reset -c exit

As well, you will need your OpenOCD configuration, which is relatively simple but I'll include mine for convenience.

source [find interface/stlink.cfg]
transport select hla_swd
source [find target/nrf52.cfg]
$_TARGETNAME configure -event gdb-detach { shutdown }

At this point you should be able to build your project and flash it to your board using command line make. If you can't successfully build and flash a program, you will not be able to complete the following steps.

Eclipse build and debug

You will need to change your build settings to use make. Uncheck the "Use default build command" option and change the build command to make. Your build directory should be whichever directory you are storing your makefile in. Change the Build Behaviour so that the default target is blank instead of "all".

Then go to your Project->Properties->C/C++ General->Preprocessor Includes settings. Here you will have to change the CDT GCC Output parser. Replace the compiler command pattern (gcc)|([gc]\+\+)|(clang) with (.*gcc)|(.*[gc]\+\+).

Now you will have to create a new debug configuration. Using the "GDB OpenOCD Debugging" type, make sure you have your project build first. Then you can search for the executable (I use nrf52832_xxaa.out). You will have to change the OpenOCD settings so it uses your configuration. You can also add the SVD stuff so you can view peripheral registers while debugging. Those can be found in the SDK folder modules/nrfx/mdk.

At this point eclipse should be set up.

You can add your custom make targets as well, by right clicking on your project, and using Build Targets->Create.