🛠 Dompter l'USB natif de la Blue Pill : CDC, DFU et la résistance rebelle

STM32F103 "Blue Pill" (STM32F103C8T6) · intermediaire · Le F103 possède un vrai périphérique USB full-speed sur PA11/PA12. Comment l'exploiter, et pourquoi l'énumération échoue sur beaucoup de cartes.

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

  1. Check/replace the D+ pull-up resistor (component near the USB connector; 1.5 kΩ).
  2. 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.
  3. 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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials