I have bought STM32F103C8T6 aka “Blue-Pill” and ST Link V2 from Aliexpress long time back. I did not get time earlier to explore this MCU. The price of this board is just
1.81$ in case you buy it from Aliexpress.
- ARM® 32-bit Cortex® -M3 CPU Core
72 MHz maximum frequency,1.25 DMIPS/MHz (Dhrystone 2.1) performance at wait state memory access
Single-cycle multiplication and hardware division
64 or 128 Kbytes of Flash memory
20 Kbytes of SRAM
- Clock, reset and supply management
2.0 to 3.6 V application supply and I/Os
POR, PDR, and programmable voltage detector (PVD)
4-to-16 MHz crystal oscillator
Internal 8 MHz factory-trimmed RC
Internal 40 kHz RC
PLL for CPU clock
32 kHz oscillator for RTC with calibration
Sleep, Stop and Standby modes
VBAT supply for RTC and backup registers
- 2 x 12-bit, 1 μs A/D converters (up to 16 channels)
Conversion range: 0 to 3.6 V
Dual-sample and hold capability
7-channel DMA controller
Peripherals supported: timers, ADC, SPIs, I2 Cs and USARTs
- Up to 80 fast I/O ports
26/37/51/80 I/Os, all mappable on 16 external interrupt vectors and almost all 5 V-tolerant
- Debug mode
Serial wire debug (SWD) & JTAG interfaces
- 7 timers
Three 16-bit timers, each with up to 4 IC/OC/PWM or pulse counter and quadrature (incremental) encoder input
16-bit, motor control PWM timer with dead-time generation and emergency stop
2 watchdog timers (Independent and Window)
SysTick timer 24-bit downcounter
- Up to 9 communication interfaces
Up to 2 x I2 C interfaces (SMBus/PMBus)
Up to 3 USARTs (ISO 7816 interface, LIN, IrDA capability, modem control)
Up to 2 SPIs (18 Mbit/s)
CAN interface (2.0B Active)
USB 2.0 full-speed interface
- CRC calculation unit, 96-bit unique ID
For more information, go to STMicroelectronics product page
Install gcc and newlib
Install stlink and openocd
stlink is a tool to download the compiled binary to the microcontroller and OpenOCD is an on-chip debugger. I shall cover OpenOCD in future tutorials.
Libopencm3 is a nice opensource
C library for cortex M0/M1/M3 and other MCUs.
This should compile without any issue.
Write your blink LED sketch
The onboard LED on board is connect at port
gpio_toggle() is the function to toggle the state of GPIOs and we would be using this function to blink the onboard led.
svn command can be used to download complete blink sample code.
You might need to modify the
libopencm3 repo path in
libopencm3-examples-rules.mk. In my case, it is set to
Build the blink program.
Uploading the program
You will need ST Link V2 programmer to upload the code.
You should see GREEN LED blinking.