GCC development setup for nRF51822

Bluetooth Low Energy ARM Cortex M0 SoC

Christopher Mason | cmason@cmason.com | http://hg.cmason.com/nrf

This is setup for MacOS, but other OSes can probably be used with some modification.

Note: this has broadened a bit since the notes below were written. They still apply, but this is more than just a demo setup. There's active development going on this repo for a wrapper C++ BLE stack and for EPaper support. Please let me know if this causes you problems.


  • A board with the NRF51822. Examples include:
  • Download of softdevice binary (requires login using product key included in Development Kit) (or older version from here.) Unzip in this directory. You can use some limited functionality (not bluetooth) without this. See release notes below.
  • JLink Software (V4.62a+)
  • arm-none-eabi gcc/binutils/gdb
    I'm targeting pretty recent versions of gcc in order to use modern C++ features. Please use at least 4.7.2. I've built 4.8 locally, which is a pain.
  • libusb: brew install libusb


  1. Set two environment variables with the paths to the Segger binaries and the GCC compiler (see download links above):

    export JLINK_DIR=/usr/local/src/jlink_old export ARM_DIR=/usr/local/src/teensy/gcc-arm-none-eabi-4_7-2013q2/

  2. Due to a bug (?) in the JLink stuff, you must disable the MacOS Communications Device Class (CDC) serial drivers:


  3. Plug in the board.

  4. cd src

  5. If you're using the soft device, you must upload it to the chip the first time you program it:

    make reset
    This erases the flash on the board and reprograms the board with the "soft device". This is also needed if your board gets into a weird state or if you upgrade versions of the soft device binary. If you're not using the soft device (for instance if you didn't buy the Dev Kit), set NRF51_USE_SOFTDEVICE=0 at the top of the makefile and skip this step.

  6. Then, do:

    make main_blink.bin debug
    This will compile the main_blink program, launch GDB, load the binary, and stop at a breakpoint at the start of main(). You can repeat this step as you edit your program, there's no need to do the reset step every time.

  7. You can add additional main programs called main_foo.c.

  8. If you copy the following files from the nordic SDK (nordic/nrf51822/Board/nrf6310/ble/ble_app_hrs/):

  • ble_bondmngr_cfg.h
  • main.c (rename to main_hrs.c)
  1. And then do:

    make main_hrs.bin debug

  2. To test, grab the Apple Heart Rate Monitor sample code and compile and run it with XCode. It should connect to the dongle over BLE.


Programming Error: Recent versions of the Segger tools intermittently produce this error when programming the soft device:

****** Error: Programming failed @ address 0x10001010 (block verification error) Verification failed @ address 0x00000000 I see this with version 4.74 of the Segger Mac tools, but not with 2.69a. See discussion here.

Debug Console: I'm trying to get either UART serial or semihosting debug console working, so far without terribly much success. I can get the UART to work but I haven't


Standing on the shoulders of giants here.

Profuse thanks to Paul Stoffregen, whose teensy 3 has taught me so much and whose makefiles and linker scripts this builds on heavily.


21 Sep 13 - Updated to Nordic SDK v4_4_0_30888 and soft device 5.2.1. This is somewhat of a hack right now because I'm trying to compile large parts of their SDK without choosing specifically what parts to compile and some of their files don't compile or link alongside other of their files.

6 Oct 13 - Update to allow some features without the Nordic SDK download (ie without having bought a Dev Kit). Edit the Makefile and set NRF51_USE_SOFTDEVICE=0. Skip the make reset step.

Other useful resources/posts:

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.