What is STM32 blue pill?
The STM32 Blue Pill is a 32-bit Arduino compatible development board that features the STM32F103C8T6. a member of the STM32 family of ARM Cortex-M3 core microcontrollers. The STM32 Blue Pill board has nearly all the capabilities of the Arduino module but with a cheaper price.
Technical Specifications
STM32F103C8T6 has operating voltage equal to 3.3V, with 10 analog inputs and 37 digital I/O pins. It have flash memory of 64/128KB and SRAM 20KB. Maximum clock frequency that can be achieved is 72MHz. I2C,SPI, UART, CAN, USB these are the possible mode of communication.
The STM32 BluePill
How to power the STM32 Blue Pill
The STM32 Blue Pill development board can be powered in different ways. Power can be provided by providing 5V to 5V pin as external supply or by supplying 3.3V directly to the 3.3V pin or by using built-in USB micro connector.
Input-Output
The Blue Pill has 4 ports with total of 37 GPIO pins, different ports have different number of pins. Ports A and B has 16pins, port C has 3pins, and Port D has 3Pins. Pull-up and pull-down resistors can be enabled on each of the pins. Each pin has a current source/sink ability of 6mA. Pin 13 has built in LED. Most of the pins can perform more than one functions like PWM, SPI-serial communication, I2C ports (two-wire communication via the IIC protocol).
STM32 blue pill pinout
- Power: 3.3V, 5V, GND these three pins can be used to power board.
- Analog pins: PA0-PA7 , PB0-PB1 these pins act as ADCs.
- Serial: TX1,RX1,TX2,RX2,TX3,RX3 these are UART pins.
- External interrupts: PA0-PA15, PB0-PB15, PC13-PC15.
- PWM: PA0-PA3,P6-PA10,PB0-PB1,PB6-PB9.
- SPI: MISO0,MISI0,SCK0,CS0, MISO1,MISI1,SCK1,CS0
- I2C: SCL1,SDA1, SCL2,SDA2
- CAN: CAN0TX,CAN0RX
How to upload program
There are two ways to program it. 1st one is using an external USB/Serial converter connected to UART1 pins, it can be programmed using Arduino software. 2nd way is STLink USB Dongle – this uses the single-wire debug interface to communicate with the board. This allows it to be programmed using advanced software like Keil/CubeMX. It also allows memory access using the STLink software.
How to set up in Arduino IDE:
One can setup IDE by following given steps:
- Open Arduino IDE and select Preferences in file section, you can also select it by ctrl + comma.
- After that Click on the Additional Board URL option and add this URL, if you want to add more than one URL you can separate them with comma.
- Next go to Tools → Board → Board Manager. Then search for STM32. Then select latest version and click install.
- Now you can select board from tools- board – generic STM32F1 series.
- Select BluePill F103C8, make U(S)ART support, as Enabled (generic ‘Serial’) and Upload method, make it as STM32CubeProgrammer (Serial).
Code for blinking LED
void setup() {
pinMode(PC13, OUTPUT);
}
void loop() {
digitalWrite(PC13, HIGH);
delay(1000);
digitalWrite(PC13, LOW);
delay(1000);
}
Code for taking reading from an Analog pin on the UNO and displaying it on an LCD Display
There are 10 analog input pins. We can use any of them, for now we will use ADC0 i.e PA0 for analog input. And 16 x 2 LCD display as output device.
//Created by Devendra Sanklecha, KRSSG, IIT Kharagpur
#include <LiquidCrystal.h>
int rs = PB11, en = PB10, d4 = PB0, d5 = PB1, d6 = PA7, d7 = PA6;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int analogInput = PA0;
void setup()
{
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“KRSSG”);
lcd.setCursor(0, 1);
lcd.print(” ADC in STM32 “);
delay(2000);
lcd.clear();
}
void loop()
{
int analogVal = analogRead(analogInput);
float inputVoltage = (float(analogVal)/4096) * 3.3;
lcd.setCursor(0, 0);
lcd.print(“ADC Value:”);
lcd.print(analogVal);
lcd.setCursor(0, 1);
lcd.print(“Voltage:”);
lcd.print(inputVoltage);
}
This blog has been submitted by KRSSG, IIT-Kharagpur under the Robocraze Club Outreach Program.
Author: Devendra Sanklecha