Building a USB bootloader for an STM32


Kevin Cuzner writes:

As my final installment for the posts about my LED Wristwatch project I wanted to write about the self-programming bootloader I made for an STM32L052 and describe how it works. So far it has shown itself to be fairly robust and I haven’t had to get out my STLink to reprogram the watch for quite some time.
The main object of this bootloader is to facilitate reprogramming of the device without requiring a external programmer.

More details on Projects & Libraries’ homepage.

STM32F103 vs GD32F103 round 4: SPI master


Sjaak writes, “This is part 4 in the series where we compare the STM32F103 with its Chinese counterpart the GD32F103. Both are ARM Cortex M3 microcontrollers which are mostly pin, peripheral and register compatible. Now we compare the SPI master peripheral of both chips.”

More details at

Check out the video after the break. 

STM32F103 vs GD32F103 round 3: UART


Here’s the part 3 of Sjaak’s post comparing the GD32 to the STM32:

Since the GD32F103 can run as fast as 108MHz but has not a proper USB clock divider to provide a 48MHz clock for USB communication we need another way to communicate with the outside world. Since the early days of computing the easiest way to go is a asynchronous serial interface using the UART peripheral. I can try to explain how this protocol works, but here is a better write-up.

If you missed part 1 and part 2, be sure to check it out.

More info at

STM32F103 vs GD32F103 round 2: Blink a LED


A follow-up to the STM32F103 vs GD32F103 round 1- Solderability post, Sjaak writes:

The defacto ‘hello world’ for microcontrollers is blink a LED at a steady rate. This is exactly what I’m going to do today. I made a small 5×5 development board, soldered it up and started programming. In this first example we not gonna use fancy IRQs or timers to blink at a steady rate, but we insert NOPsas delay. This would give an idea of the RAW performance of the chip. The used code is simple; set up the maximum available clock available and then toggle RA0 for ever.

More details at

STM32F103 vs GD32F103 round 1: Solderability


Sjaak writes:

I locked myself into the basement with a couple of PCBs, chips and fresh flux for a couple of days. For the STM32F103 vs GD32F103 challenge I needed to have two identical boards with a different microcontroller. As far as I could judge both chips are legit and not counterfeits as we bought both chips from (different) reputable sellers. The used chips are GD32F103CBT6 and STm32F103CBT7. The STM32F103CBT7 is the industrial rated part of the STM32F103CBT6 and is identical except for the temperature range.

More details at

App note: Watt-hour meter based on the STM32F101 microcontroller


ARM Microcontroller based watt-hour meter implementation from STMicroelectronics. Link here (PDF)

This document describes, in detail, the hardware and software implementation of a watthour meter using the STM32F101 microcontroller. This cost effective watt-hour meter uses shunt with an operational amplifier as a current sensor, an embedded 12-bit ADC for current and voltage measurement, GPIO for LCD management, and a lot of other peripherals for communication, tamper detection, keyboard, and power disconnection. Powerful architecture of the STM32™ microcontroller allows sampling at 1 Msps. The high sampling rate makes it possible to use methods for ADC resolution enhancement.

SMA solar readout


Jean-Claude writes:

This is the first post of a 3-part series about reading out an SMA solar inverter over Bluetooth and displaying some readings every few seconds. Long-time readers may remember the Solar at last weblog post from several years ago and the SMA Relay, based on a JeeNode v6. The Bluetooth readout code was derived from Stuart Pittaway’s Nanode SMA PV Monitor code.
This project is for a friend who’s birthday is coming up shortly, and who has the same SMA 5000TL inverter as I do – although it can probably be used with other models.

Project info at

STM32 and Arduino

STM32 is a family of 32bit microcontrollers manufactured by STMicroelectronics and based on the ARM Cortex M core.

The STM32 family is divided into different lines of microcontrollers (L0-1-4, F0-1-2…) depending on their features and the use they are designed for:


These microcontroller are widely used in the industrial world… for example both Pebble watches and Fitbit bracelets are based on STM32 MCUs.

