Skip to content

Wrapper for the Segger J-Link or STLink/V2 (via OpenOCD) to flash nRF51822 MCUs

Notifications You must be signed in to change notification settings

siderakb/Adafruit_nRF51822_Flasher

 
 

Repository files navigation

Adafruit nRF51822 Flasher

Note SideraKB's revision.

Table of Contents

The flasher utility is a wrapper for various debuggers to flash nRF51822 MCUs with the official Adafruit firmware images. Currently supported debuggers are:

This tool hides the implementation details of the different debuggers, and provides a means to flash Bluefruit LE modules with the specified softdevice, bootloader, and firmware via the SWD pins on the nRF51822 (SWDIO and SWCLK).

This is useful if you need to de-brick a board that failed a DFU update, or some other unfortunate event.

The Adafruit_BluefruitLE_Firmware folder is setup as a git submodule, linked to an external repo. you will need to clone this with --recursive flag

git clone --recursive https://github.com/siderakb/Adafruit_nRF51822_Flasher.git

If the folder is empty, you will need to run the following commands to fill it:

git submodule update --init

If you aren't operating from a git repo, you can fill the Adafruit_BluefruitLE_Firmware folder from the command-line with the following command:

git clone https://github.com/siderakb/Adafruit_BluefruitLE_Firmware.git

Requirements

General Requirements

  • One of the following SWD debuggers connected to the module via the SWD pins:
  • Adalink installed on your system (A Python JLinkExe wrapper used to flash the device)
    • git clone adalink
    • install and setup adalink
  • click Python library:
    • sudo apt-get install python-pip or sudo easy_install pip then
    • sudo pip install click

Jlink Requirements

Download and install jlink driver

STLink/V2 Requirements

Install openOCD following the instruction in Adalink doc

On Linux or Raspberry Pi the following steps are required:

Install libusb:

sudo apt-get install libusb-dev libusb-1.0-0-dev

Configure UDEV permissions:

sudo cp openocd-0.9.0/contrib/99-openocd.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules

Then reboot.

STLink/V2 to Bluefruit LE Pinout

The following pins on the STLink/V2 need to be connected to the Bluefruit LE module:

STLink/V2 Bluefruit LE
RST RST
SWCLK SWCLK
SWDIO SWDIO
GND GND
3.3V VIN

RPi GPIO Requirements

You can also use the RPi's raw GPIO to bit-bang JTAG/SWD signals, turning your RPi into a native debugger. A pre-built alpha version of openOCD binary is included in the openocd-x.x.x/rpi_gpio/openocd folder, since the current stable 0.9.0 does not support RPi GPIO with SWD interface yet. To sum up, you don't need install anything else except the libusb as follows

sudo apt-get install libusb-dev libusb-1.0-0-dev

Since accessing RPi's GPIO requires root access, sudo is required when executing the flash.py script:

RPi 1 wiring

rpi_openocd_swd

RPi 2 wiring

rpi2_swd.png

NOTE: Don't forget to connect GND, remember that there are 4 wires in total.

Usage

Usage: flash.py [OPTIONS]

  Flash Bluefruit module Softdevice + Bootloader + Firmware

Options:
  --jtag TEXT           debugger must be "jlink" or "stlink" or "rpigpio",
                        default is "jlink"
  --softdevice TEXT     Softdevice version e.g "8.0.0"
  --bootloader INTEGER  Bootloader version e.g "1" or "2".
  --board TEXT          must be "blefriend32" or "blespifriend".
  --firmware TEXT       Firmware version e.g "0.6.5".
  --help                Show this message and exit.

--firmware and --board options are mandatory.

To flash the blefriend32 module using an STLink/V2 with SD 8.0.0, bootloader ver 2, firmware 0.6.5:

python flash.py --jtag=stlink --board=blefriend32 --softdevice=8.0.0 --bootloader=2 --firmware=0.6.5

To flash the above module with the same firmware using RPi GPIO

sudo python flash.py --jtag=rpigpio --board=blefriend32 --softdevice=8.0.0 --bootloader=2 --firmware=0.6.5

About

Wrapper for the Segger J-Link or STLink/V2 (via OpenOCD) to flash nRF51822 MCUs

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Tcl 94.4%
  • Python 5.6%