Skip to main content

Flashing an STM32 "Blue Pill"

Flashing this STM32 "Blue Pill" board took me 5 hours.

I finally recieved my microcontrollers. I have at disposal :
  • A brand new WeMos D1 Mini (it's a smallish NodeMCU)
  • An Arduino Pro Mini (it acts just like a Leonardo, but it lacks some interesting pins sadly :(  )
  • An STM32F103C8T6, I'll call this the Blue Pill for short.
The Arduino Pro Mini has an Arduino bootloader out-of-the-box, so  I could play with it directly. It's nice ! Still, it lacks the double Serial of the original Leonardo, and most importantly, there's no A4 and A5 pins, so libraries for I2C won't work without modification.

But the Blue Pill needs more work. Basically, I followed the instructions on this site :
Since it's quite complicated, consider the following as a tutorial to set up your Blue Pill. I tried different things, the following has worked for me.

Before doing anything software-related, while reading the Blue Pill page ( ), I found out that the USB connector is not really soldered, and is very fragile. Looking on my Blue Pill, I saw that the 4 legs didn't have any soldering tin. So I took my soldering iron out to add some tin on its 4 legs. It should make it sturdier.

The Blue Pill comes without bootloader. I will hence burn the STM32duino bootloader. The procedure is somewhat detailed here :
A simple way to achieve this is to use an external USB-Serial adapter. To achieve that, I simply used the CH340 chip embedded on my old (and dead) NodeMCU.

My Blue Pill uses the USB-Serial chip from the NodeMCU for its bootloader flashing.

First things first, I connected the NodeMCU to the Blue Pill. I plugged as follows on the little scheme. You can notice that I pulled the NodeMCU RST to GND in order to disable the ESP8266, so that I can use freely the CH340 as USB-TTL adapter. It's a trick I've seen on some Youtube video. If you have for example an Arduino Uno, you can do the same by disabling the Atmel chip with this RST-GND strap.

Then, I put the jumpers to allow flashing. Just see the photo !

Pins I linked together. Notice the RST-GND ! Plus, positions of the jumpers to allow bootloader flashing.
hoto. After doing this, you have to press the Reset button on the board. The onboard LED should stop blinking.

Then, I have to download some useful stuff :
I extracted the archive, installed the Flash Loader Demonstrator, and started it (it's called Demonstrator GUI). I entered these options (see following screenshots). Because my personal Blue Pill has its onboard LED on pin PC13, I chose the bootloader called generic_boot20_pc13. I tried with several other bootloader and the PC13 was the only one working for me. I can only advise you to be extra careful when choosing your bootloader, otherwise you won't find where your errors come from.


After burning successfully, I unplugged everything. I installed the Windows drivers by launching the install_drivers.bat in the archive (it's in drivers --> win ). I put both jumpers on 0 (instead of 1 and 0). These jumpers indicate the BOOT mode (the upper one is jumper BOOT0, the lower one is BOOT1. In short, I put BOOT0 and BOOT1 to 0).

I opened my Arduino IDE and configured it to recognize the STM32 family. First, I opened the Board Manager and installed the Arduino Due. According to the STM32duino website, it should install the Cortex M3 compiler.

I added the STM32 boards repositories into the Arduino IDE by going into "Preferences", then adding into the repositories the following URL :

You can see I already had the repository for ESP8266. The STM32duino has been added.
Then, in the Board Manager, I installed the boards STM32F1xxx (just type STM32 in the research and choose the right one). I closed and re-opened the IDE, plugged the Blue Pill with the USB cable, and began my first Blink example :

 Blink: Turns on the built-in LED on for one second, then off for one second, repeatedly.
 Arduino 1.6.0rc1
   Sketch uses 11,900 bytes (11%) of program storage space. Maximum is 108,000 bytes.
   Global variables use 2,592 bytes of dynamic memory.
 Ported to Maple from the Arduino example 27 May 2011 By Marti Bolivar

void setup() {
    // Set up the built-in LED pin as an output:
    pinMode(PC13, OUTPUT);

void loop() {
    digitalWrite(PC13,!digitalRead(PC13));// Turn the LED from off to on, or on to off
    delay(1500);          // Wait for 1.5 second (1500 milliseconds)

The Arduino IDE uses "user-friendly" names for the pins. I used the pinout from the wiki (names in light yellow. It just corresponds directly to what's written on board, so it's really convenient. I just wrote "PC13" in order to control the Pin written "C13" on the board.
Blue Pill pinout. Credits :

In the Windows Device Manager, before the first flashing, the Blue Pill appears as a Maple DFU. It's like a "ready-to-be-sketched" Maple Mini board. When launching the first upload on the Arduino IDE, it detects the Maple DFU and programs it in order to assign it to a COM port. After the first programming, the Blue Pill is detected as a Maple Serial (COM12) on my PC. I can't remember well, but if the first programming doesn't work because it doesn't find the Maple DFU (which may happen), just try again and quickly press the RESET button on the Blue Pill board when the Arduino IDE is searching for Maple DFU. It worked for me. I had a lot of different problems I can't really recall at this step ; try to re-burn the good bootloader if you can't find anything.

Don't pay attention to the RIM Virtual Serial Port... I had a BlackBerry.

At last, I have a glorious STM32 "Blue Pill", ready to be programmed through the Arduino IDE. It was quite a pain to figure out some of these things, but hey, that's why I write on this blog. I hope this might help someone to set up all of this.

Final words : I though about calling this rant "Flashing open a cold "Blue Pill" one with the "Arduino" boys, but I don't think Google would reference it correctly.

See you next time where I'll play with buttons, LEDs, interrupts, I2C and LCD screen !


Popular posts from this blog

KaRadio DVT-01

I packed everything in my little case.

It's really a mess in there, with cables flying around and every card floating, not fixed on the inside. But it looks quite cool ! I removed the old radio antenna to use its hole to pass my USB cable.

Here's how it looks !

As you can see, I let the rotary knob (it's a simple angular potentiometer, in fact) from the amplifier out. It holds with a little nut that was provided with it. The buttons you can see are all fakes, they belonged to the old radio and I forgot to remove them (in fact they're simply glued to the back). 
Maybe I'll find some tools to make a nice-looking front panel when my stuff arrives. I'll ask people around me to lend me their tools...  In the end, the radio would have a 20x4 LCD screen to display artist + title and useful infos (like the IP or the volume when you change it from the website, maybe). I think I'll need two more buttons to change the station. I won't bother myself to add a volume…

Adding some speakers, part 2

I added the audio transistors.

Before diving into this modification, I wanted to see how deteriorated the sound is when you try to link everything on the same power supply WITHOUT transistors. So I made this little video. You can hear the difference !

First, I noticed that my three little wires (on the output of the VS1053) were badly soldered and caused a short-circuit somewhere. So I removed them, and replaced them with a naked Jack plug. (I took it from a selfie stick. True story. These selfie sticks have an audio Jack plug to be able to take a shot from a button near the hand, that acts just like a button from headphones with mic. End of the story, back to business :p )

I wired the output of the VS1053 to the input of the transformers, and I wired the output of the transformers to the input of the PAM8403 (the amplifier). Since on the input and on the output, they have common ground between the two channels, I kept the common ground. You can see a rough scheme below (the "Aud…