How to program STM32F103 board (the Blue Pill) using its USB port

Once upon a time, I bought some new Arduino compatible board, STM32F103 a.k.a Blue Pill (STM32F103CBTL).

Blue Pill
STM32F103 Board Blue Pill

I don’t know about this board before and has no experience in STM related board, but my friend suggest me this board is powerfull in small and cheap form which make me curious. I manage to use it with Arduino IDE using FTDI Serial to burn the program, just like in this tutorial but I have big QUESTION in my head “why they didn’t use its own USB port to burn the program??”. Now I will give you the step, after I crawling on several sites related and compile it for you (tested on Windows 7 64 bit, additional ‘python27’).


This STM32F103 board I bought only comes with a default USART bootloader (I think for other similar board from China also). Even though there is a USB port on the board, it cannot be used to program because of its factory bootloader. We need to add another USB bootloader using a simple USB to UART converter (me using FTDI) to program the board via USART, and after those steps hopefully, we can program it directly via USB.

Actually, there is 2 step to burn the USB Bootloader, using ‘python script’ or using ‘STM Software’, as a loader. We describe the ‘python script’ ways now because they share the script without any requisite.

Follow this step:

  1. Do wiring like this image below

    wiring STM32F103
    wiring STM32F103 (source)
  2. Move the Yellow Jumper for BOOT1 to 1 position (both BOOT1 and BOOT2 default position is 0).
  3. Connect the USB-Serial to your PC and Push the reset of the STM32F103 board.
  4. Download this python file, and extract to a folder (Make sure you have python27 in your computer, or just install it from this, and also do a,b,c step)
    a. Open cmd as admin.
    b. Go to scripts folder: C:\Python27\Scripts
    c. Type “pip install pyserial”
  5. Download this bootloader file which is USB bootloader with pin PC13 as built-in LED by Roger Clark.
  6. Put both python file and bootloader file into the same folder, and the move all those files into ‘Python27’ directory. (me C:\Python27)
  7. Open your CMD and run this following code:
    cd C:\Python27
    and then run also this code (please edit the port COM with yours)
    python stm32loader.py -p COM3 -w generic_boot20_pc13.bin
    will come out like this:

    Load bootloader
    Load bootloader
  8. After Finish Burning the USB Bootloader make sure you installing the STM32 USB driver. either from your Arduino IDE-Board Manager (change Additional Board URL in preference into “http://dan.drown.org/stm32duino/package_STM32duino_index.json”) or other ways.

Now the USB bootloader is burned into your Bluepill, hope it helps you…

Notes:

  • I guess the steps aren’t completely finished. It should contain step to verify the USB function, but I will complete it later in this post. You can also see the reference link below to crosscheck.
  • There is HW defect on some Bluepill board, you have to replace some Resistor, look at this link from amitesh-singh.

Reference and credits : Medium, Roger Clark, STM32 Wiki,

Leave a Reply

Your email address will not be published. Required fields are marked *