STM32 Blue Pill: prepare USB programming
This guide applies to the STM32F103C8 Blue Pill (64 KiB flash, 20 KiB RAM). Identify the actual chip and board revision before choosing a bootloader.
Choose the connection
| Connection | Bootloader requirement | Current Elementic Android support |
|---|---|---|
| ST-Link connected to SWD | No added bootloader | No ST-Link programmer adapter |
| USB-to-UART adapter connected to PA9/PA10 | Uses ST's already-installed ROM USART bootloader | No STM32 USART programmer adapter |
| The Blue Pill's own USB socket | Install a compatible USB bootloader once | No STM32 HID/DFU programmer adapter |
The USB CDC serial interface exposed by running Elementic firmware is a configuration/logging connection. Its presence does not establish that the board can accept a firmware upload through that connection.
ST's STM32F103C8 ROM bootloader supports USART1, not native USB DFU. Other STM32 models may support USB DFU in ROM: check the exact part in ST AN2606.
Recommended native-USB test candidate
For this Blue Pill, evaluate
Serasidis STM32 HID Bootloader 2.2.2,
using the low/medium-density PC13 binary hid_generic_pc13.bin. Do not select
the high-density variant for an F103C8.
The F1 bootloader occupies 2 KiB. It uses USB HID during programming; the Elementic application uses USB CDC after boot. The upstream project labels the software experimental. This is an evaluation recommendation, not an Elementic-approved Flashing Method. Installing it alone does not enable Android's Program button.
Install once with ST-Link
- Install STM32CubeProgrammer. Download the selected bootloader binary from the upstream release and retain its version and SHA-256 with your board preparation record.
- Connect ST-Link SWDIO to PA13, SWCLK to PA14, and GND to GND. Connect NRST if needed. Use the programmer's documented target-voltage reference and a single suitable board power source.
- Set BOOT0 and BOOT1 to 0 and connect in STM32CubeProgrammer using ST-LINK/SWD. Confirm the detected chip and physical capacity.
- Save the current flash before replacing firmware. For a genuine 64 KiB C8,
read 65536 bytes starting at
0x08000000and save the backup. Export important project settings separately. - Open
hid_generic_pc13.bin, select address0x08000000, enable verification, and program it. This replaces the beginning of the previous application. Avoid a whole-chip erase when settings must survive; first installation still needs a backup. - Verify, reset, and reconnect the board's USB cable. If necessary, set BOOT1 to 1 with BOOT0 still 0 and reset to keep this bootloader in HID mode. Return BOOT1 to 0 for normal application startup.
A successful preparation check identifies the HID bootloader. A COM port is expected only after a valid USB-CDC application starts. See the upstream installation instructions.
Build firmware for that exact bootloader
A firmware image built for ST-Link at 0x08000000 cannot be reused unchanged
behind the HID bootloader. The application vector table and code must start
at 0x08000800 (2 KiB offset).
In a successor PlatformIO Build Configuration, replace upload_protocol = stlink
with the following settings while retaining the Elementic feature flags and
USB CDC flags:
upload_protocol = hid
board_build.flash_offset = 0x800
board_upload.offset_address = 0x08000800
Keep the dependency pinned to robertsauer/Elementic@1.1.3. The STM32 Arduino
core recognizes hid and configures its bootloader integration. Compile with
the selected offset and use a matching HID uploader on the PC for the first
application test. Changing these settings does not install the bootloader.
Reserve both the bootloader at the start and the actual emulated EEPROM/ provisioning pages at the end of flash. The nominal 64 KiB capacity is not all application space. Check the ELF/map and signed memory layout before approving an Elementic Flashing Method. Do not rely only on a successful compile or the uploader's acknowledgement to claim stored settings are preserved.
If you mean USB-to-UART serial instead
No new bootloader needs installing for a genuine STM32F103C8. Use its factory ROM bootloader:
- Use a USB-to-UART adapter with 3.3 V logic. Adapter TX goes to PA10 (RX), adapter RX to PA9 (TX), and GND to GND.
- Set BOOT0 to 1 and BOOT1 to 0, then reset.
- In STM32CubeProgrammer choose UART, select the adapter's COM port and connect.
Program a firmware image linked for the normal flash base
0x08000000and verify it. - Set BOOT0 back to 0 and reset to start the application.
The native USB socket is not a substitute for that UART adapter. UART-ROM and HID builds use different application layouts; select the intended method.
Elementic website and Android status
The website can build a matching configuration once it has been validated and published by an administrator. Existing immutable configurations are not changed by installing a bootloader.
Android 1.4 currently implements AVR, Espressif and RP2 programmer adapters, not STM32 USART, HID, DFU or ST-Link. Until a matching adapter and reviewed, signed Flashing Method exist, upload from the PC and use Android USB CDC for Elementic configuration. Future approval must cover chip identity, boot entry, application offset, protected storage, interrupted transfers, verification and post-flash reconnect.
Do not infer bootloader installation from a saved project setting or a USB serial VID/PID. Only the programmer's bootloader probe can confirm it.
Recovery
Keep ST-Link available during evaluation. To return to the previous setup,
use SWD to restore the saved image at 0x08000000, or program a fresh ST-Link
build linked at that address, then reset with BOOT0 and BOOT1 at 0. A new
application at flash base replaces the added USB bootloader. Restore exported
settings if they were erased.
Build behavior reference
STM32 Arduino PlatformIO integration
defines the F1 HID offset as 0x800; the older STM32duino DFU v2 bootloader
uses 0x2000. Those bootloaders and firmware images are not interchangeable.