Setting up nRF5 compilation and flashing on OSX

Robert Massaioli
3 min readNov 3, 2017

--

This story is the natural continuation of: Using the BLE400 and nRF51822 on OSX. If you have not read that yet then I highly recommend that you do.

In this story I am just going to guide you through the tools that you need to setup in order to be able to compile and run your own programs on your new nRF51822.

Install GCC for ARM

Your first step will be to install a GCC compiler that can compile C programs into something that the Cortex-M0 on your nRF51822 can understand. To do that:

brew install caskroom/cask/gcc-arm-embedded

To ensure that it has worked as expected:

$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors 6-2017-q2-update) 6.3.1 20170620 (release) [ARM/embedded-6-branch revision 249437]
Copyright (C) 2016 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$

You should see something like the message above. In this example, the version of this compiler will be 6.3.1, keep that in mind for later. Also take note of where the files have been linked to on your machine, for me it was /usr/local/bin.

Update your toolchains Makefile.posix

Now that you have successfully installed a GCC compiler that will work with ARM, you need to update your downloaded nRF5 SDK to point to your newly installed GCC compiler. I have my nRF5 SDK under version control (so that I can play around with it and revert easily). You should be making a diff similar to this:

$ git diff
diff --git a/components/toolchain/gcc/Makefile.posix b/components/toolchain/gcc/Makefile.posix
index e4503e4..462f509 100755
--- a/components/toolchain/gcc/Makefile.posix
+++ b/components/toolchain/gcc/Makefile.posix
@@ -1,3 +1,3 @@
-GNU_INSTALL_ROOT := /usr/local/gcc-arm-none-eabi-4_9-2015q3
-GNU_VERSION := 4.9.3
+GNU_INSTALL_ROOT := /usr/local
+GNU_VERSION := 6.3.1
GNU_PREFIX := arm-none-eabi
$

As you can see, I have:

  • Set the GNU_INSTALL_ROOT to /usr/local
  • Set the version to 6.3.1.
    (Which should be the same as the version you received from the previous command)

Install the nRF5x Command Line Tools

Nordic Semiconductor provides a number of command line tools to help your development. You need to download them, unpack them, and make them available in your PATH.

Go to Nordic Semiconductor now to download the nRF5x Command Line Tools.

Once you have downloaded that tarball, unpack it and place it somewhere sensible on your file system. Then you need to include it in your path.

I already have a ~/.bin directory in my path:

PATH="${PATH}:${HOME}/.bin"

So all I needed to do was symlink the command line tools into that directory like so:

$ mkdir -p ~/.bin
$ cd ~/.bin
$ ln -s ~/Code/nordic-semiconductor/nRF5x-Command-Line-Tools_9_7_1_OSX/nrfjprog/nrfjprog .
$ ln -s ~/Code/nordic-semiconductor/nRF5x-Command-Line-Tools_9_7_1_OSX/mergehex/mergehex .

Congratulations! You now have nrfjprog in your PATH. At this point in time you should be able to compile (but not flash) your nRF5x source code.

Install the Segger J-Link tools

When running the flash functionality nrfjprog to upload your code to your device, you will need some of the shared object libraries that Segger provides in their J-Link tooling.

Go to Segger and download the J-Link Software and Documentation pack for MacOSX.

That should give you a pkg file that you should be able to open and install on your machine as a standard OSX installer. Congratulations you now have all of the tooling that you need to run nrfjprog on any project!

Trying it out!

Now that you have setup all of the tooling, you probably want to actually try it out. To do that, use one of the example projects in your downloaded nRF5 SDK (this example is with SDK 12.3.0):

$ cd examples/ble_central_and_peripheral/experimental/ble_app_hrs_rscs_relay/pca10028/s130/armgcc
$ make
$ make flash_softdevice
$ make flash

Congratulations! You should have the relay example flashed to your nRF5 device. Please leave a comment if you have any issues.

--

--