Home / Learn Chip Programming / STM32 System Bootloader, DFU and Option Bytes
STM32 System Bootloader, DFU and Option Bytes
Flash a chip with no debugger and protect it with option bytes.
In shortFlash a chip with no debugger and protect it with option bytes.
Theory in plain words
What it is
Every STM32 has a ROM bootloader. BOOT0 high at reset starts it. It speaks UART, I2C, SPI, CAN or USB DFU. Option bytes set read protection (RDP) and write protection.
Why we use it
Production flashing, bricked board recovery and protecting firmware all use these.
How it works
Set BOOT0 = 1, reset, flash with STM32CubeProgrammer over USB DFU or UART, set BOOT0 = 0, reset. RDP level 1 blocks reading flash; level 2 is permanent.
Where it is used
- Blue Pill without ST-LINK
- Factory programming
- Firmware protection
Read protection levels
What does each RDP level do?Try it Yourself
Use level 1 in production. Level 2 is irreversible: only use it on finished products.
STM32_Programmer_CLI -c port=USB1 -w firmware.bin 0x08000000 -v -rst # DFU over USB
STM32_Programmer_CLI -c port=COM3 br=115200 -w firmware.bin 0x08000000 # UART bootloader
dfu-util -a 0 -s 0x08000000:leave -D firmware.bin # open source alternativeCareful:Clone Blue Pill boards may have a wrong flash size or fake chip. If STM32CubeProgrammer cannot connect, check BOOT0, power and the USB cable (many are charge-only).
Quick quiz
1. How do you enter the ROM bootloader?
BOOT0 = 1 selects system memory.
2. RDP level 2 is...
It cannot be undone.