Program STM32 Blue Pill (STM32F103C8T6) with Arduino IDE - GitMasterNikanjam/Arduino_WiKi GitHub Wiki

STM32 Blue Pill is a feature-rich development board based on STM32F103C8T6 processor - a 32-bit ARM Cortex M3 processor running at 72MHz frequency. Unlike the common Arduino board which is easy to use, programming the STM32 Blue Pill can be confusing especially for a new user.

There are several ways to program the STM32 Blue Pill with Arduino IDE - some require external hardware, others just need an USB cable. In the following guide, we will cover three common methods of downloading the sketch in Arduino IDE:

Arduino bootloader for program through USB Port
STMCUBE programmer Software
USB to 3.3V TTL adapter

So roll up our sleeves and get started.

Download and install Arduino IDE

The first thing you need to do is to download and install the Arduino IDE to your computer. You can get the latest version from the official Arduino website: https://www.arduino.cc/en/Main/Software

Follow the link below to install the Arduino IDE:

Windows: https://www.arduino.cc/en/Guide/Windows
Mac OSX: https://www.arduino.cc/en/Guide/MacOSX

Install STM32 Add-on to Arduino IDE

In your Arduino IDE, go to File > Preferences
Add the URL below to Additional Board Manager URLs text box:

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

If the text box is not empty, you can separate the URLs with a comma.

image

Go to Tools > Board > Boards Manager

image

Search for STM32, select latest version and click Install.

image

There are a few megabytes of data to download and install, so be patient.

Once the installation is completed, quit and restart the Arduino IDE.

1. Arduino bootloader for program through USB Port (Windows & Mac OSX)

The STM32 Blue Pill is pre-flashed with Arduino bootloader which allows you to download the sketch through the Type-C connector.

NOTE: Using JLink / ST-Link dongle or USB to 3.3V TTL adapter to program the board will erase this bootloader.

we will learn how to program STM32 Blue Pill through USB port by uploading Bootloader to the board. It is a step by step guide which will help you to install STM32 Bootloader and then program your Blue Pill through the micro USB port using Arduino IDE.

The STM32 Blue Pill comes with a micro USB port but it does not contain the Arduino ready boot loader. Therefore, we use USB-TTL converter to upload code as the board is not discoverable if connected through the USB port. Moreover, as seen in previous STM32 Blue Pill tutorials, in order to successfully upload code we had to move the BOOT jumper from 0 to 1 to enable the microcontroller to go into programming mode. Therefore, in order to utilize the USB port of Blue Pill ad upload code just like with other microcntrollers like Arduino, ESP32 etc. we will install the bootloader. Follow this step by step guide to successfully blink the onboard LED of your Blue Pill with Arduino IDE through the micro USB port.

Prerequisites

Before we move ahead, let us list the hardware components and the software packages that will be required for this guide.

Hardware Required

STM32F103C8 Board
USB-TTL Converter
Connecting Wires
Breadboard
1.5k ohm resistor (if required)

Software Required

STM32 Flash Loader (Download from this link)
STM32duino Bootloader generic_boot20_pc13.bin (Download from this link)
STM32 USB Mini Driver (Download from this link)

Circuit Setup to Flash Boot Loader

In order to successfully flash the boot loader we will have to first connect our STM32 Blue Pill with a USB-TTL converter/FTDI programmer. Follow the table below to connect the two devices.

USB-TTL Converter STM32 Blue Pill
VCC 3.3V
GND GND
RX PA9
TX PA10

image

Upload Maple Bootloader to STM32 Blue Pill

After connecting your STM32 Blue Pill with a USB to TTL converter, let us show you the process to upload the maple boot loader to our Blue Pill.

First connect STM32 Blue with USB to TTL converter as shown in the circuit diagram above. Make sure to move the BOOT jumper from 0 to 1 to enable the microcontroller to go into programming mode. Now plug the USB to TTL converter in your computer.

Next, make sure you have downloaded the STM32duino Bootloader generic_boot20_pc13.bin (Download from this link) file from this link. Now, download the STM32 Flash Loader (Download from this link)

image

Download the STM32 flasher by first accepting the license agreement, registering your account on my.st.com and then you will get the download link on your email.

Open the STM32 flasher. It will detect the COM port through which the USB to TTL converter is connected. You can even confirm the COM port through the Device Manger. In our case it is COM5. Click ‘Next’ to proceed further.

image

As our connections are proper, hence target is readable message appears. Click ‘Next’ to proceed further.

image

The target is automatically detected. Click ‘Next.’

image

Now select the ‘Download to device’ option and click the box with the three dots highlighted below:

image

Select the generic_boot20_pc13.bin file that we previously download from its saved location. Then, click ‘Next’ to procced further.

image

The download process will start shortly.

image

After the STM32 is successfully flashed with the boot loader, you will view the success message. Now click the ‘Close’ button.

image

Now lets move to the next step. We will now have to setup our Arduino IDE for STM32 Blue Pill programming as well as install the required drivers.

Remove the USB-TTL converter from the STM32 Blue Pill and plug the Blue Pill using the USB port. Setting up Arduino IDE for STM32 We will use Arduino IDE to program our STM32 Blue Pill using the micro USB port. Thus, you should have the latest version of Arduino IDE.

Setting up Arduino IDE for STM32

We will use Arduino IDE to program our STM32 Blue Pill using the micro USB port. Thus, you should have the latest version of Arduino IDE. Additionally, you also need to install the STM32 plugin. First of all open your Arduino IDE and head over to File > Preferences and add the following link in the Additional Boards Manager URLs:

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

