GCC development setup for nRF51822
Bluetooth Low Energy ARM Cortex M0 SoC
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.
brew install libusb
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/
Due to a bug (?) in the JLink stuff, you must disable the MacOS Communications Device Class (CDC) serial drivers:
Plug in the board.
If you're using the soft device, you must upload it to the chip the first time you program it:
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.
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.
You can add additional main programs called main_foo.c.
If you copy the following files from the nordic SDK (nordic/nrf51822/Board/nrf6310/ble/ble_app_hrs/):
- main.c (rename to main_hrs.c)
And then do:
make main_hrs.bin debug
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.
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: