Nordic NRF51 and FruityMesh BLE Up and Running


 

Update:

There’s now also an Ansible script that runs locally if you want to use your Mac natively. Use this repo.

Enjoy!

 

Some learnings and new implementations have happened since the last post about the Nordic NRF51:

– I wrote an Ansible script to automate the provisioning and deployment of a complete development environment for NRF51 using the FruityMesh framework. Please note that the environment is hosted on a headless Ubuntu, so you need some command-line fu.
The repo supports VirtualBox and Parallels running Ubuntu using Vagrant. I hope you find it be a useful way to quickly enable you to develop modules for BLE mesh experimentation or simply develop for the NRF51.

– I cloned the original and created this repo to exercise its mesh programming, specifically:
* Timer functions
* RSSI values
* GPIO programming

The implementation demonstrates an RGB LED that changes colours when its paired NRFs change their relative signal strengths as their distance from it changes.

I hope you find these two artefacts useful, and as always, your comments are welcomed.

Some useful links:
M-Way Labs FruityMesh implementation
– Helpers for development
Mac OS/X setup (without FruityMesh support)

Happy hacking!

Advertisements

Nordic NRF51 up and running


Update:

If you want to know the insides of how to set up a development environment, read on!

If you want Ansible to do all the work for you, skip this post and check out my repos:
* For an Ubuntu VM, use this repo
* For using your Mac natively, use this repo.

Enjoy!

Introduction

There is not much documentation about the NRF51, and the tool-collection hunting and gathering process can be intimidating.
I hope this blog entry will help those that want to use and program the Nordic NRF51 development board to test out BLE functionality.

The hardware

We are using the NRF51 development board, which was purchased from here.

Basic operations

Connecting to the board

Connection is done via conneting a standard Micro USB Cable to your host computer. Once power is supplied to board, it will run the current program automatically.

Communicating with the board

Flashing the device can be done using the JLinkExe program runing on the host computer. JLinkExe can be downloaded from here.

Resetting the board to manufacturer settings

From a terminal window, as the device is connected and turned on, run the following command line:

prompt> JLinkExe -device nrf51822

When the JLink prompt appears, type the following:

J-Link> w4 4001e504 2 
J-Link> w4 4001e50c 1 
J-Link> r 
J-Link> g 
J-Link> exit 

This will erase all the programs that were loaded.

Programming the device

In order to program the device, you must first set up the following tools:

The Nordic SDK

The SDK can be downloaded from the Nordic website here. For our testing, we used nRF51_SDK_v9.0.0. The SDK contains a binary referred to as “SoftDevice” that supports BLE management of the chip. Please see below on how to load the SoftDevice to the board using JLink.

Compiler and Linker toolchain from GNU

The cross-compiler/linker tools that are needed to build executables for the board can be found here. We placed them under ‘/usr/local’. If you have multiple development environments, it may be easier to set an alias to run the right tools rather than modifying the path. For example:

alias gdb51="/usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/arm-none-eabi-gdb"
alias jdb51="jlinkgdbserver -device nrf51822 -if swd -speed 4000 -noir -port 2331”

Loading a binary to the device

An executable image is created in the form of “.HEX” files that has to be loaded to the board’s flash memory. To load it to the device, open a terminal window and run JLinkExe, this time using the loadfile command:

prompt> JLinkExe -device nrf51822 
J-Link> loadfile path-to-binary
J-Link> r  
J-Link> g  
J-Link> exit 

When you program BLE functionality, you will need to load the chip’s firmware in order to support your programs. This is packaged as an executable and is part of the SDK. In order to load the SoftDevice, simply use the loadfile command with the correct path, such as:

J-Link> loadfile SDK_ROOT/components/softdevice/s110/hex/s110_softdevice.hex 
J-Link> r
J-Link> g
J-Link> exit

Select a different path if you want to change the version loaded (in this example, it’s S110).

Checkpoint

At this stage, you should have a connected board that has a version of the firmware loaded, and the toolchain downloaded, ready for development to begin!

BLE is hard, but blinking the board is easy

Using the toolchain let’s compile and load the demo blink program that comes with the SDK to make sure we have everything in place for future development.

Making Make make

