Develop Bluetooth Multirole applications with NRF5 chips and perform In-Circuit debugging

Using the nRF5 SDK hugely speeds up the development of simple and complex Bluetooth applications. The procedure explained here has the following benefits:

  • Uses all-free tools.
  • Keeps all the project configuration in text files, making it ideal for Version Control.
  • Allows using all the libraries and examples provided by Nordic.
  • Uses an Open Source in-circuit debugger to inspect the program while running.

Key concepts


It’s a precompiled and linked binary image implementing a Bluetooth 5.0 low energy protocol stack for the nRF52 Series of SoCs. The Application Programming Interface (API) is declared in C header files.  We will use the S132 which  is a Bluetooth low energy central and peripheral protocol stack.

Environment setup

The tools used will be: Eclipse, GNU compiler collection (GCC), and the GNU Debugger (GDB).




GNU toolchain for ARM Cortex-M (compiler + debugger) and GNU make

  • Dowload and install the latest version.
  • Add the /bin folder to your OS PATH.
  • Test by issuing this on the terminal on any directory:

arm-none-eabi-gcc --version

make -v

Nordic nRF5x SDK

  • Download the latest SDK version.
  • Set the toolchain path and version in or makefile.posix ( <SDK>/components/toolchain/gcc ). Always use forward slash when feeding paths to GNU.

  • Test make in <SDK>/examples/peripheral/blinky/pca10040/blank/armgcc/  You should se the linked .out products and finally the .hex and .bin binaries.

Eclipse IDE and makefile project setup

Install Eclipse Neon for C/C++ developers. You might need the JRE to run Eclipse. JRE 9 does not work well some times due to Java 9 making only some modules available, use another version or try to fix it.

Open Help > Eclipse Marketplace and install the GNU MCU Eclipse plug-in family.

-Or, if it fails that way:

  • Help > Install New Software
  • Click the Add… button (on future updates, select the URL in the Work with: combo)
  • Name: with GNU MCU Eclipse Plug-ins
  • Location: with
  • OK

Install device family pack for the nRF5x series. This provides a memory map of the peripherals, very useful for debugging:

  • Window > perspective > open perspective > other > Packs. Refresh icon. Install Nordic Semiconductor “Device family pack”.

Fill the Build Tools path pointing to the installed tools:

File > Import > Existing Code as Makefile Project (We want to manage the makefile since it’s more versatile than letting the IDE do it for you)

Point it to the root of the desired project folder, it will find the sources.

Then, point the build folder and command to the appropriate sub-folder. Adding verbosity to the make command will ease troubleshooting:

Now, you can Build and the console should show the progress. It will compile, link and generate the .hex and .bin files. Those will be available along with the .o (object files) and .d (detected #include dependencies).


Symbol browsing

In order to support debugging, and optimize it for gdb, the optimization flags should be changed to -O0 -g3 ggdb

To enable automatic symbol discovery, include paths and compiler settings based on the Makefile output:

  • Enter Project Properties -> C/C++->Preprocessor Include Paths,etc.->Providers
  • Click on CDT GCC Build Output Parser and change the compiler command pattern  to (.*gcc)|(.*[gc]\+\+)
  • Click on CDT ARM Cross GCC Built-in Compiler Settings  and replace ${COMMAND} with arm-none-eabi-gcc

Rebuild now. The CDT parser will analyze the output of the make command and all the unresolved symbol errors will go away. Now you can freely browse function declarations and references.


which are set in the makefile can be added to the project for convenience by setting the target name to match the makefile one.

Setting Eclipse up for In-Circuit debugging

This is an awesome feature, you can use a Black Magic Probe  (which you can build for $2 with Open Source code, and forget J-Link), as hardware debugger and inspect the program while it runs live. You can add breakpoints, examine memory, halt execution… and so much more.

BMP includes a GDB server so there is no need to configure and run one while debugging.

Select your Project first, then, open Debug Configurations. Add a new device under GDB Hardware Debugging with a double-click. Set the GDB Command pointing to your gdb binary with your probe serial port, and target selection arguments and untick Use remote target:

  • arm-none-eabi-gdb -q -ex “target extended-remote \\.\COM4″ -ex “monitor swdp_scan” -ex “attach 1”

Connect the BMP debugger to your PC and the target nRF5 device to the BMP via the SWD (Serial Wire Debug) interface.

If you select the default target and click Debug (F11), it should enter the Debug Perspective and show you all the run and debug available tools.


Examine peripherals

Just select your Device (since the whole family was installed before), in the project properties.

Start debugging (F11) and now you can use the Peripherals tab. This is an amazingly useful, since you can not only view the state, but also control the peripherals such as pins.

The nRF5 SDK provides several logging levels that you can enable and redirect to a file or console.