Posted on

Setting up makefile development environment for nrf51822 in Linux

I have recently set up the development environment for the nrf51822 SoC. I have a Development Kit (DK) of this IC, which for 99$ is quite a bang for the buck. A Development or Evaluation kit is necessary to access all the support documents, codes and binaries at Nordic Semiconductor’s page (or not, based on your web searching skills :P). The steps are based on the instructions provided here, so take a look at that helpful post too.

Step 1: For using the J-Link programmer/debugger, download the its software from here. You’ll need to have the serial number of the JLink unit to do this.  Download the 32 or 64 bit rpm or deb file based on the OS that you have. On 64 bit Ubuntu 13.10, the 4.80 deb file installs the software to /opt/SEGGER/JLink

Step 2: I prefer using the GNU-GCC toolchain to Sourcery Codebench.  Download the Linux pre-compiled tarball and extract to a convenient location.

Step 3: Register as a user in and enter the product key of your DK or EK to get access to the nrf51822 SDK. Download the nRF51-SDK-zip not the .msi installer. This SDK contains documentation and lots of example codes.  Extract the SDK to a convenient location.

Step 4: Download and extract this zip which is a compressed version of a demo project which lights up the green LED  and echos whatever is sent through the serial port. Many files  from the SDK that you get from step 3 are removed in this. This is because of the current license of the SDK which prevents us from sharing any of its files. Hopefully this will change soon if what is mentioned here is true.

Before deleting the SDK files, the file structure is as shown below. Copy the necessary files from the SDK as shown in the structure below.

|-- bin
|-- build
|-- include
| |-- board.h
| |-- gcc
| | |-- compiler_abstraction.h
| | |-- core_cm0.h
| | |-- core_cmFunc.h
| | `-- core_cmInstr.h
| |-- nrf
| | |-- common.h
| | |-- nordic_common.h
| | |-- nrf51_bitfields.h
| | |-- nrf51_deprecated.h
| | |-- nrf51.h
| | |-- nrf.h
| | `-- system_nrf51.h
| `-- peripherals
| |-- nrf_delay.h
| |-- nrf_gpio.h
| `-- simple_uart.h
|-- link
| |-- gcc_nrf51_blank_xxaa.ld
| |-- gcc_nrf51_common.ld
| `-- gcc_nrf51_s110_xxaa.ld
|-- Makefile
|-- obj
|-- src
| |-- gcc_startup_nrf51.s
| |-- main.c
| |-- nrf_delay.c
| |-- simple_uart.c
| `-- system_nrf51.c

I have sourced this from this link. Thanks a lot. The makefile was wonderfully made. I have made it better in some aspects. The approach taken is that all the .c and .s (assembly) files must be in src folder. A ‘link’ folder is added to store the linker files. Few changes in the CFLAG has made this version compatible with GDB debugging in eclipse. Comment if you want some info about the makefile. More on setting up eclipse in the next post. The file is made to be used by the ‘External Tools’ in eclipse.

Step 5:  Open the make file and edit the location of GNU-GCC tool-chain that you extracted in step 2. The GCC_INSTALL_ROOT and GCC_VERSION variables must be correct. Save it. Open Teminal (Ctrl + Alt + T) and navigate to where you have extracted the nrf51Demo project. Here are the make targets which I have used:

make all : Compiles the project
make clean : Cleans all object, output, map files etc.
make upload : Uploads to MCU the build/main.bin
make erase-all : Erases entire contents of memory

The next post in this series will be to setup eclipse to use this project with debugging. The zip file that is you’ve downloaded can be used to import an eclipse project if you want to get started already.

About prithvirajnarendra

Geek. Introvert. Empathetic. Wannabe entrepreneur. Traveler.

2 responses to “Setting up makefile development environment for nrf51822 in Linux

  1. Marvin

    Hey man, awesome posts! Keep it up. I’m playing around with Bluetooth too. Huge help.

Wanna reply?

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s