Here you’ll edit the file named Makefile.posix to point to the correct toolchain for cross-development. The file is found at SDK_ROOT/components/toolchain/gcc/Makefile.posix, where SDK_ROOT being the location you installed the Nordik SDK files.
Edit this file so it contains the path to where you installed the cross-compiler:

GNU_INSTALL_ROOT := /usr/local/gcc-arm-none-eabi-4_9-2015q2
GNU_VERSION := 4.9.3
GNU_PREFIX := arm-none-eabi

Building the blink example

Navigate to the “blink” example directory

cd SDK_ROOT/examples/peripheral/blinky

Depending on your board (the one we used was PCA10028), you might need to create a subdirectory within “blinky” by copying the one present, if your model number does not appear there:

cp -r pcaXXXXX pca10028

Edit the Makefile in the PCA10028/armgcc directory to reference DBOARD_PCA10028, if it’s not already referenced there.

The path to the makefile is: SDK_ROOT/examples/peripheral/blinky/pca10028/s110/armgcc/Makefile.

Once you have saved the modification, return to the terminal window and invoke make to build the image:

prompt> make

in the directory where the makefile is located.

Even though the LED program does not need BLE functionality, let’s load the S110 firmware prior to loading our image for illustrative purposes:

prompt> JLinkExe -device nrf51822
JLink> loadfile SDK_ROOT/components/softdevice/s110/hex/s110_softdevice.hex

And now we’ll load our blink example

JLink> loadfile _build/nrf51422_xxac.hex
JLink> r 
JLink> g

You should now see the board’s four LEDs should blink at a nice rhythm.

Debugging

Download the jlinkgdbserver debugger from here. When run, it will connect to the board via the serial cable, and wait for commands coming from the GNU debugger, which was included in the GCC download described previously.

To build with debug symbols, invoke make with the debug goal:

prompt> make clean
prompy> make debug

Run the debugger server in a terminal window or tab:

prompt> jlinkgdbserver -device nrf51822 -if swd -speed 4000 -noir -port 2331

Open another terminal window and run your image from the armgcc subdirectory so that JLinkExe will be able to load the debug symbols created when building the application:

prompt> gdb51 program-name.out
(gdb) target remote localhost:2331
(gdb) gdb-command-here

This runs the debugger, loading debug symbols which will relay instructions to the JLink server that in turn will relay those to the board.

Summary

We made sure that the hardware and the development environment was set up correctly for future application development. In order to take advantage of the hardware’s capabilities, please refer to the documention of the board and firmware here, which contains essential links to the BLE functionality as well as a demo mesh project.

Acknowledgements

I’d like to thank Tim Kadom, my friend and colleague at ThoughtWorks, who sparked my interest by introducing me to BLE and mesh applications and was instrumental in helping me set up the environment and getting everything to work.

Nordic NRF51 up and running


Update:

If you want to know the insides of how to set up a development environment, read on!

If you want Ansible to do all the work for you, skip this post and check out my repos:
* For an Ubuntu VM, use this repo
* For using your Mac natively, use this repo.

Enjoy!

Introduction

There is not much documentation about the NRF51, and the tool-collection hunting and gathering process can be intimidating.
I hope this blog entry will help those that want to use and program the Nordic NRF51 development board to test out BLE functionality.

The hardware

We are using the NRF51 development board, which was purchased from here.

Basic operations

Connecting to the board

Connection is done via conneting a standard Micro USB Cable to your host computer. Once power is supplied to board, it will run the current program automatically.

Communicating with the board

Flashing the device can be done using the JLinkExe program runing on the host computer. JLinkExe can be downloaded from here.

Resetting the board to manufacturer settings

From a terminal window, as the device is connected and turned on, run the following command line:

prompt> JLinkExe -device nrf51822

When the JLink prompt appears, type the following:

J-Link> w4 4001e504 2 
J-Link> w4 4001e50c 1 
J-Link> r 
J-Link> g 
J-Link> exit 

This will erase all the programs that were loaded.

Programming the device

In order to program the device, you must first set up the following tools:

The Nordic SDK

The SDK can be downloaded from the Nordic website here. For our testing, we used nRF51_SDK_v9.0.0. The SDK contains a binary referred to as “SoftDevice” that supports BLE management of the chip. Please see below on how to load the SoftDevice to the board using JLink.

