Skip to content
DFU Bootloader for STM32 chips
C Makefile Shell
Branch: master
Clone or download
devanlai Merge pull request #7 from karel-3d/patch-1
Using WINUSB_MS_VENDOR_CODE in extra string
Latest commit 9bb26fa Aug 19, 2019


The dapboot project is an open-source USB Device Firmware Upgrade (DFU) bootloader for STM32 devices.

Currently, the only targets officially supported are the STM32F103x series.

Build instructions

The default target is a generic STM32F103 dev board with an LED on PC13, commonly referred to as a "bluepill" board.

To build other targets, you can override the TARGET variable when invoking make.

make clean


Target Name Description Link
BLUEPILL Cheap dev board
MAPLEMINI LeafLabs Maple Mini board and clone derivatives
STLINK STLink/v2 hardware clones

Flash instructions

The make flash target will use openocd to upload the bootloader to an attached board. By default, the Makefile assumes you're using a CMSIS-DAP based probe, but you can override this by overriding OOCD_INTERFACE variable. For example:

make OOCD_INTERFACE=interface/stlink-v2.cfg flash

Overriding defaults

Local makefile settings can be set by creating a, which is automatically included.

Here is an example that changes the default target to the STLink/v2 and uses an unmodified STLink/v2 to flash it.

OOCD_INTERFACE ?= interface/stlink-v2.cfg

You can also use the env variable DEFS to override default configuration for a target, like:

# Disable LED on BluePill

# Allow access to all Flash on MapleMini and change the app base address
DEFS="-DFLASH_SIZE_OVERRIDE=0x20000 -DAPP_BASE_ADDRESS=0x08004000" make TARGET=MAPLEMINI LDSCRIPT="/some/folder/stm32f103x8-16kb-boot.ld"

Using the bootloader

Building for the bootloader

The bootloader occupies the lower 8KiB of flash, so your application must offset its flash contents by 8KiB. This can be done by modifying your linker script or flags as appropriate.

See the highboot branch for an experimental variation that doesn't require the application to be offset.

Switching to the bootloader

The bootloader can be built to look for arbitrary patterns, but the default for the STM32F103 target looks for a magic value stored in the RTC backup registers. Writing the magic value and then resetting will run the bootloader instead of the main application.

The bootloader currently looks for 0x544F in RTC backup register 1 and 0x4F42 in RTC backup register 0 (together they spell "BOOT" in ASCII).

You can also use a button to stay in bootloader while booting. It's configured using HAVE_BUTTON define. If your button has a debounce capacitor, you can use BUTTON_SAMPLE_DELAY_CYCLES define to specify how many cycles to wait before sampling the I/O pin, by default it is approximately 20ms in a 72Mhz MCU.


This bootloader implements the draft WebUSB specification, which allows web pages to access the bootloader (after presenting the user with a device picker dialog).

For a demo implementing dfu-util features in the browser, see


The USB VID/PID pair (1209/DB42) is allocated through the open-source USB PID program.


All contents of the dapboot project are licensed under terms that are compatible with the terms of the GNU Lesser General Public License version 3.

Non-libopencm3 related portions of the dapboot project are licensed under the less restrictive ISC license, except where otherwise specified in the headers of specific files.

See the LICENSE file for full details.

You can’t perform that action at this time.