Arduino goes STM32


You can develop for STM32 using the Arduino IDE. Here are the steps:

What you need:

  • STM32F103C8T6 module (ARM32 Cortex-M3, 72 Mhz, 64K flash, 20K SRAM, 33 I/O pins, 3.3V), you can find cheap modules on eBay
  • Serial-to-USB-module (3.3V level, e.g. CH340)


1. Wire STM32 module and Serial-to-USB module as shown below:

arduino_stm32f103c8t6       arduino_stm32f103c8t6_schematics

2. Download and install Arduino IDE (I did use 1.6.3)
3. Download ‘‘, extract it and copy the folder ‘Arduino_STM32-master’ to your Arduino/hardware folder (C:\Programs\Arduino\hardware).
4. Run Arduino IDE, choose settings:
Board: Generic STM32F103C series
‘Variant: STM32F103C8 (20k RAM, 64k Flash)’
Upload method: Serial
‘Port: <the COM port of your USB-to-serial adapter>’
5. Compile this sketch:

#define pinLED PC13

void setup() {
  pinMode(pinLED, OUTPUT);

void loop() {
  digitalWrite(pinLED, HIGH);
  digitalWrite(pinLED, LOW);
  Serial.println("Hello World");  

6. On the board, set ‘BOOT0‘ to 1 (will boot from system memory which contains an UART to flash uploader). Press RESET button.
7. In the Arduino IDE, choose ‘Upload‘. On the board, the blue LED will start to flash.
8. After upload completed, your sketch will start. If you want your uploaded sketch to boot automatically after next power-on/reset, set ‘BOOT0‘ back to 0 (will boot from program memory). Press RESET button.

Arduino demo code for STM32F103C8T6:

1. SPI interface

#include "SPI.h"

#define pinLED PC13
#define pinRST PB0
#define pinIRQ PB1

#define pinSPI_SS  PA4  
#define pinSPI_CLK PA5
#define pinSPI_MISO PA6
#define pinSPI_MOSI PA7

volatile int irqCounter = 0;
int lastIrqCounter = 0;

void handleIRQ(){

void setup(){  
  pinMode(pinLED, OUTPUT);
  pinMode(pinSPI_SS, OUTPUT);
  pinMode(pinRST, OUTPUT);
  pinMode(pinIRQ, INPUT);  

  attachInterrupt(pinIRQ, handleIRQ, RISING);

  // Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high. 

  digitalWrite(pinRST, LOW);
  digitalWrite(pinRST, HIGH);

void spiTest(){
  unsigned long msg = 0;
  SPI.beginTransaction(SPISettings(16000000L, MSBFIRST, SPI_MODE0));
  digitalWrite(pinSPI_SS, LOW);
  msg = SPI.transfer(0x00);
  msg = (msg << 8) + SPI.transfer(0x00);
  msg = (msg << 8) + SPI.transfer(0x00);
  msg = (msg << 8) + SPI.transfer(0x00);  
  digitalWrite(pinSPI_SS, HIGH);
  Serial.println(msg, HEX);  

void loop(){
  digitalWrite(pinLED, HIGH);
  digitalWrite(pinLED, LOW);
  if (irqCounter != lastIrqCounter){
    lastIrqCounter = irqCounter;

2. I2C interface:

#include <Wire.h>

#define OLED_address  0x3C

int pinSDA = PB4;
int pinSCL = PB5;

TwoWire MyWire(pinSCL, pinSDA);

MyWire.beginTransmission(OLED_address); //start transmission to device 
MyWire.write(0x80);        // send register address
MyWire.write(0);        // send value to write
MyWire.endTransmission(); //end transmission




7 thoughts on “Arduino goes STM32”

  1. LED blinkt nicht

    void loop()
    digitalWrite(pinLED, HIGH);
    digitalWrite(pinLED, LOW);
    Serial.println(“Hello World”);

    delay(1000); // fehlt! PC13


  2. It would be better with example to use USB (as serial device) 🙂

    USBSerial usb;

    void setup() {
    pinMode(pinLED, OUTPUT);

    void loop() {
    digitalWrite(pinLED, HIGH);
    digitalWrite(pinLED, LOW);
    Serial.println(“Hello World”)
    if (usb.isConnected()){
    usb.write(“Hello USB”);

    1. hi
      i want to using stm32f103c8 by arduino
      i uploaded “generic_boot20_pc13.bin” file
      i checked led(pc13) on/off
      but when connect usb cable
      pc didn’t link to stm32f103c8 board
      i did download “install_drivers” in C:\Users\xxx\Documents\Arduino\hardware\Arduino_STM32\drivers\win
      i want tip or solution

  3. Hi Developer,
    my try to program a STN32F103C8-Board with the Arduino-IDE was successful.
    On the other hand to program a STM32F407-Discovery-Board produces many problem at compile-time,
    although I select the necessary menu-item “Board: “STM32 Discovery F407”.
    Has anyone an idea?

Leave a Reply

Your email address will not be published. Required fields are marked *

IMPORTANT! To be able to proceed, please enter the magic word 'andega' so we know hat you are a human)

Enter the magic word:
Please leave these two fields as-is:

A blog on projects with robotics, computer vision, 3D printing, microcontrollers, car diagnostics, localization & mapping, digital filters, LiDAR and more