Burning the bootloader
This page contains tutorials about how to flash the STM32duino bootloader to F103 boards. For details of the bootloader itself, see here.
Most STM32F103 boards do not come with a USB bootloader installed. The main exception is the Maple mini. The STM32F4 series MCU has a built in DFU and Serial bootloader, so there is no need to install a bootloader
On the STM32F103 there are 2 ways to flash the bootloader onto the board
- Using the Serial bootloader which is built into the STM32F103, by connecting to USART1
- Using a SWD programmer tool like the ST-Link
Currently it is not possible to burn the bootloader from within the Arduino IDE.
It is possible to flash the bootloader using any of the following hardware:
- A USB to TTL serial adapter
- A CH340G or FT232RL board can be bought for less than a dollar
- An Arduino Nano or Uno can act as a USB to serial adapter
- The adapter would preferably be 3.3 volt, but some STM chips have 5V tolerant USART pins.
- A JTAG adapter
- Black Magic Probe
- Most STM32 boards can be reprogrammed as a BMP
If you don't own any of the above hardware, it might be easier to start out with a Maple Mini, which comes with a USB bootloader pre-installed.
See below and/or Uploading a sketch for more on the serial and ST-Link upload methods.
Flashing the bootloader onto the Black Pill via USB to Serial converter using UART1
The Black Pill does not come with any USB bootloader. This process should be roughly the same for all F103 boards.
- Download the correct bootloader binary, in this case generic_boot20_pb12.bin 
- Set the 'boot 0' pin/jumper high, and 'boot 1' low
- B0+ to center pin
- B1- to center pin
- Connect the board to the PC using a USB to serial converter
- RX to PA9
- TX to PA10
- GND to G on the ST-Link connector
- 3.3V to V3 on the ST-Link connector
- Ensure the USB to serial converter is in 3.3 V mode
- Reset the board, the user LED should now be off
- Download and install Flash Loader Demonstrator from here: 
- Use Flash Loader Demonstrator to flash the bootloader
- See screenshots below
- Select the correct COM port, yours will be different from the screenshots
- For normal use, set both boot pins low
- B0- to center pin B1 stays the same
Steps 1-4 and 7 are the same for both Windows and Linux
For steps 5-6, use the command from the Maple Mini Linux procedure, changing the paths and filenames as necessary
cd ~/.arduino15/packages/stm32duino/tools/stm32tools/1.0.9/linux/stm32flash ./stm32flash -w ~/Downloads/generic_boot20_pb12.bin -v -g 0x0 /dev/ttyUSB0
Flashing the bootloader - Maple Mini
Download the bootloader binary from here: 
Connect Serial1 to your computer using a USB/TTL converter.
Connect the adapter TXD to RX1 and RXD to TX1.
A video of the connection procedure is here: 
Jumper the Boot1/PB2/D2 pin to ground.
Power the board from the 3.3v pin on the USB adapter. The on board USB connector should be disconnected.
Note: Some USB/TTL adapters (notably CP2102) have the RX and TX pins reversed, so RX connects to RX1 and TX to TX1.
Press and hold Button1 then press reset.
Windows: Download the STM Demonstrator GUI for windows from here  to upload the bootloader.
After flashing is complete, disconnect the USB/TTL adapter from your computer and connect a USB cable directly to the Maple Mini. You should be able to upload using Tools->Bootloader Version->Bootloader 2.0 (20K Ram 120K Flash).
Linux: The jumpers and wiring are the same as for Windows. Immediately after connecting the USB/TTL converter, open a terminal window and enter dmesg. Note the port assigned to the adapter. If this is the only USB serial device, it will likely be /dev/ttyUSB0. You can give the full path to the flash utility, but it's probably easier to go to the folder and run the program from there. Assuming the maple bootloader bin is in your ~/Download folder and your serial port is on /dev/ttyUSB0, run these commands:
cd ~/.arduino15/packages/stm32duino/tools/stm32tools/1.0.9/linux/stm32flash ./stm32flash -w ~/Downloads/maple_rev5_boot20.bin -v -g 0x0 /dev/ttyUSB0
The console should show that the board is detected and that the bootloader was written successfully.
stm32flash Arduino_STM32_0.9 http://github.com/rogerclarkmelbourne/arduino_stm32 Using Parser : Raw BINARY Interface serial_posix: 57600 8E1 Version : 0x22 Option 1 : 0x00 Option 2 : 0x00 Device ID : 0x0410 (Medium-density) - RAM : 20KiB (512b reserved by bootloader) - Flash : 128KiB (sector size: 4x1024) - Option RAM : 16b - System RAM : 2KiB Write to memory Erasing memory Wrote and verified address 0x08001bc0 (100.00%) Done. Starting execution at address 0x08000000... done.
Now connect your USB cable to the board and run dmesg. You should see the Maple pid/vid:
[Sat Oct 22 12:20:45 2016] usb 3-3: New USB device found, idVendor=1eaf, idProduct=0003 [Sat Oct 22 12:20:45 2016] usb 3-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [Sat Oct 22 12:20:45 2016] usb 3-3: Product: Maple 003 [Sat Oct 22 12:20:45 2016] usb 3-3: Manufacturer: LeafLabs [Sat Oct 22 12:20:45 2016] usb 3-3: SerialNumber: LLM 003
The above procedures work for any STM32 board. You will need to download the correct bootloader bin to match your board and change the jumpers to Boot0=1 and Boot1=0 for the flash procedure. Once the flash procedure is complete, set both Boot jumpers to 0.