If you’re interested in quadricopters or drones, you probably have heard or used F1, F3, F4 flight control boards. The board name (“F…”) indicated indeed the STM32 microcontroller they are based on.

Thanks to the work made by the stm32duino community and to the support of ST itself, starting from the past June STM32 microcontrollers can be easily used with the Arduino IDE and it’s also possible to take advantage of most of the libraries available for Arduino.

I decided to buy a minimal development board based on the STM32F103C8T6 microcontroller (these boards are sometimes known as blue pills); let’s see how to use it with Arduino.


Many boards are sold unprogrammed: the first thing to do is therefore to program a bootloader, that is a small program which will allow to upload the “real” program via USB port.

To flash the bootloader, you need an USB -> serial adapter, connected to your dev board as it follows:

  • RX -> A9
  • TX -> A10
  • VCC -> 5V
  • GND -> GND

stm32-18 stm32-19

You have also to enable the programming mode, moving the first jumper (labeled BOOT0) to position 1:


Now you need a software to flash the file with the bootloader into the chip. If you’re under Windows, you can download the Flash Loader from ST’s official website: after having registered (for free) you’ll receive the download link via email.

The bootloader is developed and maintained by Roger Clark and it’s available in his Github repository. For STMF1 boards there are several binary files, depending on the PIN the onboard led is connected to. My board uses P13, so I downloaded the file generic_boot20_pb13.bin.

Run the Demonstrator GUI program and select the serial port your adapter is connected to:


If all the connections are ok, the software should be able to detect the microcontroller:


Now you can select the specific MCU your board uses:


then select the file with the bootloader and program it. To be sure, you can ask the software to perform also a global erase of the memory:


The program will flash the chip and, when complete, will confirm the operation with a message:


If you now move back the BOOT0 jumper to the original position, you should see the led blink: this means that the bootloader is running and can’t find a program to execute… now it’s time to configure the IDE.

Arduino IDE

Open your IDE and select File – Preferences. Type the following address in the Additional Boards Manager URLs field:


Now open the Boards Manager:


Search STM32F1 and install the corresponding Cores package:


You’re almost ready to compile and run your first program…


Connect the dev board to your PC using an USB cable and verify how it is identified.

It may happen that Windows cannot correctly identify the board and displays it as Maple 003, is this case you have to install the correct drivers:


Download the following files from Clark’s repository:

  • install_STM_COM_drivers.bat
  • install_drivers.bat
  • wdi-simple.exe

Run the two .bat:


now Windows should identify the board correctly:


Sometimes Windows cannot see the additional serial port of the board. To solve the problem, you can try to program on the board a simple sketch that uses the Serial object. Open for example the blink sketch and change it as it follows:


Program the sketch choosing BluePill F103C8 as board and STM32duino bootloader as upload method.

Once the sketch is programmed and executed, Windows should detect and install the new COM port:


You’re done, now the board is fully integrated with the Arduino IDE:


Hacking the DPS5005


Johan Kanflo’s OpenDPS project, a free firmware replacement for the DPS5005:

This write up of the OpenDPS project is divided into three parts. Part one (this one) covers reverse engineering the stock firmware and could be of interest for those looking at reverse engineering STM32 devices in general. Part two covers the design of OpenDPS, the name given to the open DPS5005 firmware. Part three covers the upgrade process of stock DPS:es and connecting these to the world. If you only want to upgrade your DPS you may skip directly to part three.

More details at Johan Kanflo’s blog.

BlackMagicProbe SMDprutser style


Sjaak has published a new build:

When you get started on ARM microcontrollers things are very overwhelming at first… After coping with the first few hurdles like installing a toolchain and IDE, the next part should be getting a tool to program the chip. Many vendors have some kind of bootloader burned in the chip, which can’t be altered. Some manufacturers use serial, some use USB (mass-storage, DFU or HID). Unfortunately every vendor has it own implementation and they aren’t compatible with each other and may require special hardware. This can make it hard(er) for you to change between vendors. Another downside is your code can only be debugged by ‘printf” and not ‘realtime’.

More details at