-
Notifications
You must be signed in to change notification settings - Fork 23
Uploading
You will need to consequently flash 2 files, softdevice and firmware (order does not matter):
-
s130_nrf51_2.0.1_softdevice.hex
from the Nordic site or from nRF5x SDK 12.3.0 -
nrf51822_xxac.hex
, the latest .hex file from the releases section
It's enough to flash softdevice just once (it never changes and adresses do not overlap).
You may use either ST-Link V2 or BluePill with Blackmagic firmware (the latter is more advanced)
Also check out the nRFMicro bootloader article here: https://github.com/joric/nrfmicro/wiki/Bootloader
You can purchase the ST-LINK/V2 programmer for $1.39 on Aliexpress.
You will need the following software:
- OpenOCD - embedded debugger for Windows 10 (openocd-0.10.0-dev-00247-g73b676c.7z)
- Zadig - you will need to install libusb in order to run OpenOCD (zadig-2.3.exe)
To flash nRF modules, connect ST-LINK/V2 to the module programming pins (SWCLK, SWDIO, GND, 3.3V - top to bottom, see Hardware) and run this batch:
@echo off
set path=C:\SDK\openocd-0.10.0-dev-00247-g73b676c\bin-x64;%path%
set file=%~dp0custom\iar\_build\nrf51822_xxac.hex
openocd -f interface/stlink-v2.cfg -f target/nrf51.cfg -c init ^
-c "reset halt" -c "flash write_image erase %file:\=/%" -c reset -c exit
The cheapest Blackmagic programmer is Bluepill, $1.58 STM32 board (STM32F103C8T6). It creates two virtual ports via USB (GDB and UART for debugging) and does not use OpenOCD. You will also need $0.98 UART TTL Module to flash it.
- blackmagic_dfu.bin (blackmagic bootloader)
- blackmagic.bin (stripped down to 57kb as written here, only stm32f1 and nrf5x supported)
-
Blackmagic repository (source code, build with
make PROBE_HOST=stlink
)
Hook an UART adapter first (A9 - RX, A10 - TX). Set Bluepill jumpers to bootloader mode (BOOT0 jumper=1, BOOT1 jumper=0).
WARNING If device is not recognized that's because new Bluepill revisions have wrong R3 resistor (100K instead of 10K), preventing BOOT0 mode. See #13.
You can use either stm32loader with dfu-util or Demonstrator GUI (windows only). After flashing unplug UART adapter, set jumpers back, plug in USB and update USB drivers with libusb from Zadig.
stm32loader.py -p \\.\COM5 -e -w -v ../blackmagic_dfu.bin # considering COM5 is UART
dfu-util -d 1d50:6018,:6017 -s 0x08002000:leave -D blackmagic.bin # flash firmware
- STM32 Flash loader demonstrator (stock STM32 firmware flasher)
Flash blackmagic_dfu.bin at offset 0x08000000 with "Erase all" option then flash blackmagic.bin at 0x08002000 with "Erase necessary pages" option. The blackmagic.bin needs to be stripped down to about 57K for the Bluepill, or you could try force selecting 128K device (doesn't always work).
- arm-none-eabi-gdb (I use one from the gnu-rm toolchain)
To flash nRF module, hook it up to the STM32 board (A5 - SWCLK, B14 - SWDIO, GND - GND, 3.3V - VCC) and run this batch (considering COM5 is the first virtual port):
arm-none-eabi-gdb --quiet --batch -ex "target extended-remote \\.\COM5" ^
-ex "mon swdp_scan" -ex "att 1" –ex "load nrf51822_xxac.hex" –ex kill
Neither nRF51822 nor ST-Link V2 have SWO pin for printf (there is no tracing hardware in the nRF51 series), so you have to use UART. You only need ONE pin to print debug messages.
It's pretty convenient to use Bluepill board with Blackmagic firmware both as a programmer and a debugger. It has built in UART (A2 - RX, A3 - TX - our debug pin) on the second virtual COM port and occupies only one physical USB. The best Windows serial monitor is probably Putty with enabled local echo (for keymap testing).
This firmware implements small drop-in logger that initializes and runs local UART. It redirects printf output to a given TX pin and doesn't need much space (but you will be unable to see system messages).
There are no free broken out pins on Mitosis so you can just use pin 19 (bottom right key) as TX_PIN_NUMBER. Hook up a single UART RX pin at 115200 baud (currently pin 21, key S15 or S23, see Hardware). You will also need common GND and VCC to make it work. It doesn't really interfere much with the keyboard keys so you can use any pin you want, just don't use the same pin for TX and RX to avoid feedback.
In IAR you can try using NRF_LOG_ENABLED
and NRF_LOG_USES_UART
in sdk-config.h
. Note that built in debugging has its own pin settings in sdk-config.h
(not custom_board.h
). Sadly it does not work with GCC (probably not enough memory on 16K QFAA nRF51 modules).