Arduino Alternative - STM32 Blue Pill Programming Via USB

61K3040

Intro: Arduino Alternative - STM32 Blue Pill Programming Via USB

You and I both love Arduino boards, from the smallest Attiny85, to the biggest MEGA2560. However if you need more speed, more analog inputs, more precision, but still don't want to switch from Arduino programming, there's a elegant solution....The blue pill!

If you haven't heard there's an Arduino nano like board, nicknamed the blue pill. Would you care to guess it's colour?

The best thing (apart from it's amazing speed and overall performance) is the ability to program it with the Arduino IDE, essentially making it an Arduino.

You'll say it sounds too good to be true and it kind of is. There is a catch. The boards can't be programmed over USB, since they don't come with a bootloader. (A bootloader is basically Windows for microcontrollers, it doesn't do anything, but you still need it to run stuff)

In this instructible I'll show you where to get the boards, how to program them and FIX the no USB connection problem so you can program it exactly like an Arduino, using just a USB serial connection.

STEP 1: What You'll Need:

First you'll need the board itself. I recommend you buy them here:

https://www.ebay.com/itm/192674786885

You'll also need a USB to TTL programmer which you will only need to program the board the first time, but it's also usefull for other projects so you might as well own one...you can get it here:

https://www.ebay.com/itm/401604236499

Some wires or jumper cables are also usefull, but I'll assume you have those on hand. If not, improvise.

STEP 2: Arduino IDE

Before you can start programming the blue pill in the Arduino IDE. you'll need to add a few things. Don't worry, this is quite easy.


First open the Arduino IDE. Go to File->Prefferences...a new window will open

At the bottom there's a line saying "Additional Boards Manager URLs:"...at the end of the line, there's an icon of two windows open, click that.

Yet another window will open and there you have to write

http://dan.drown.org/stm32duino/package_STM32duino_index.json

If you already have something in the window, just go into a new line. Then click OK and close Arduino IDE.

See, the hard part is done.