Compiler and Linker toolchain from GNU

The cross-compiler/linker tools that are needed to build executables for the board can be found here. We placed them under ‘/usr/local’. If you have multiple development environments, it may be easier to set an alias to run the right tools rather than modifying the path. For example:

alias gdb51="/usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/arm-none-eabi-gdb"
alias jdb51="jlinkgdbserver -device nrf51822 -if swd -speed 4000 -noir -port 2331”

Loading a binary to the device

An executable image is created in the form of “.HEX” files that has to be loaded to the board’s flash memory. To load it to the device, open a terminal window and run JLinkExe, this time using the loadfile command:

prompt> JLinkExe -device nrf51822 
J-Link> loadfile path-to-binary
J-Link> r  
J-Link> g  
J-Link> exit 

When you program BLE functionality, you will need to load the chip’s firmware in order to support your programs. This is packaged as an executable and is part of the SDK. In order to load the SoftDevice, simply use the loadfile command with the correct path, such as:

J-Link> loadfile SDK_ROOT/components/softdevice/s110/hex/s110_softdevice.hex 
J-Link> r
J-Link> g
J-Link> exit

Select a different path if you want to change the version loaded (in this example, it’s S110).

Checkpoint

At this stage, you should have a connected board that has a version of the firmware loaded, and the toolchain downloaded, ready for development to begin!

BLE is hard, but blinking the board is easy

Using the toolchain let’s compile and load the demo blink program that comes with the SDK to make sure we have everything in place for future development.

Making Make make

Here you’ll edit the file named Makefile.posix to point to the correct toolchain for cross-development. The file is found at SDK_ROOT/components/toolchain/gcc/Makefile.posix, where SDK_ROOT being the location you installed the Nordik SDK files.
Edit this file so it contains the path to where you installed the cross-compiler:

GNU_INSTALL_ROOT := /usr/local/gcc-arm-none-eabi-4_9-2015q2
GNU_VERSION := 4.9.3
GNU_PREFIX := arm-none-eabi

Building the blink example

Navigate to the “blink” example directory

cd SDK_ROOT/examples/peripheral/blinky

Depending on your board (the one we used was PCA10028), you might need to create a subdirectory within “blinky” by copying the one present, if your model number does not appear there:

cp -r pcaXXXXX pca10028

Edit the Makefile in the PCA10028/armgcc directory to reference DBOARD_PCA10028, if it’s not already referenced there.

The path to the makefile is: SDK_ROOT/examples/peripheral/blinky/pca10028/s110/armgcc/Makefile.

Once you have saved the modification, return to the terminal window and invoke make to build the image:

prompt> make

in the directory where the makefile is located.

Even though the LED program does not need BLE functionality, let’s load the S110 firmware prior to loading our image for illustrative purposes:

prompt> JLinkExe -device nrf51822
JLink> loadfile SDK_ROOT/components/softdevice/s110/hex/s110_softdevice.hex

And now we’ll load our blink example

JLink> loadfile _build/nrf51422_xxac.hex
JLink> r 
JLink> g

You should now see the board’s four LEDs should blink at a nice rhythm.

Debugging

Download the jlinkgdbserver debugger from here. When run, it will connect to the board via the serial cable, and wait for commands coming from the GNU debugger, which was included in the GCC download described previously.

To build with debug symbols, invoke make with the debug goal:

prompt> make clean
prompy> make debug

Run the debugger server in a terminal window or tab:

prompt> jlinkgdbserver -device nrf51822 -if swd -speed 4000 -noir -port 2331

Open another terminal window and run your image from the armgcc subdirectory so that JLinkExe will be able to load the debug symbols created when building the application:

prompt> gdb51

This runs the debugger, loading debug symbols which will relay instructions to the JLink server that in turn will relay those to the board.

Summary

We made sure that the hardware and the development environment was set up correctly for future application development. In order to take advantage of the hardware’s capabilities, please refer to the documention of the board and firmware here, which contains essential links to the BLE functionality as well as a demo mesh project.

Acknowledgements

I’d like to thank Tim Kadom, my friend and colleague at ThoughtWorks, who sparked my interest by introducing me to BLE and mesh applications and was instrumental in helping me set up the environment and getting everything to work.