Introduction: STM32 "Blue Pill" Progmaming Via Arduino IDE & USB

Comparing STM32F generic prototype board (i.e. Blue Pill) to its counter part Arduino is easy to see how much more resources it has, which open a lot of new opportunities for IOT projects.

The cons are the lack of support to it. Actually not really lack of support, but it is too spread in many forums, blogs and bunch of other pages. Many are outdated.

I will describe my experiences to get one those boards not only configured by Arduino IDE but also via it built in USB connector.

I also will show how upload Bootloader using ST-Link V2.

Step 1: Parts:

You will need some parts:

  1. First thing you will need is, of course,a ST32F103 prototype board. "Blue Pill" is how it is know around, and you can buy it for affordable price in many eCommerce store.
  2. An ST-Link V2 Module
  3. Bread board and jump cables

Step 2: Software You Will Need:

  1. First of all, Arduino IDE. If you did not download it yet, this is the link: I test this instructable with version 1.8.11, 1.8.12, and the app version, which work only for Windows 8 and 10.
    I will not cover this software installation, once there are many information around how do it.
  2. From STM site you will need below software. It is necessary to create a account:
    1. ST-Link V2 windows driver:
    2. STM32-Link Utility (
  3. Then it is time to download Boot loader. This is what will allow Blue Pill to connect to computer USB. This is the link to this:

Notice you will also need add boards to Arduino IDE. I will explain in details how do this.

Step 3: STM32F103 Generic Prototype Board, the Blue Pill

Now a brief explanation about STM32F103 prototype board, know by "Blue Pill".

This is open source hardware, looks alike Arduino Nano (almost similar size). You may find many different manufacture, but they follow schematic very close, even the issues.

You may ask: "If it looks like Arduino Nano, why I should move to a different hardware?

Answer is simple. Like I told already, if your project need Faster Micro controller, with more GPIO (33 in total), more and/or precise ADC inputs (10 inputs x 12 Bits resolution), more analog outputs (15), more communications interfaces, etc; this is the micro controller you may need.

Above there is the pin out and schematic diagram.

Now, some advises:

  1. This is 3V3 micro controller. Despite some pin's are 5V resilient, I suggest keep accessories level high in 3V3, other wise you can fry you Blue Pill.
  2. Pin's PA11 and PA12 are not available, once they are responsible for USB communication.
  3. Talking about USB, You will find many sites and blogs informing Blue Pill has a wrong pull up resistor value in its ports. According then, they are in general 10KΩ instead of a 4,7KΩ.This may cause USB connection problems.
    To be honest, I have 3 boards and I never had problem to connect any of then in any laptop. So, I would recommend just work on it if you really get problems to connect USB to your computer. Late I found a circuit draw were this resistor value was indeed 10KΩ. Go figure....
    Solution is solder a 1.5KΩ or 1.8KΩ resistor between pin PA12 and 5V vcc.
  4. A close look at diagram also is possible to see there is no protection between 5V power supply lines and USB 5V.
    BE CAREFUL OR JUST avoid use multiple power supply sources. You may fry your computer USB port, if perhaps you use an external 5V power supply mean while board is connect to USB.

Step 4: ST LINK V2 USB Adapter

ST LINK V2 is a USB to SWD adapter, designed for debug and programming tasks.

If you intend to work with STM32 chip in serious manner, you will need this tool. It allows you to communicate to chip directly via SWB head connector.

There are a lot of blog and site with instructions how load using USB to TTL adapter, but I could not find any using this tool to load boot loader.

This also allow to program Blue Pill with original boot loader using STM32Cube Programmer software (maybe I will create a instructable for this in future).

To install Windows drive follow this steps:

  1. Unzip downloaded file
  2. Run "stlink_winusb_install.bat as Administrator
  3. Press key after it finishes.
  4. Connect ST-Link V2 to any available computer USB.

Remember: This will install a USB Device, NOT a comm port.

Step 5: Time to Start Real Work: Loading STM32Duino Boot Loader

First things first: connect ST-Link to Blue Pill. This is very simple, once ST pin out is labeled over its case.

ST-Link Blue Pill SWD Connector

pin2- SWDIO <--------->pin2- SWIO (or IO in some boards)

pin3- GND <----------->pin4- GND

pin6- SWCLK<----------->pin3- SWCLK (or just CLK)

pin7- 3.3V <------------>pin1- 3V3

ST-Link V2 pin out is clear label over its body.

Run "STM32 ST-Link Utility" software (you may have already installed in you computer).

As soon software loads, it will retrieve all data in Boot0 memory. If not, click in "Connec to to Device", the outlet plug with a bolt icon. It will also retrieve a lot of STM32 chip information.

load binary file is very simple:

  1. Move "Boot0" jumper to "1" position
  2. Click in "Binary"
  3. Select Bootloader file (.bin)
  4. At menu, click in "Target" and "Program".

This will allowed load Boot0 with new Bootloader.

  1. Return "Boot0" jumper to "0" position
  2. Press reset button.

ATTENTION: You will never need to move Boot0 jumper anymore to "1" position to load programs created in Arduino IDE.

Step 6: Time to Deal to Arduino IDE

You may noticed after load "generic_boot20_pc13.bin" your Blue Pill USB port will be recognized by the computer Device Manager as "Maple Serial (COMx)".

To prepare you Arduino IDE to deal to STM32, follow steps below:

Step 7: Time to Deal to Arduino IDE

Now you may noticed, connecting you USB port to your computer, it would be recognized as "Maple Serial(COMx)".

Now, lets prepare Arduino IDE for STM32 programing. Open Arduino IDE, if did not open it yet:

  1. Go File menu and select "Preferences". This will open the Preferences window.
  2. Click on the double square icon close to "Additional Boards Manager Url" text box.
  3. Inside Text Box, copy and paste below links, one each line:

    You will need both boards set in those links.
  4. Now go to "Tools" menu and select "Board Manager". This will open "Board Manager" Window.
  5. Be sure "All" is selected in "Type" and in text box type "STM32F1"
  6. Install both option appear.

Step 8: The "Gran Finale"

Now, you can type your code and compile it.

Connect your "Blue Pill" and set configurations as it is in picture. Be sure to select correct port.

So, now it is ready to upload code to "Blue Pill".

I hope it help you!