riteshtheone/stm32f411ceu6_dfu_bootloader_application
USB DFU bootloader and sample application for STM32F411CEU6 (e.g. Black Pill board) with runtime DFU entry and separate memory mapping.
STM32F411CEU6 (Black Pill) DFU Bootloader + Application
This project demonstrates a USB DFU (Device Firmware Upgrade) bootloader with a sample user application for the STM32F411CEU6 microcontroller, such as the Black Pill board.
It allows firmware upgrades over USB without needing ST-Link or toggling BOOT0 โ perfect for production or remote updates.
๐งญ How to Enter DFU Bootloader Mode
โ Method (No BOOT0 Needed)
To trigger DFU mode on boot:
- Step 1: Press and hold the Boot Button (connected to PA0) available on the board.
- Step 2: Power on the board or press the reset button (while still holding the Boot Button).
- Step 3: After ~0.5 seconds, release the Boot Button.
๐ The LED on PC13 will blink rapidly (100ms interval) to indicate DFU mode is active.
โ If no valid application is found, the LED on PC13 will double-blink every 1.5 seconds to indicate the application is not found.
๐ Connection Methods
-
USB DFU Mode:
Connect a USB data cable to the board's USB Micro or Type-C port. -
No UART/Serial Needed:
This bootloader does not require BOOT0 or UART (PA9/PA10) usage.
๐ Application Details (Important)
The user application is flashed to 0x08008000 onward.
๐ฆ Linker Script (application.ld) โ โ ๏ธ Do Not Ignore This
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
FLASH (rx) : ORIGIN = 0x08008000, LENGTH = 480K
}
โ ๏ธ Important: This ensures the application does not overwrite the bootloader and has access to the full RAM.
๐พ Flashing Firmware
Use one of the following tools that support USB DFU:
- โ STM32CubeProgrammer
- โ
dfu-util(Linux/macOS/WSL)
Flash your firmware binary (.bin or .hex) starting at address:
0x08008000
โ Below is the Bootloader Internal Details (Can Be Ignored)
๐ง Bootloader Details
The bootloader is flashed to the first 32KB of flash (0x08000000โ0x08007FFF).
๐ฆ Linker Script (bootloader.ld)
MEMORY
{
BOOTFLAG (xrw) : ORIGIN = 0x20000000 , LENGTH = 0x8 /* 8 bytes for boot_flag */
RAM (xrw) : ORIGIN = 0x20000008 , LENGTH = 128K - 0x8
FLASH (rx) : ORIGIN = 0x08000000 , LENGTH = 32K
}๐ Project Structure
stm32f411ceu6_dfu_bootloader_applicationer/
โโโ stm32_bootloader # USB DFU Bootloader (starts at 0x08000000)
โโโ stm32_application # User application (starts at 0x08008000)
Each project includes STM32CubeMX .ioc, Makefile, USB stack, HAL drivers, and build folders.
๐ ๏ธ Build & Flash
You can build, flash via DFU, and open a serial monitor using the included helper Makefile in each folder.
๐งฐ Example Helper Makefile
# Build target (requires sub-make in ./Debug)
make all
# Flash using dfu-util (must have sudo or permissions)
make flash
# Open serial monitor (uses miniterm from pyserial)
make serial
# Clean build
make cleanUpdate this line in the Makefile to match your serial device:
SERIAL := /dev/ttyUSB0๐ก Tip: Make sure
dfu-utilandpyserialare installed:
sudo apt install dfu-util
pip install pyserialโ How It Works
๐ 1. Power-Up / Reset
- Bootloader checks a boot flag in RAM to decide whether to enter DFU or jump to the application.
๐ป 2. DFU Mode (Firmware Update)
- If a DFU request is detected (via PA0 or host), bootloader enters USB DFU mode.
- While in DFU mode, LED (PC13) blinks at 100ms interval.
๐ 3. Application Launch
- If no DFU request is detected and a valid application is found at
0x08008000, it jumps to the app. - If the application is not valid, LED (PC13) shows a double-blink every 1.5 seconds.
๐ ๏ธ You can customize this logic in
main.cโ GPIO, UART, button triggers, etc.
๐ฆ Requirements
- STM32F411CEU6 (e.g., Black Pill board)
- USB cable
- ST-Link (for initial bootloader flash only)
dfu-util- Python 3 +
pyserial
๐ License
This project is licensed under the MIT License. You're free to use, modify, and distribute.
๐ฌ Need Help?
Open issues or discussions on the GitHub repository:
๐ https://github.com/riteshtheone/stm32f411ceu6_dfu_bootloader_application