This time round, we’ll have a look at setting up the development environment for the nRF51 development board on Linux. This board and microcontroller in particular are showing their age at this point, but all the code is easily transferable to the newer Nordic nRF52 series devices. The Nordic SDK does a great job in abstracting the all the interactions between software and hardware.

Here are the prerequisites for our development environment:

  • nRF51 development kit (details)
  • Nordic nRF5 SDK version 12.3 (download)
  • nRF Command Line Tools (download)
  • SEGGER J-Link software (download)
  • GNU make (available in your repositories if you are using Linux/BSD)
  • GNU Arm Embedded Toolchain- latest version is 9-2020-q2-update (download)

Extract the SDK and toolchain to locations of your choice. Make a note of both paths; we will need to edit a couple of files which use these paths.

Navigate to <SDK_LOCATION>/components/toolchain/gcc and edit Makefile.posix. GNU_INSTALL_ROOT should point to the location of the toolchain on your disk:

GNU_INSTALL_ROOT := /path/to/gcc-arm-none-eabi-9-2020-q2-update
GNU_VERSION := 9.3.1
GNU_PREFIX := arm-none-eabi

Let’s try and build an example project to test our toolchain. Navigate to <SDK_DIR>/examples/peripheral/blinky_freertos/pca10028/blank/armgcc in a terminal and run make. You should see the following output:

❯ make
mkdir _build
Compiling file: nrf_log_backend_serial.c
Compiling file: nrf_log_frontend.c
Compiling file: app_button.c
Compiling file: app_error.c
Compiling file: app_error_weak.c
Compiling file: app_timer_freertos.c
Compiling file: app_util_platform.c
Compiling file: nrf_assert.c
Compiling file: sdk_errors.c
Compiling file: croutine.c
Compiling file: event_groups.c
Compiling file: heap_1.c
Compiling file: list.c
Compiling file: port.c
Compiling file: port_cmsis.c
Compiling file: port_cmsis_systick.c
Compiling file: queue.c
Compiling file: tasks.c
Compiling file: timers.c
Compiling file: boards.c
Compiling file: nrf_drv_clock.c
Compiling file: nrf_drv_common.c
Compiling file: nrf_drv_gpiote.c
Compiling file: nrf_drv_uart.c
Compiling file: nrf_nvic.c
Compiling file: nrf_soc.c
Compiling file: bsp.c
Compiling file: bsp_nfc.c
Compiling file: main.c
Compiling file: RTT_Syscalls_GCC.c
Compiling file: SEGGER_RTT.c
Compiling file: SEGGER_RTT_printf.c
Assembling file: gcc_startup_nrf51.S
Compiling file: system_nrf51.c
Linking target: _build/nrf51422_xxac.out

   text	   data	    bss	    dec	    hex	filename
  10228	    108	   4564	  14900	   3a34	_build/nrf51422_xxac.out

Preparing: _build/nrf51422_xxac.hex
Preparing: _build/nrf51422_xxac.bin

The last thing we need to do is make sure we can program the example project onto the development board. Before we do that, make sure that you have:

  • Installed the SEGGER J-Link software
  • Extracted the nRF Command Line tools
  • Added both directories in the Command Line Tools to your PATH environment variable

Now we can make a copy of the blinky example using FreeRTOS (<NRF_ROOT_SDK>/examples/peripheral/blinky_freertos). Copy the entire blinky_freertos folder to a location of your choice. We’ll need to edit one of the first few lines of makefile so that the SDK can be found during the build process. The makefile is located in the project sub-directory blinky_freertos/pca10028/blank/armgcc.

The line we need to edit refer to the build variable SDK_ROOT, which refer to top-level directory of the Nordic SDK.

PROJECT_NAME     := blinky_FreeRTOS_pca10028
TARGETS          := nrf51422_xxac
OUTPUT_DIRECTORY := _build

SDK_ROOT := path/to/nRF5_SDK_12.3.0_d7731ad
PROJ_DIR := ../../..

We can now test if our configuration is correct by attempting to build the project by running ‘make’ in your terminal. You should see the same output as when we built the project from the SDK examples folder.

The last task for today is to make sure we can program our development board with the hex file we just built. The utility nrfjprog is used for this purpose. Before we attempt to flash the board, we must add the directory where nrfjprog is located to our path. While we are there, we will also add the path to the mergehex utility.

In your user .bashrc or .zshrc file (or config file for your favourite shell), add the following;

# Add nRF Command Line tools to PATH
PATH="/path/to/nRF5-Command-Line-Tools_9_8_1/nrfjprog:$PATH"
PATH="/path/to/nRF5-Command-Line-Tools_9_8_1/mergehex:$PATH"
export PATH

Adjust the path above to suit your version of the nRF5 Command Line Tools.

Let’s navigate to the location of our project and flash our board;

> cd /path/to/blinky_freertos/hex
> nrfjprog --program .hex --chiperase --family NRF51

If everything went well, we should now see a blinking LED. Success!

You should also be able to program the board using ‘make’. The makefile provided by Nordic has a ‘flash’ rule which flashes the board.

> cd /path/to/blinky_freertos/pca10028/blank/armgcc
> make flash

Next time, I’ll look at how to implement button debouncing on the nRF51 development board in combination with FreeRTOS. Stay tuned.

Nordic development environment setup
Tagged on:

Leave a Reply

Your email address will not be published.