Installing Firmware - devanlai/DAPLink GitHub Wiki
ST Nucleo boards
ST Nucleo boards are the current preferred development platform for DAPLink with WebUSB because they are cheap and highly available. Currently, the only Nucleo board with a pre-compiled flash algorithm is the Nucleo F103RB board.
There are two different DAPLink targets that support ST Nucleo boards:
stm32f103xb_nucleo_f103rb_if
This target is meant to be used with the standard DAPLink mass-storage bootloader (stm32f103xb_nucleo_bl
). It can either be flashed directly with the bootloader in a single step, or it can be loaded via drag'n'drop once the bootloader has been flashed.
Note: Flashing this target requires erasing the existing STLink/V2-1 firmware. If later you want to restore the original STLink/V2-1 firmware, you will need to make a backup copy of the bootloader before flashing the board.
If you're looking to actively develop DAPLink WebUSB firmware and/or you don't mind losing the original STLink/V2-1 firmware, use this target.
Flashing with openocd
Wiring up SWD
The unpopulated SMD jumpers SB6, SB10, and SB11 on the underside of the board provide access to the STLink/V2-1's SWCLK, SWDIO, and nRESET pins respectively.
Clearing read protection
The STLink/V2-1 bootloader enables read protection, which automatically protects the first 8 KiB of flash from being reflashed. To reflash the chip, we need to first clear the read protection
openocd -f interface/cmsis-dap.cfg -f target/stm32f1x.cfg \
-c "init" -c "reset init" \
-c "stm32f1x unlock 0; reset init" \
-c "reset" -c "shutdown"
Flashing the bootloader
stm32f103xb_nucleo_bl.bin
is a USB mass-storage bootloader that can be used to update the main DAPLink firmware.
openocd -f interface/cmsis-dap.cfg -f target/stm32f1x.cfg \
-c "init" -c "reset init" \
-c "program stm32f103xb_nucleo_bl.bin 0x08000000" \
-c "reset" -c "shutdown"
After flashing the bootloader, it should enumerate and appear as a USB volume named "MAINTENANCE".
Uploading the main firmware
stm32f103xb_nucleo_f103rb_if_crc.bin
is the main firmware with a CRC appended.
After flashing the bootloader, the main firmware can be uploaded by dragging and dropping it onto the "MAINTENANCE" drive.
It should reset and enumerate as a "DAPLINK" drive.
To update the firmware in the future, hold down the target's reset button while plugging in the USB cable to re-activate the mass-storage bootloader.
stm32f103xb_native_nucleo_f103rb_if
This target uses the STLink/V2-1's protected bootloader that normally handles official firmware updates. It can be uploaded by modifying the official STLink updater to deliver our firmware instead. This keeps the bootloader intact and allows for later using the STLink updater to re-install the official STLink/V2-1 firmware.
If you're looking to try out the DAPLink WebUSB firmware, but don't plan to do active firmware development, choose this target.
Encrypting the firmware
The STLink updater stores the firmware encrypted with an AES-128 key. As described in this article, the encrypted firmware is stored inside of STLinkUpgrade.jar
under com/st/stlinkupgrade/core
. For the STLink/V2-1 on the Nucleo board, we will replace f2_4.bin
with our own encrypted firmware.
Note: releases on GitHub include pre-encrypted copies of f2_4.bin
, so you can skip this step if you're not building from scratch.
lujji's st-decrypt utility is available on GitHub:
git clone https://github.com/lujji/st-decrypt.git
Using st-decrypt
, we can encrypt our firmware so that the STLink/V2-1 will accept it. stm32f103xb_native_nucleo_f103rb_if.bin
is the unencrypted DAPLink firmware to use with the STLink/V2-1's bootloader.
java -jar st-decrypt/dist/st_decrypt.jar -k "best performance" \
-i stm32f103xb_native_nucleo_f103rb_if.bin \
-o f2_4.bin --encrypt
Modifying STLinkUpgrade.jar
We can then replace the firmware in the jar file. The jar
cannot update files located under subdirectories, so we must manually create the appropriate directory structure:
mkdir -p com/st/stlinkupgrade/core/
cp f2_4.bin com/st/stlinkupgrade/core/
jar -uf STLinkUpgrade.jar com/st/stlinkupgrade/core/f2_4.bin
If you don't have the JDK installed, you can also just open the jar file with an archive manager and replace f2_4.bin
Uploading the encrypted firmware
Run the modified jar file with with java -jar STLinkUpgrade.jar
.
After the upgrade completes, it will stall after it finishes flashing, erroring out with "ST-Link device lost when exiting upgrade mode."
This is normal, since the updater expects the debugger to reset as an STLink device, but it shows up as a CMSIS-DAP device instead. The DAPLink firmware will enumerate as a "DAPLink" volume instead of "MBED".
To restore the STLink/V2-1 firmware, hold down the reset button while plugging in the USB cable and run an unmodified copy of STLinkUpgrade.