The STM32 Blue Pill (STM32F103C8T6) is arguably the most exciting budget microcontroller board available to hobbyists today. Priced at under ₹150 in India, it packs a 72 MHz ARM Cortex-M3 processor, 64 KB of flash, 20 KB of RAM, and a rich peripheral set that leaves the 8-bit Arduino Uno far behind. The best news: you can program it directly from the Arduino IDE using the STM32duino core — no proprietary toolchain required. This guide walks you through everything from installing the core to running your first sketch.
Table of Contents
- Why Choose the STM32 Blue Pill?
- Hardware Overview and Pinout
- Installing the STM32duino Arduino Core
- Upload Methods: ST-Link, USB Serial, and DFU
- Your First Sketch: Blink and Serial Monitor
- Using ADC, PWM, I2C, SPI, and UART
- Common Issues and Fixes
- Frequently Asked Questions
Why Choose the STM32 Blue Pill?
Compared to the Arduino Uno (16 MHz ATmega328P, 2 KB RAM, 32 KB flash), the STM32 Blue Pill offers:
- 4.5× faster clock: 72 MHz ARM Cortex-M3 vs 16 MHz AVR
- 10× more RAM: 20 KB vs 2 KB — enough for display buffers, audio, and complex data structures
- 2× more flash: 64 KB (up to 128 KB on many chips) vs 32 KB
- More peripherals: 3 USARTs, 2 I2C buses, 2 SPI buses, 10 timers, 10 ADC channels, USB Full Speed, CAN
- 3.3 V logic: Modern sensors and displays speak 3.3 V — no level shifting needed
- Price: Under ₹150 vs ₹700+ for genuine Arduino Uno
The trade-offs are a steeper initial learning curve (bootloader setup, upload tools) and 3.3 V I/O that cannot directly drive 5 V devices. Once the Arduino core is configured, the programming experience is nearly identical to standard Arduino development.
Hardware Overview and Pinout
The Blue Pill is named for its blue PCB color. Key components on board:
- STM32F103C8T6: 64-pin LQFP package ARM Cortex-M3 SoC
- 8 MHz HSE crystal: External oscillator; PLL multiplies to 72 MHz
- 32.768 kHz LSE crystal: For RTC (Real-Time Clock)
- Micro-USB connector: For power and USB communication
- BOOT0 and BOOT1 jumpers: Select boot source (flash, bootloader, SRAM)
- PC13 LED: Built-in LED (active LOW, unlike Arduino’s active HIGH)
- Reset button
The board exposes two rows of 20 pins each. Notable pins:
- PA0–PA7: ADC channels + GPIO + Timer channels
- PB6/PB7: I2C1 SCL/SDA
- PA5/PA6/PA7: SPI1 SCK/MISO/MOSI
- PA9/PA10: USART1 TX/RX
- PA11/PA12: USB D-/D+
- 3V3, GND (multiple pins)
Note: The board does not have a 5 V regulator output pin. All GPIO operates at 3.3 V. However, some pins are 5V-tolerant — check the STM32F103 reference manual to confirm which ones before connecting 5 V devices.
Installing the STM32duino Arduino Core
The official STM32duino core is maintained by STMicroelectronics and is the recommended choice over the older Roger Clark core.
Step 1: Add the Board Manager URL
Open Arduino IDE, go to File → Preferences, and add the following to Additional Boards Manager URLs:
https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
Step 2: Install the Core
- Go to Tools → Board → Boards Manager.
- Search for
STM32. - Install STM32 MCU based boards by STMicroelectronics.
The download is approximately 200 MB as it includes the ARM GCC toolchain.
Step 3: Select Your Board
After installation, go to Tools → Board → STM32 MCU based boards → Generic STM32F1 series. Then under Tools → Board part number, select BluePill F103C8.
Upload Methods: ST-Link, USB Serial, and DFU
Unlike Arduino boards with a built-in USB-serial chip, the Blue Pill requires a separate programmer for the first upload. There are three approaches:
Method 1: ST-Link V2 (Recommended)
The ST-Link V2 is a cheap (₹200–300) JTAG/SWD programmer. Connect:
- ST-Link SWDIO → Blue Pill SWIO
- ST-Link SWCLK → Blue Pill SWCLK
- ST-Link GND → Blue Pill GND
- ST-Link 3.3V → Blue Pill 3.3V
In Arduino IDE, set Tools → Upload method → STM32CubeProgrammer (SWD). Install STM32CubeProgrammer from ST’s website. This method works every time and supports debugging — strongly recommended.
Method 2: USB-to-Serial Adapter (UART Bootloader)
Set BOOT0 jumper to 1 (3.3V), BOOT1 to 0. Connect a USB-TTL adapter:
- Adapter TX → Blue Pill PA10 (USART1 RX)
- Adapter RX → Blue Pill PA9 (USART1 TX)
- Adapter 3.3V → Blue Pill 3.3V
- GND → GND
In Arduino IDE, set Upload method → STM32CubeProgrammer (Serial). After uploading, move BOOT0 back to 0 and reset. The STM32 will now boot from flash.
Method 3: DFU via USB (After First Flash)
Once you have flashed a USB bootloader (e.g., HID bootloader or Maple DFU), you can upload directly via the USB port without any hardware programmer. Set Upload method → HID Bootloader 2.2 and install the hid-flash utility. This is the most convenient method for ongoing development.
Your First Sketch: Blink and Serial Monitor
The built-in LED is on PC13 and is active LOW (turns on when PC13 is LOW, unlike Arduino’s active-HIGH convention).
// Built-in LED on PC13 (active LOW)
void setup() {
pinMode(PC13, OUTPUT);
Serial.begin(9600); // USART1 or USB depending on upload method
}
void loop() {
digitalWrite(PC13, LOW); // LED ON
Serial.println("LED is ON");
delay(500);
digitalWrite(PC13, HIGH); // LED OFF
Serial.println("LED is OFF");
delay(500);
}
If you are using USB Serial (HID bootloader method), set Tools → USB Support → CDC (generic Serial supersede U(S)ART). This routes Serial over the USB connection, eliminating the need for a UART adapter for Serial Monitor access.
For USART1 hardware serial, use Serial1 (maps to PA9/PA10), not Serial.
Using ADC, PWM, I2C, SPI, and UART
ADC (Analog to Digital Conversion)
The STM32F103C8 has a 12-bit ADC (compared to Arduino Uno’s 10-bit), giving 4096 steps vs 1024. Use analogRead(PA0) just as with Arduino. The default reference is 3.3 V, so full scale is 3.3 V = 4095.
Note: By default the STM32duino core maps analogRead() to 10-bit resolution for Arduino compatibility. To unlock the full 12-bit range, call analogReadResolution(12) in setup().
PWM
Use analogWrite(pin, value) on any PWM-capable pin. STM32F103C8 has 10 timers with up to 17 PWM channels. Default frequency depends on the timer; you can configure it with HardwareTimer for custom frequencies — essential for motor control and audio generation.
I2C
#include <Wire.h>
void setup() {
Wire.begin(); // PB6=SCL, PB7=SDA (I2C1 defaults)
// or Wire.begin(PB9, PB8) for I2C1 remapped
}
All standard I2C sensor libraries (BME280, MPU6050, OLED displays) work without modification.
SPI
#include <SPI.h>
void setup() {
SPI.begin(); // PA5=SCK, PA6=MISO, PA7=MOSI, PA4=SS
}
Common Issues and Fixes
Issue: Upload fails — “Error: libusb_open() failed”
This means STM32CubeProgrammer cannot find the ST-Link. Install the ST-Link USB driver (ST provides a Windows driver installer with CubeProgrammer). On Linux, add udev rules for the ST-Link USB VID/PID.
Issue: Blue Pill has 128 KB flash but board says 64 KB
Many Blue Pill boards actually have the STM32F103C8T6 which officially has 64 KB but physically has 128 KB of flash that works reliably. In Arduino IDE, select Board part number → BluePill F103CB (or C8 with 128k) to unlock the full 128 KB.
Issue: USB not recognized on Windows
Windows requires Zadig to install the WinUSB driver for the STM32 DFU device. Open Zadig, select STM32 BOOTLOADER, and install WinUSB. For HID bootloader, use hid-flash which communicates over HID — no driver change needed.
Issue: millis() drift or incorrect timing
Ensure the Arduino core is using the HSE crystal (8 MHz) rather than the internal HSI oscillator. In Tools → C Runtime Library settings, the crystal source is usually auto-configured by the core for BluePill F103C8.
Frequently Asked Questions
Is the STM32 Blue Pill 5V tolerant?
Most STM32F103C8 I/O pins are 3.3 V. Some pins are explicitly marked as 5V-tolerant in the datasheet (look for “FT” in the pin table). For connecting 5V Arduino shields or sensors directly, add voltage dividers or a logic level converter on non-5V-tolerant pins. Power input via the USB or 5V pin goes through a 3.3 V LDO regulator onboard.
Can I use Arduino libraries designed for Uno on the Blue Pill?
Most libraries work without modification — Wire, SPI, Serial, Servo, and hundreds of sensor/display libraries are compatible with STM32duino. Libraries that directly access AVR registers (PORTD, TCCR2, etc.) will not compile. These are rare in modern well-maintained libraries. Always check the library’s issue tracker for STM32 compatibility notes.
What is the maximum current I can draw from a GPIO pin?
Each STM32F103 GPIO pin can source or sink up to 25 mA. The total current drawn from all GPIO combined should not exceed 150 mA. For driving LEDs, a 220–470 Ω resistor keeps current at a safe 7–15 mA per LED. For motors or high-current loads, always use a transistor or MOSFET driver.
Does the STM32duino core support FreeRTOS?
Yes. You can add the STM32FreeRTOS library from the Library Manager. It provides the FreeRTOS kernel wrapped for the STM32duino environment, allowing multi-tasking with tasks, queues, semaphores, and mutexes — a powerful feature unavailable on 8-bit AVR boards.
How does the Blue Pill compare to the ESP32?
The STM32 Blue Pill excels at deterministic real-time control (PWM, hardware timers, ADC) with very low latency. The ESP32 offers Wi-Fi and Bluetooth but has less deterministic timing due to its RTOS. For wireless IoT projects, choose ESP32. For precision motor control, audio DSP, or CAN bus projects, choose STM32.
Level Up Your Projects with STM32
The STM32 Blue Pill running under the Arduino IDE gives you professional ARM performance at a budget price. Once you get past the initial core setup and upload method configuration, you will find it a dramatically more capable platform for signal processing, motor control, USB devices, and any application that pushes the limits of an 8-bit AVR.
Explore the complete range of microcontroller boards, sensors, and accessories at zbotic.in Arduino & Microcontrollers. Everything for your next project, shipped fast across India.
Add comment