Some time ago we bought BLE400 from Waveshare as probably one of the cheapest option to enter nRF51822 market. As our readers know, we prefer to use the Linux environment for embedded systems development. Because of that, we’re following the guide for using Waveshare nRF51822 Eval Kit: icarus-sensors. Kudos due to great post that helped us enter nRF51822 and mbed OS land under Linux.

BLE400 is pretty cheap, because it hasn’t got integrated debugger/programmer. Key is to realize, that you can use BLE400 eval kit and STM32 development board ie. Discovery or any Nucleo (only for its stlink integrated debugger/programmer), which are also cheap. Of course other boards or standalone ST-Link could be used.

Hardware connections

On the Nucleo board both jumpers from CN2 connector should be removed. Thanks to this ST-LINK could be used in stand-alone mode.

Connection should be made this way:

nrf51822_stlink

Both boards should be connected to host’s USB ports. USB port on BLE400 is used for power supply and debug UART connection (cp210x converter should be detected and ttyUSBx exposed).

OpenOCD basic test

No stlink tools are needed. Only OpenOCD.

OpenOCD version we’re using:

Enable user access to Debugger

First we need to check, that our debugger is detected. There should be line like this:

Note the ID's: 0483:3748. Create rule in /etc/udev/rules.d (as root):

Reload udev rules (as root):

Reconnect the st-link. After that, debugger should be accessible by user.

Test the OpenOCD connection

Run this command to connect the debugger to the target system (attaching example output). cfg files location depend on your setup, if you compiled OpenOCD from source those files should be in /usr/local/share/openocd/scripts:

If you see error like this:

This means you may have STLink v2.1, so your command should look like this:

After that OpenOCD is waiting for incoming telnet connections on port 4444. This sample connection, to check everything is ok:

Testing the example program

First we need proper SDK for out device. ICs that we tested were revision 2 and 3 (QFAA and QFAC code, see the print on the NRF chip). You can check the revision table and compatibility matrix to determine SDK version. We used SDK v.12.1.0 for the rev3 chip.

After downloading and uncompressing the SDK. We can find the blinky example in examples/peripheral/blinky/hex/blinky_pca10028.hex. Now we can try to program it:

During that procedure you may face this problem:

To solve that please issue nrf51 mass_erase and retry program command. This have to be done only once.

After that, LED3 and LED4 should start blinking on the target board.

Sample script for flashing

I’ve created this script to simplify the flashing operation:

Note: openocd does not accept filenames containing space in path.

Summary

As you can see, it’s possible to work with nRF51822 under Linux using only OpenOCD. Whole workflow can be scripted to match your needs. With this knowledge, we can start to deploy mbed OS and Zephyr, which both have great support for Linux through command line interface.