Getting started with ARM Cortex M3 - Programming STM32F103C8T6 (STM32)

STM32 is a more powerful alternative for an Arduino and has more functionalities. STM32F103C8T6, also know as Blue pill has ARM Cortex M3 core and

  • 32-bit CPU
  • 64KB flash memory
  • 20KB SRAM
  • 2 to 3.6 V I/O
  • 72 MHZ maximum frequency
  • ADC, SPI, I2C, USART, CAN, etc.,
  • 16 external interrupt vectors
  • Serial wire debug (SWD) and JTAG interfaces for debugging
  • Three 16-bit timers
  • Two watchdog timers
More details in datasheet | Reference manual


STM32F103C8T6 comes with an USB interface. The board can be powered through USB but can't be programmed because it doesn't have the USB bootloader.

We can choose how to program and upload the code to STM32 from any of the following (but not limited to this list) IDE and interfaces 

1) Program IDE: 
  1. STCubeIDE
  2. Arduino IDE
  3. KEIL IDE
2) Programming interface:
  1. FTDI 
  2. STLink
  3. USB (only for Arduino IDE with bootloader)
A) FTDI interface: (USB to serial interface)

To upload the code to STM32 using FTDI board, make the connection as in the below picture:


VCC, Gnd, Rx, Tx

If the FTDI chip has a jumper, set the jumper to 3.3V and connect VCC to 3.3V, else use 5V. 

Before uploading the code, switch the upper boot jumper position in STM32 to enter programming mode. After flashing is complete switch the jumper back, to enter operation mode. 

If the program doesn't start, click the reset button.

B) STLink interface: (perform SWD debugging also)

Install STLink device driver
Make the connections as in below picture:

After uploading the code, remove the STLink and use STM32 onboard USB to power the board

For full programming video, click here

While trying to run the program, if you get following error:
STLink couldn't verify ST device

Then, it's probably because the STM32 chip is fake. To upload your program in it, follow this video

C) USB interface (only for Arduino):

  1. Download Maple bootloader for STM32 - USB bootloader
  2. Install STM Flash loader - To Flash the bootloader into STM32 using FTDI / STLink
  3. Install necessary packages in Arduino IDE 
Detailed steps can be found here

D) STCubeIDE: (Compiler + debugger + Cube Programmer)

Install STCubeIDE, which includes HAL driver making it easier for programming STM32. Complete HAL documentation can be found here

Blinking LED program with own header file in KEIL IDE can be found in the next post

For I2C driver program in ATMega328P, see this post

For RTOS in STM32, see this post

Connecting Bluetooth with STM32 - post

Comments