More Than a Hobby..


Using a Generic STM32 Board with Arduino

If you haven't got one already, you can buy one on the oddWires website here. Before we look at how you use one, let's recognize the great work by Roger Clark of Melbourne that has enabled these boards to be used by the Arduino IDE. The two key components are the files necessary to enable the IDE and compile M3 cortex applications in the Arduino environment as well as the boot loader so the USB interface can be used to upload programs to the STM32 board. 

Secondly there's an open forum STM32duino that contains great information for the new or experienced user. 

You will also need a USB to Serial Device like the one here both to download programs if you want to use it without a boot loader or to download a boot loader so you can simply use the USB interface subsequently.

Wiring up the board

Connect the USB to Serial board as follows:

  • Vcc to Vcc
  • GND to GND
  • Rx to A9 
  • Tx to A10

Note the position of the two jumpers on the board:

  • Run mode: Both jumpers at "0"
  • Program Mode: Jumper / Boot 0 (top) at "1"

Software Installation

We assume you have already installed the arduino IDE, if not goto the arduino download page and follow the instructions. Then you need to go to Board Manager under Tools and install the support for SAM boards. 

Download the necessary files as well as the boot loader from the links above. Add a "documents/arduino/hardware/" directory if it does not exists. Extract files into the "hardware" directory and rename them by removing the "-master" from each of the directories. You should now have two directories in the hardware folder:

  • Arduino_STM32
  • STM32duino-bootloader


Loading a Program without Bootloader

1. Download ‘https://github.com/rogerclarkmelbourne/Arduino_STM32‘, extract it and copy the folder ‘Arduino_STM32-master’ to your Arduino/hardware folder (C:\Programs\Arduino\hardware).
2. 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>’
3. Compile this sketch:

#define pinLED PC13

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

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

4. On the board, set ‘BOOT0 jumper‘ to 1 (will boot from system memory which contains an UART to flash uploader). Press RESET button.
5. In the Arduino IDE, choose ‘Upload‘. On the board, the blue LED will start to flash.
6. 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.

Flashing a bootloader 

The simplest method to flash the bootloader onto a generic board is to use a USB to Serial adaptor (e.g. CP2102) attached to Serial 1 PA9 and PA10, and set Boot0 HIGH. Press RESET.

Then flash the boot loader. 

On Mac open a terminal window. On Windows open up a CMD window. Change to the documents/arduino/hardware/Arduino_STM32 directory. This example shows Mac. On Windows, change /dev/cu.SLAB_USBtoUART to the appropriate COM port. This example shows a CP2102 based USB to Serial device (Silicon Labs driver).

./stm32flash -w ../../../../STM32duino-bootloader/STM32F1/binaries/generic_boot20_pa9.bin /dev/cu.SLAB_USBtoUART

Where /dev/cu.SLAB_USBtoUART is the USB port. You will see something like this:

ians-iMac:stm32flash ian$ ./stm32flash -w ../../../../STM32duino-bootloader/STM32F1/binaries/generic_boot20_pa9.bin /dev/cu.SLAB_USBtoUART

stm32flash Arduino_STM32_0.9

Using Parser : Raw BINARY

Interface serial_posix: 57600 8E1

Version : 0x22

Option 1 : 0x00

Option 2 : 0x00

Device ID : 0x0410 (Medium-density)

- RAM : 20KiB (512b reserved by bootloader)

- Flash : 128KiB (sector size: 4x1024)

- Option RAM : 16b

- System RAM : 2KiB

Write to memory

Erasing memory

Wrote address 0x08001ba0 (100.00%) Done.

After the board has been flashed, you can remove the USB to Serial adaptor, set Boot0 to Low, and connect via USB. 

Prior to connecting on Windows, you should also install the windows "driver" stub files, (see /Arduino_ST32/driver/win batch file)

After the drivers are installed... When you connect your generic board; Windows should initially recognise it as a libUSB Maple DFU device, the LED should flash quickly 6 times, After this the bootloader will continue to flash the LED at a slighly slower rate. The slower flashing indicates the bootloader has not found an existing sketch and is waiting for an upload. In the Windows device manager you should see a libUSB Maple DFU device.

On Mac you need to install du-util to see the DFU boot loader on the STM32 board: brew install dfu-util

In the Arduino IDE, select your generic board from the menu, e.g. Generic STM32F103C series, then select STM32duino bootloader from the upload menu.