Now you should open the IDE again and go to Tools->boards->Boards Manager (it's the very first thing on the list)

A new window will open and where it says "Filter your search..." you should type in stm32f1

There should only be one result. Click install (lower right corner) and wait for it to install. When that finishes, close the IDE again.

There you're all done with the IDE part.

STEP 3: Drivers

Since windows doesn't properly recognise the board, you should manually install the drivers. This too it just a "drag and drop" process so don't worry, I'm sure you can handle it.

First, download the drivers here:

https://github.com/rogerclarkmelbourne/Arduino_STM32

You do this by clicking the green button that says "Clone or Download" then selecting Download ZIP.

Once you've done that, open the zip file. Keep it open and go to where ever your Arduino installation folder is. It's usually C:\Program files(x86)\Arduino

Once there, open the hardware folder...you should have one, but if not, just make one.

Once you're in the hardware folder, drag the "Arduino_STM32-master" from the ZIP to the hardware folder. Rename it to Arduino_STM32 (just delete the master part)

Now open the Arduino_STM32 folder...there is a folder inside that's named drivers. Somewhere in that folder you'll find a file named install_drivers (it's a batch file). Click on that and install the drivers. Just say yes to everything.

Congratulations, you're basically done...well, almost.

STEP 4: Burning the Bootloader

Remember that "windows" thingy that needs to be on the board in order for you to use the USB, well, we have to put it on the board now. It's called a bootloader, but the name doesn't really matter.

In order to do this, you'll need two things. Download both here:

https://www.st.com/en/development-tools/flasher-stm32.html

This is a program that you use to install the bootloader. (bottom of the page) You need to register to the page and then you get to download it.

You also need to download the bootloader itself. You can get that here:

https://github.com/rogerclarkmelbourne/STM32duino-bootloader/tree/master/binaries

Download "generic_boot_pc13.bit"

Now that you have everything you need to start, it's time to connect everything up and burn the bootloader.

Plug your USB-TTL adapter into a USB port.

Make these connctions

USB-TTL........blue pill

TX.........A10

RX.........A9

3.3V.......3.3V

GND.......GND

On your blue pill, the top most jumper has to be on the right side. (see picture)

Now open the software you just downloaded. Install it (just click next next next) and then open it.

It should recognise your device and list a COM port. If it doesn't check if you missed a stip or if your connections are ok. Also run the software again so it resets.

Once you have a COM port recognised, you can click Next 3 times, then you'll come to a window where it's possible to select "Download to device"...select it and where it says "Download from file", click the ... icon and find your bootloader. Select it, click ok and again click Next. This will install your bootloader. You can close the program now, but DO NOT disconnect the board yet!

First make sure to put the top most jumper on the board back to the left side, so both of them are on the 0 position. Now you can disconnect everything.

STEP 5: First Programming

Open your Arduino IDE. Go to tools and where it says "Boards", select "Generic STM32F103C series"

Select the upload method as STM32duino bootloader

Select the Port to be "COMX (Maple Mini)"....the X is what ever your port number is.

Your blue pill just became a Maple Mini. Again, don't forget the jumpers as shown on the picture.

You're good to go. For your first program you don't need to upload anything fancy, you can just upload a blank sketch with a setup and loop funcion, but I like to make a Serial.print program, since that's way more satisfying. My program is attached below. It's a txt file, so just copy it into you Arduino IDE if you wish to use it.

The IDE might report an error, buf will still upload the program, so you
can just ignore it. If you still run into problems, try putting the lower of the two jumpers to the right position.

With all that done, congratulations! You now can use the blue pill as an Arduino!

If you enjoyed this Instructable, consider visiting my Fundrazr page here. And of course, share.

21 Comments

Hi, guy!
It is a really good article. I am new to the stm32 microcontroller, which have some difficulties in progressing the STM32 family. And I try to search for some resources for it. Therefore, this article is very useful.
Thanks!
Just buy it from another place...

Crikey there are a lot of places where thats going to go wrong. Can see it coming . I'm not gonna try it . You don't seem to have given us any reasons to do this? Whats the pitch?

You can program it over usb. Thats a big plus, since you sont waste any pins and you dont need a usb adapter

You can program most controllers over usb . Thats no reason to go through all those complicated steps to get this thing programmed?

There is, if you want to program it by the USB port. Yes, it can be programmed through th USB port. But as an ordinary Arduino, you have to have a bootloader to support that, also with them...
The Blue Pill series of boards don't come natively able to download code through the USB; that functionality needs to be programmed into them This tutorial outlines the process of preparing the board to use the USB for code download. When one first receives the Blue Pill board from the distributor, it can only download code either through the UART using a USB-serial convertor, or through the ST-link connector on the end of the board.
Hi, after reading your post, I 'm interested in using the blue pill too in my project,
please add an information about how to protect the stm32 chip from reading the code that has been programmed in.
thank you in advance
Why would you like to do that?
Hi, just wanted to say that I have finally managed to get my bluepill talking to my PC thanks to the above insructions! Have a great day!
Hi,
very good article.
I tried and all works fine.
I need to use a module NRF24L01.
With Arduino Nano all is fine, but with BluePill the library has some problems.
Do you have tried it, or have some hints.
Thank you very much.
elvisee
For the ST bootloader to recognize your device you have to press the "reset" button on the bluepill after it has been plugged in
Thanks for this, I was going to use a Pro mini for it's USB capability until I found out that the PCB did not provide a single 8 bit port! I shall be referring to this when I need it. :)
So the question is, can this unit emulate a USB HID when suitably programmed?
I must have a bad Blue Pill, cannot get a com port. But bootloader is fast flasing (green led)
Did you find a solution to this?
In Arduino preferences I put in :
http://dan.drown.org/stm32duino/package_STM32duino...
And when I close the IDE and then open and go to boards manager I get an error "file signature verification failed" so is there an updated version of this file that won't generate this error?
Oops! when i typed in the URL under preferences I typed brown and not drown. Made
the correction and file loaded no issues.
Followed through and made it succesfully. Thank you so much
I think, it is better to use %userprofile%\documents\arduino\hardware instead of %programfiles%\arduino\hardware... and actually all you need is already there after installing stm32duino from the boards manager in Arduino IDE.
More Comments