STM32F401CCU6 Blackpill DFU recovery
If you should happen to "brick" your blackpill dev board in such a way that it doesn't respond to your STLINK v2 debugger anymore, you can recover it by flashing a known-good program via USB Device Firmware Update (DFU) mode.
Every stm32f4 has a built-in DFU bootloader in ROM. To boot into DFU mode, connect the board to your computer via USB (directly, do not use an st-link debugger) hold down the BOOT0 button, and then briefly press the NRST button.
Once in DFU mode, we can flash a known-good program onto it to reset it to a usable-state. I used https://github.com/a5021/STM32F401CCU6-Blink-Bare-Metal/ (`cd ide; make`).
Before we can flash that program, we need to convert the ELF executable into a stm32 proprietary DfuSe format. To do that, I used:
https://github.com/majbthrd/elf2dfuse
cd elf2dfuse
make
./elf2dfuse ../STM32F401CCU6-Blink-Bare-Metal/ide/build/STM32F401CCU6-Blink-Bare-Metal.elf ./out.hex
Now that we have out.hex a DfuSe format binary known-good program for our microcontroller, we just need to flash it over to the board. To flash it, I used dfu-util (`brew install dfu-util`):
dfu-util -a "@Internal Flash /0x08000000/04*016Kg,01*064Kg,01*128Kg" -D ./out.hex
To figure out the exact "@Internal Flash" string to use for that command, run `dfu-util --list` to list the possible dfu targets. They vary slightly between boards (one board I have ended in 03*128Kg, the other 01*128Kg).
That's it. Tap the NRST button to reboot out of DFU mode, and you should see a quick repeating pattern of blinks as the Blink-Bare-Metal program runs.















