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:
- Segger J-Link (via Adalink)
- STLink/V2 (via Adalink)
- Raspberry Pi GPIO (via an alpha version of OpenOCD, included in this repo)
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
- One of the following SWD debuggers connected to the module via the SWD pins:
- Segger J-Link
- STLink/V2
- Raspberry Pi (1 & 2) GPIO
- 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
orsudo easy_install pip
thensudo pip install click
Download and install jlink driver
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 |
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 2 wiring
NOTE: Don't forget to connect GND, remember that there are 4 wires in total.
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