UPDATE (2017-01-24): In my workspace I’m now using SDK 12.2.0, gcc-arm-none-eabi-6_2-2016q4 and Eclipse Neon.2, but these instructions still work.
UPDATE (2018-01-29): In my workspace I’m now using SDK 14.2.0, gcc-arm-none-eabi-7-2017-q4-major and Eclipse Oxygen.2, but these instructions still work with minor changes.
UPDATE (2018-03-08): Finally, Part 2 is available: Starting Development with Nordic nRF5X and GCC on Linux + Eclipse
If you plan to start development using Nordic’s nRF51 or nRF52 series you have 3 options: Use Keil, IAR or gcc. The disadvantages of using the first two (at least for me) is that Keil and IAR run only on Windows. I have my development environment fully set on Linux, specifically, my setup is Gnome Ubuntu 14.04.5 64bits and Eclipse Neon.1. So thinking about switching to Windows, using Wine or running a VM are not enjoyable options for me.
This post is strongly based on this post: Development with GCC and Eclipse by Vidar Berg, posted on devzone.nordicsemi.com. Although this post was published almost 2 years ago and has been updated continuously, I’ve decided to create a new post focusing on a current step-by-step guide from scratch.
Now, the list of components required to complete this guide:
- GNU toolchain for ARM (gcc-arm-none-eabi-5_4-2016q3)
- GNU Make 3.81
- nRF5 SDK 12.1.0
- JLink 6.10g
- nrfjprog version: 9.0.0
- Eclipse Neon (Coming post)
This guide will be split into 2 parts: First, a sample project will be built and flashed to the device without using Eclipse . This is for testing that building tools and programming tools are correctly configured. Then, we will configure Eclipse as our IDE for resource indexing, syntax highlighting, targets programming and for debugging.
1.1 GNU toolchain for ARM
GNU toolchain for ARM can be downloaded from here (Update: newer versions of toolchain are found here). After download it, extract it in a folder of your preference (<INSTALL_PATH>) and then add this path to your OS PATH environment variable. Add this line to .bashrc file in /home/$USER directory
$ export PATH=$PATH:<INSTALL_PATH>/gcc-arm-none-eabi-5_4-2016q3/bin
and then execute
$ source ~/.bashrc
To verify that the path is set correctly, type the following in your terminal and check the output:
$ arm-none-eabi-gcc --version arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496] Copyright (C) 2015 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.
1.2 GNU make
In most of the cases, Ubuntu-based distros already have installed needed tools to build objects from source code using makefiles. You can check this typing:
$ make -v
In the case that make was not recognized, you can get it executing:
$ sudo apt-get install build-essential checkinstall
1.3 nRF5 SDK 12.1.0
Nordic offers an SDK for development on nRF51 and nRF52 series. This SDK includes a wide set of examples for BLE and ANT. You can get the last version (12.1.0 at 2016-11-09) of this from here (Update: SDK 14.2.0 available here). Download it and extract it to the folder of your preference.
Then, to correctly build the included examples, you first have to modify Makefile.posix file located in
Update value of GNU_INSTALL_ROOT variable to match the toolchain path. For the current set up, it should be (from step 1.1):
GNU_INSTALL_ROOT := <INSTALL_PATH>/gcc-arm-none-eabi-5_4-2016q3/ GNU_VERSION := 5.4.3 GNU_PREFIX := arm-none-eabi
Now we can try building one of the included examples.
1.3.1 Building an example
Examples paths in the SDK have the following structure:
The content of examples is
<BOARD_NAME> refers to which platform or hardware distribution will be used, for example, nRF51 DEVKIT, nRF52DEVKIT, nRF51 Dongle, nRF51 Beacon, etc.
<SOFTDEVICE/BLANK> refers to which softdevice is used or blank if a softdevice is not needed.
Within armgcc folder, you could find the linker file and the Makefile.
Now we will try to build a simple example, the blinky example using the board PCA10031. Move to
Execute make and check the output:
Makefile:173: Cannot find include folder: ../../../config/blinky_pca10031 Makefile:173: Cannot find include folder: ../../../config mkdir _build Assembling file: gcc_startup_nrf51.S Compiling file: system_nrf51.c Compiling file: main.c Compiling file: app_error.c Compiling file: app_error_weak.c Compiling file: app_fifo.c Compiling file: app_timer.c Compiling file: app_util_platform.c Compiling file: hardfault_implementation.c Compiling file: nrf_assert.c Compiling file: nrf_drv_clock.c Compiling file: nrf_drv_common.c Compiling file: nrf_nvic.c Compiling file: nrf_soc.c Linking target: _build/nrf51422_xxac.out text data bss dec hex filename 2816 112 84 3012 bc4 _build/nrf51422_xxac.out Preparing: _build/nrf51422_xxac.hex Preparing: _build/nrf51422_xxac.bin
If your output looks like this, you should have a new _build folder containing the output of the build.
1.4 nrfjprog – Programming tool
nrfjprog is a command-line tool to load firmware to the device through SWD debug interface. It is bundled in nRF5x-Command-Line-Tools. Download it and add nrfjprog folder to PATH variable. nrfjprog needs some resources from J-Link, so it is also needed to download and install J-Link software from here. Be sure to install the version that matches your system, 64-bits in my case. (I put this warning because install the wrong version is a common mistake – I know 3 people that did it while following the guide at Nordic site, me included).
After this you can execute nrfjprog from console. Check version with nrfjprog -v and check the output.
$ nrfjprog -v nrfjprog version: 9.0.0 JLinkARM.dll version: 6.10g
1.4.1 Programming the example
Now we will program the previously built example. I’m using the nRF51 Dongle (PCA10031). Move to
and execute the following commands and check the output:
$ nrfjprog --family nRF51 -e Erasing code and UICR flash areas. Applying system reset. $ nrfjprog --family nRF51 --program _build/nrf51422_xxac.hex Parsing hex file. Reading flash area to program to guarantee it is erased. Checking that the area to write is not protected. Programing device. $ nrfjprog --family nRF51 -r Applying system reset. Run.
If your output is similar to this, congratulations! Now you have set up your workspace to develop nRF5X applications in Linux using gcc and you are able to program devices using nrfjprog. The next step is setting up eclipse for doing both from the IDE.
Great Work. Clear and concise. Was looking for 100% Linux based development solution for nRF51-DK and your work was right on the dot. Thank You for the time and effort.
Waiting for Part II of the guide – preferably Eclipse Oxygen (being the latest) instead of Eclipse Neon.
Hi, thanks for your comment. I hope to post the guide for setting up Eclipse Oxygen at the end of the year. Do you have any suggestion on what to include in it?
LikeLiked by 1 person
I’d also really appreciate if you could update it for Eclipse Oxygen as well.
I tried your instructions with SDK 15.2.0 and gcc gcc-arm-none-eabi-7-2018-q2-update.
I did manage to build the blinky example, but I’ve flashed it and it does nothing. I tried flashing the pre-built blinky.hex and that works though.
Something is not compatible and I’m still trying to find out what it is.
LikeLiked by 1 person
Hi Mark, which platform are you using?
Thank you! Years down the line this has now helped me get SDK 17.1.0 (for PCA10040) running under Ubuntu on WSL. Next step, configuring VSCode :).
LikeLiked by 1 person