🛠 Dompter l'USB natif de la Blue Pill : CDC, DFU et la résistance rebelle
A real USB device, not a serial bridge
One of the major advantages of the STM32F103 at this price point: an integrated full-speed USB peripheral on the chip, on PA11 (D−) and PA12 (D+). Unlike an Arduino Uno with its ATmega16U2, here the microcontroller itself speaks USB: CDC (virtual serial port), HID (keyboard/mouse), MIDI, DFU… without additional silicon. Note: USB is device-only (the board cannot host USB drives) and the F103 has no WiFi or Bluetooth.
The famous hardware flaw: the D+ pull-up
To enumerate on a full-speed USB bus, the D+ line must be pulled high via a 1.5 kΩ resistor to 3.3 V. However, stm32-base documents a recurring manufacturing defect: "instead of a 1.5 kΩ, it carries either a 10 kΩ or a 4.7 kΩ" — resulting in random USB enumeration (device recognized then lost, or never detected). The fix: replace the resistor with a 1.5 kΩ one. This same pull-up is critical for the STM32duino bootloader, whose USB reset trick (briefly grounding PA12 to re-enumerate) "relies on PA12 having a pull-up resistor of approximately 1.5 kΩ".
The three-step plan
- Check/replace the D+ pull-up resistor (component near the USB connector; 1.5 kΩ).
- Install the community STM32duino bootloader (derived from maple-bootloader) via SWD or the ROM serial bootloader. It occupies 8 KB of flash (the "boot20" revision; the older maple bootloader reserved 20 KB flash / 3 KB RAM) and exposes DFU and serial upload over USB.
- Upload via DFU:
dfu-util -a 1 -D sketch.bin -s 0x8002000:leave— the 0x8002000 offset corresponds to the 8 KB offset left by the bootloader.
Precautions before opening the USB hood
- Keep a backup re-flashing method (ST-Link on the SWD connector, or serial on USART1): cutting off access by modifying the bootloader is the fastest way to an apparent brick.
- The community bootloader must be compiled with GCC 4.8; with 4.9 or newer, "hardware registers are read incorrectly and the bootloader does not work" — useful if you want to compile it yourself.
- For custom HID/MIDI without a bootloader, look at the USB CDC-ACM examples in libopencm3-examples, which run on Maple/Blue Pill class boards.
Other tutorials for this board
- Découvrir la Blue Pill : que trouve-t-on dans la boîte ?
- Premier programme Arduino sur la Blue Pill (core officiel stm32duino)
- Alimenter et flasher la Blue Pill : BOOT0, port série, ST-Link et DFU
- Série, ADC et chasse aux contrefaçons : diagnostiquer sa Blue Pill
- Passer au niveau supérieur : STM32CubeIDE, HAL et LL sur F103
- Firmware libre sur Blue Pill avec libopencm3 et OpenOCD