Now head over to Tools > Board > Board Manager. Type ‘STM32F1’ in the search bar and press enter. Install the board package highlighted below:

image

After the installation is complete, you will be able to view STM32F1 Boards in Tools > Boards.

image

Select ‘Generic STM32F103C series’ from the board section. The Upload method is “STM32duino bootloader.” Note that the USB port is still not discoverable at this moment. We have to install STM32 USB driver now in order for the port to be visible.

image

Install STM32 USB Driver

First of all download the STM32 USB Mini Driver (Download from this link). After the download is complete open the folder and navigate to drivers > win > install_drivers

Click install_drivers and the Maple DFU and Serial drivers will start installing in the command prompt:

image

After a few minutes, you can view that the Maple DFU driver is successfully installed.

image

Likewise, the STM Serial driver is also successfully installed.

image

Now head over to Arduino IDE Tools > Port or Device Manager to check whether the port through which the STM32 Blue Pill is connected is visible or not. Maple Mini will be written in brackets along with the COM port.

image

If the port is still not visible, solder a 1.5k ohm resistor between the Blue Pill’s 3.3V and PA12 pins.

Program STM32 Blue Pill through the USB Port

Now we are ready to program our STM32 Blue Pill directly through the USB port. Open Arduino IDE and head over to File > Examples > A_STM32_Examples > Digital > Blink

The basic example sketch to toggle the onboard LED after every second will open up. For STM32 Blue Pill, the onboard LED is connected with PC13. Remember to change the LED pin configuration in code accordingly.

/* Blink Turns on an LED on for one second, then off for one second, repeatedly.

Most Arduinos have an on-board LED you can control. On the Uno and Leonardo, it is attached to digital pin 13. If you're unsure what pin the on-board LED is connected to on your Arduino model, check the documentation at http://arduino.cc

This example code is in the public domain.

modified 8 May 2014 by Scott Fitzgerald

Modified by Roger Clark. www.rogerclark.net for Maple mini 25th April 2015 , where the LED is on PB1

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin PB1 as an output.
  pinMode(PC13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(PC13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(PC13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

The following code sets PC13 to a high state for a second and then to a low state for a second. This occurs inside the infinite loop function hence causing the onboard LED to toggle after each second.

Demonstration

Choose the correct board and COM port before uploading your code to the board.

Therefore go to Tools > Board and select Generic STM32F103C series Then, go to Tools > Port and select the appropriate port through which your board is connected. In our case it is COM14

image

Click on the upload button to upload the code to STM32 Blue Pill. Make sure that the BOOT jumper is present at 0. There is no need to move it to 1. The picture below shows a successful upload of code through the boot loader.

image

After you have uploaded your code to the board, press its RST button. When you press the RST button, the onboard LED starts blinking.

2. STMCUBE Programmer (Windows only)

There are many software programmer eg (CUBE Programmer, ST-LINK Utility, STM32 Flashloader).
it can choose any software to upload binary code to STM microcontroller.
at this, we want introduce use STMCUBE Programmer software for upload custom binary code that exported from arduino ide.

This method just used when the compiled binary of arduino code existed.
NOTE: Using JLink / ST-Link dongle to program the board will erase the Arduino bootloader.

For Export compiled binary code in arduino got to Sketch -> Export Compile Binary

Screenshot (9)

Install STM32CubeProg

Download and install STM32CubeProg from ST.com: https://www.st.com/en/development-tools/stm32cubeprog.html

image

Start the STM32CubeProg. It will look like this:

image

Connect STM32 Blue Pill to ST-Link compatible Emulator And Programmer dongle

Follow the wiring diagram below to connect the STM32 Blue Pill to ST-Link compatible Emulator And Programmer dongle.

STM32 Blue Pill ST-Link compatible Dongle
GND GND
SCK SWCLK
DIO SWDIO
3V3 3.3V

image

Connect the dongle to your computer. NOTE: Do not connect STM32 Blue Pill to computer via Type-C USB cable.

Start the STM32CubeProg. In the top right corner, below the Not Connected message, find the dropdown to the left of the Connect button

Select ST-Link and Click Connect button.

image

You should see the Target information panel in the bottom right corner.

image

Select binary file path and click on start programming.

image

Now The application can run on Bluepill board.

3. USB to 3.3V TTL adapter (Windows only)

NOTE: Using USB to 3.3V TTL adapter to program the board will erase the Arduino bootloader.

Wiring

Follow the wiring digram below to connect the STM32 Blue Pill to USB to 3.3V TTL adapter.

STM32 Blue Pill USB to 3.3V TTL Adapter
3.3V 3.3V
GND GND
A10 RX
A9 TX

image

Connect the adapter to your computer. NOTE: Do not connect STM32 Blue Pill to computer via Type-C cable.

Setup Arduino IDE
Follow instructions above to install the STM32 Add-on to Arduino IDE.

Set the Upload method to (Serial)

image

These are your Tool configurations:

Screenshot (8)

Upload sketch

Create a LED blink sketch.

Set the STM32 Blue Pill to bootloader mode using both BOOT0 connected to 3.3V and Push NRST button to reboot the board.

Click on the upload button to compile and upload the code to STM32 Blue Pill.

Once the sketch is successfully uploaded, the blue LED should blink at 0.1 second interval

⚠️ **GitHub.com Fallback** ⚠️