A simple example to get going with a Nordic Microcontroller. This example blinks an LED attached to GPIO 11. Download the example Blinky.zip. which contains a readme describing each file in the package.

Hooking up the circuit

We are using a 120 Ohm resistor for R1 but you can use a larger value resistor (up to a point) it will just mean the LED might appear a little dimmer.


main.cpp – main source file

//	Required includes.
//	Defining BOARD_CUSTOM will cause boards.h to include custom_board.h 
//	which contains the hardware definitions for the board this program
//      is intended for. In particular, custom_board.h contains the
//      definition for LED_A i.e which is set to GPIO 11
#include <stdlib.h>
#include "nrf_delay.h"
#include "boards.h"

int main()
	//	Initialise the board.
	//	LED_A is defined as GPIO 11 in custom_board.h

	//	Loop forever toggling the led ON/OFF every 500 ms
	bool setOn = true;
    	while (true)
		setOn = setOn ? false : true;

custom_board.h – When developing with the Nordic SDK, the convention is to include a header file that describes which pins are used and for what function. The SDK includes some headers for pre-defined boards however it is most likely that a custom definition will be required. If so, add a file called custom_board.h to the project and compile the whole project with the #define BOARD_CUSTOM (-DBOARD_CUSTOM) and the header file will automatically be included by the SDK header boards.h. Here is the contents of custom_board.h for this project


#include "nrf52832_peripherals.h"
#include "nrf_assert.h"

//  The custom board has 1 LED
#define LEDS_NUMBER    1

//  Custom board LEDS are active high i.e. a 1 is required
//  on the GPIO to illuminate the LED
#define LED_A       11
#define BSP_LED_0   LED_A
#define LEDS_LIST { LED_A }


Building and Flashing the Program

Any toolchain/programmer can be used for these steps. All the examples here are built using make and gcc. The binary is flashed using the Raspberry Pi networked programmer. See here for how to set up make, gcc and the Raspberry Pi networked programmer.


From the terminal type:

C:\Projects\Blinky> "c:\Program Files (x86)\GnuWin32\bin\make.exe" -f makefile CONFIG=Debug all

If there are no errors then the binary blinky.elf should be output to the sub-folder bin\debug

Flashing the Binary to the Microcontroller

Hooking up the Programmer to the Microcontroller

See here for how to connect the programmer to the microcontroller.


From a terminal type:

C:\Projects\Blinky> "C:\Program Files\NoSMD\SWorD\bin\SWorDProgrammer.exe" -program:bin\debug\blinky.elf -probe:rpi4programmer -pagesize:4096

Attempting to connect to rpi4programmer on

Connected to rpi4programmer on

Progress 100%
Completed with success


If all is well you should now see the LED blinking.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: