Nordic NRF51 up and running


If you want to know the insides of how to set up a development environment, read on!

If you want Ansible to do all the work for you, skip this post and check out my repos:
* For an Ubuntu VM, use this repo
* For using your Mac natively, use this repo.



There is not much documentation about the NRF51, and the tool-collection hunting and gathering process can be intimidating.
I hope this blog entry will help those that want to use and program the Nordic NRF51 development board to test out BLE functionality.

The hardware

We are using the NRF51 development board, which was purchased from here.

Basic operations

Connecting to the board

Connection is done via conneting a standard Micro USB Cable to your host computer. Once power is supplied to board, it will run the current program automatically.

Communicating with the board

Flashing the device can be done using the JLinkExe program runing on the host computer. JLinkExe can be downloaded from here.

Resetting the board to manufacturer settings

From a terminal window, as the device is connected and turned on, run the following command line:

prompt> JLinkExe -device nrf51822

When the JLink prompt appears, type the following:

J-Link> w4 4001e504 2 
J-Link> w4 4001e50c 1 
J-Link> r 
J-Link> g 
J-Link> exit 

This will erase all the programs that were loaded.

Programming the device

In order to program the device, you must first set up the following tools:

The Nordic SDK

The SDK can be downloaded from the Nordic website here. For our testing, we used nRF51_SDK_v9.0.0. The SDK contains a binary referred to as “SoftDevice” that supports BLE management of the chip. Please see below on how to load the SoftDevice to the board using JLink.

Compiler and Linker toolchain from GNU

The cross-compiler/linker tools that are needed to build executables for the board can be found here. We placed them under ‘/usr/local’. If you have multiple development environments, it may be easier to set an alias to run the right tools rather than modifying the path. For example:

alias gdb51="/usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/arm-none-eabi-gdb"
alias jdb51="jlinkgdbserver -device nrf51822 -if swd -speed 4000 -noir -port 2331”

Loading a binary to the device

An executable image is created in the form of “.HEX” files that has to be loaded to the board’s flash memory. To load it to the device, open a terminal window and run JLinkExe, this time using the loadfile command:

prompt> JLinkExe -device nrf51822 
J-Link> loadfile path-to-binary
J-Link> r  
J-Link> g  
J-Link> exit 

When you program BLE functionality, you will need to load the chip’s firmware in order to support your programs. This is packaged as an executable and is part of the SDK. In order to load the SoftDevice, simply use the loadfile command with the correct path, such as:

J-Link> loadfile SDK_ROOT/components/softdevice/s110/hex/s110_softdevice.hex 
J-Link> r
J-Link> g
J-Link> exit

Select a different path if you want to change the version loaded (in this example, it’s S110).


At this stage, you should have a connected board that has a version of the firmware loaded, and the toolchain downloaded, ready for development to begin!

BLE is hard, but blinking the board is easy

Using the toolchain let’s compile and load the demo blink program that comes with the SDK to make sure we have everything in place for future development.

Making Make make

Here you’ll edit the file named Makefile.posix to point to the correct toolchain for cross-development. The file is found at SDK_ROOT/components/toolchain/gcc/Makefile.posix, where SDK_ROOT being the location you installed the Nordik SDK files.
Edit this file so it contains the path to where you installed the cross-compiler:

GNU_INSTALL_ROOT := /usr/local/gcc-arm-none-eabi-4_9-2015q2
GNU_VERSION := 4.9.3
GNU_PREFIX := arm-none-eabi

Building the blink example

Navigate to the “blink” example directory

cd SDK_ROOT/examples/peripheral/blinky

Depending on your board (the one we used was PCA10028), you might need to create a subdirectory within “blinky” by copying the one present, if your model number does not appear there:

cp -r pcaXXXXX pca10028

Edit the Makefile in the PCA10028/armgcc directory to reference DBOARD_PCA10028, if it’s not already referenced there.

The path to the makefile is: SDK_ROOT/examples/peripheral/blinky/pca10028/s110/armgcc/Makefile.

Once you have saved the modification, return to the terminal window and invoke make to build the image:

prompt> make

in the directory where the makefile is located.

Even though the LED program does not need BLE functionality, let’s load the S110 firmware prior to loading our image for illustrative purposes:

prompt> JLinkExe -device nrf51822
JLink> loadfile SDK_ROOT/components/softdevice/s110/hex/s110_softdevice.hex

And now we’ll load our blink example

JLink> loadfile _build/nrf51422_xxac.hex
JLink> r 
JLink> g

You should now see the board’s four LEDs should blink at a nice rhythm.


Download the jlinkgdbserver debugger from here. When run, it will connect to the board via the serial cable, and wait for commands coming from the GNU debugger, which was included in the GCC download described previously.

To build with debug symbols, invoke make with the debug goal:

prompt> make clean
prompy> make debug

Run the debugger server in a terminal window or tab:

prompt> jlinkgdbserver -device nrf51822 -if swd -speed 4000 -noir -port 2331

Open another terminal window and run your image from the armgcc subdirectory so that JLinkExe will be able to load the debug symbols created when building the application:

prompt> gdb51

This runs the debugger, loading debug symbols which will relay instructions to the JLink server that in turn will relay those to the board.


We made sure that the hardware and the development environment was set up correctly for future application development. In order to take advantage of the hardware’s capabilities, please refer to the documention of the board and firmware here, which contains essential links to the BLE functionality as well as a demo mesh project.


I’d like to thank Tim Kadom, my friend and colleague at ThoughtWorks, who sparked my interest by introducing me to BLE and mesh applications and was instrumental in helping me set up the environment and getting everything to work.


4 thoughts on “Nordic NRF51 up and running

  1. Pingback: Nordic NRF51 and FruityMesh BLE Up and Running | InContext, by Itamar Hassin

  2. Hi Itamar,

    I tried this. blinking LED worked, but I was not able to find the bluetooth device.
    Don’t you think flashing blink hex will overwrite the softdevice hex file ?

    JLink> loadfile _build/nrf51422_xxac.hex

    I think we need to provide location from where the blink hex should be written. If this is right, what should be the memory location for the blink hex ?

  3. Nipun,

    Thanks for your comment, you are absolutely right.

    A fix:
    1. Create a file named upload.jlink and insert this :
    device nrf51822
    speed 1000
    w4 4001e504 2
    w4 4001e50c 1
    loadfile s110_softdevice.hex 0
    loadfile _build/nrf51822_xxac.hex 0x00018000

    As you see, the soft device is loaded at address zero and the app at address 0x00018000

    2. Create a file named and insert this:
    #!/usr/bin/env bash
    jlinkexe upload.jlink

    3. Flash the device using:


    Hope this helps!

    • Thanks Itamar,
      It helped.
      I found a painful to create upload.jlink for new project. more when experimenting with examples.
      So I had created a script, and an alias to it.
      sharing for future readers..

      jlinkexe -if SWD -device nrf51822 -Speed 1000 <<EOF
      loadfile $1 0x00018000

      and in ~/.bashrc

      alias NRFflash='/Users/nipunkanade/development/iot/nrfbox/jlinkScripts/'
      so in a directory with a hex file,
      I just have to execute
      NRFflash xyz.hex and it flashes it to the device 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s