STM32 boards – Part 1: Overview and Upload

About this Post

In this and the following article, I will focus on boards based on STM32 microcontrollers. In this first part, I will first give you a brief overview and then show you how to upload your sketches to the STM32 boards using the Arduino IDE.

While uploading to the official STM32 Nucleo and Arduino boards is generally easy, the unofficial variants such as the “Blue Pill” or the “Black Pill” have their own peculiarities. This is why these boards receive a disproportionate amount of attention in this article. Although there are already heaps of articles on the net, few of them take a comprehensive look at the STM32 boards.  

One more note in advance: In the article I stick to the Arduino convention that flashing a microcontroller is an upload. It’s all a question of perspective – in the ST world, this is a download.  

This is what you can expect:

What I will not go into: STM32CubeIDE / STM32CubeMX

STM32CubeMX is a graphical configuration tool for STM32 microcontrollers that can be used to set pins, peripherals and clock systems. It automatically generates initialization code based on the STM32Cube HAL library. STM32CubeIDE is a free development environment from ST based on Eclipse. It integrates editor, compiler, debugger and STM32CubeMX in a single tool. This allows STM32 projects to be fully implemented from configuration to debugging.

I won ‘t go into these tools in this article. Maybe I’ll do a separate post on this at some point.  

STM32 boards – Overview

“STM” stands for the semiconductor electronics manufacturer STMicroelectronics (abbreviation: “ST”). Among other things, ST develops and produces 8- and 32-bit microcontrollers, which are used on hundreds of different boards. I will only discuss a selection of 32-bit variants here.   

STM32 microcontrollers are based on the ARM architecture. The ARM architecture was developed by ARM Ltd. Microcontroller manufacturers such as ST use the architecture as licensees.  

ST itself uses its microcontrollers on the Nucleo development boards, discovery kits and evaluation boards. Arduino also has a number of boards based on STM32 MCUs, such as the Portenta series or the Arduino GIGA R1 WiFi board. There are also many other electronics suppliers who have their own STM32 boards in their range, such as Adafruit with its Adafruit STM32F405 Feather Express.  

The blue or the black pill?

And then there is the large group of BluePill and BlackPill boards. They are extremely inexpensive but not clearly defined, as their designations are not protected brand names but nicknames assigned by the STM32 community.

Under the names “BluePill” and “BlackPill”, you can buy boards in different versions and with different microcontrollers. One major problem is the large number of counterfeit STM32 microcontrollers. On the one hand, these are not always clearly recognizable as counterfeits, and on the other hand, they sometimes have properties that differ from the original. In addition, there are also incorrectly assembled boards.

A few examples of STM32 boards

STM32 boards - Nucleo-L412KB
Nucleo-L412KB
STM32 boards - Nucleo-F446RE
Nucleo-F446RE
STM32 boards - BluePill
BluePill
STM32 boards - Arduino GIGA R1 WiFi
Arduino GIGA R1 WiFi
STM32-Boards - STM32F103Cx Demo Board
STM32F103Cx Demo Board
STM32 boards - BlackPill
BlackPill

The following table lists selected features of some STM32 boards. This is merely intended to give a certain impression of the league we are playing in here.  

Selected features of some STM32 boards
Selected features of some STM32 boards

Nomenclature of STM32 microcontrollers

There are certain rules for the designation of STM32 microcontrollers, but unfortunately the nomenclature is not consistent across the entire portfolio. This means that certain codes can have a different meaning in different series. However, the designation of the microcontrollers follows a certain pattern; here, as an example, the STM32F103C8T6:

Name coding STM32 - Type

The first capital letter indicates the Type:

  • F = Mainstream / Foundation
  • G = General Purpose
  • H = High Performance
  • L / U = Low Power / Ultra Low Power
  • W = Wireless

The following number codes the ARM Cortex used:

Name coding STM32 - Core
Core coding

This is followed by the productline. For example, F103 stands for the Performance Line, F100 is the Value Line. These numbers do not directly encode technical properties.  

The number of pins (No of Pins) is usually defined as follows: 

Name coding STM32 - Number of pins
Coding of the number of pins

Here is the size of the flash (Flash Size):

Name coding STM32 - Flash Size
Flash size coding

You will come across the following codes for the package:

Name coding STM32 - Package
Coding of the package

And the following applies to the operating temperature limits (T-range):

  • 6: -40 to +85 °C
  • 8: -40 to +105 °C

However, as mentioned above, the designations are not always consistent. Take a look at the data sheet or the product descriptions before you order anything!  

Preparations

Installing board package

The board package I am using is Arduino_Core_STM32 from stm32duino. I chose it because it supports some unofficial boards as well as many Nucleo boards. For the current release, you must use the Arduino IDE 2.x or go back to an older version of the board package (< 2.8.0).

To install, first enter the following board administrator URL under File → Settings → “Additional boards manager URLs”:

https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json

Then go to the boards manager and enter STM32 as the search term. You will find the package under the name STM32 MCU based Boards. Click on “Install”.

Is this installation description too short for you? Then you will find detailed instructions with pictures here.  

Alternative board package: STM32F1XX/GD32F1XX

With STM32F1XX/GD32F1XX there is another, quite common board package, which is now outdated. You can find it here on GitHub under the name Arduino_STM32. As the name STM32F1XX/GD32F1XX suggests, the package only supports some of the STM32 boards, but some additional boards with microcontrollers from Giga Device. It is also characterized by lean code and broad community support.  

Optional: Installing STMCubeProgrammer

You can download STMCubeProgrammer here for free. Among other things, it allows you:

  • Flashing a bootloader.
  • Getting information about your STM32 chip.
  • Reading the flash and writing to it.
  • Setting up write protection.
  • Making certain settings, e.g. for the watchdog.
  • Reading registers.

You can also use your STM32 boards without this program. However, I recommend it, especially if you do a lot with the BluePill.  

STM32CubeProgrammer - Program Surface
STM32CubeProgrammer

BluePill board variants

STMF103C8T6- and STM32F103CB-based BluePill boards

In most cases, your BluePill boards will be the version with the STMF103C8T6, which should originally have a flash of 64 kB. There is also a version with 128 kB RAM (F103CBT6). However, many F103C8T6 chips actually have 128 kB flash. You can find out how much flash your board has in the appendix. F103C8T6 chips with 128 kB can be fake, but they don’t have to be, as ST sometimes uses higher-quality chips for logistical reasons.  

There are also variants with microcontrollers from Giga Device, such as the GD32F103xx family.

STM32F103C6T6-based BluePill boards

With 32 kB flash, 10 kB RAM and fewer interfaces, the STM32F103C6T6 is the little brother of the STM32F103C8T6. Apart from the different microcontroller, the boards assembled with the “C6T6” usually have the same design.

What didn’t work for me with these boards was uploading sketches via HID bootloader over USB (more on this below). Otherwise, they did what they were supposed to do. However, I did not test these boards intensively.

In two out of four orders from different stores, I received the big brother instead of the STM32F103C6T6 variant without comment.   

BluePill boards with counterfeit chips

As already mentioned, BluePill boards with counterfeit chips, especially with alleged STM32F103C8T6 microcontrollers, are widespread. Most counterfeits work in principle, but there are deviations in the details. For example, there are reports of excessive power consumption, as some fake chips ignore low power functions. Others report general instability. The HID bootloader also does not work with many fake chips. Further indications of fakes are

  • Chip labeling that is only printed on and not lasered in. The laser engraving should be visible.
  • Obviously wrong ST logo.

I received a BluePill version, which according to the (printed) label is equipped with an STMF103C8T6, but even has a flash of 256 kB. 

BluePill boards with wrong parts

Then there are BluePill boards with a false pull-up resistor for the D+ line of the USB connection. You will find the resistor on the back of the board, labeled as R10. This resistor should have a size of 1.5 kΩ (label: 152); instead, you can probably also find R10 resistors with 10 kΩ (label: 103). However, none have come between my fingers. A hardware solution for the associated problems can be found here; a software solution can be found here.  

Uploading sketches to the BluePill board

Although the BluePill board has a USB port, it cannot be programmed via USB without further precautions. I will show you several methods for uploading programs.

Uploading via USB-to-TTL adapter

Connection

For this method, you need a USB-to-TTL or FTDI adapter. It is best to use a model that can be switched to 3.3 volts. Connect the adapter to the BluePill board as follows:

BluePill with FTDI adapter
Programming BluePill with USB-to-TTL adapter

A9 is TXD1, A10 is RXD1. 

As most of the pins on the BluePill boards are 5V-tolerant (as input!), you could also work with five volts here. But since this does not apply to all pins and also not to pins in ADC mode, I would advise you to generally work with 3.3 volts so that you don’t forget it at some point.  

Settings in the Arduino IDE

In the Arduino IDE, choose your board under “Tools”: “STM32 MCU based boards” → “Generic STM32F1 series”. Then set the correct version under “Board part number”:

BluePill selection in Arduino IDE
BluePill selection in Arduino IDE

Select the port to which your USB-to-TTL adapter is connected and set the following as the “Upload Method”: 

  • Upload method: STM32CubeProgrammer (Serial)

If you want to use the serial monitor, there are two options: 

  1. U(S)ART support: Enabled (generic ‘Serial’). 
    • Serial monitor is connected via the USB-to-TTL adapter.
  2. USB support (if available): “CDC (generic ‘Serial’ supersede U(S)ART)”
    • Serial monitor is connected via the USB port of the BluePill board.
    • The USB connection appears as a separate port. 

If you set 1 and 2 as specified above, setting 2 will “override” setting 1.

Otherwise, leave the settings unchanged:

BluePill - Settings in the Arduino IDE
Settings in the Arduino IDE

Settings on the board

To upload sketches to the BluePill board via serial, you must set it to programming mode. To do this, set the BOOT0 jumper to 1 and leave the BOOT1 jumper at 0. Then press the reset button.

More precisely, the above setting leads to the “System Memory Boot Mode”. This means that the boot process starts in the system memory. The STM32F1x microcontroller has a hardware bootloader there.

In the BOOT0 = 0 position, the STM32F1x is in “Main Flash Memory Boot Mode”. This means that the boot process starts in the flash memory where your uploaded program is saved to.  

BluePill - BOOTx Jumper
Boot Mode – left: System Memory, right: Main Flash Memory

Uploading an example sketch

Once you have made all the settings, upload your first sketch using the “upload arrow”. You could use the following example to test the serial monitor:

void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);                    
  digitalWrite(LED_BUILTIN, LOW); 
  delay(1000);                     
  Serial.println("Hello World");
}

The sketch starts immediately after uploading. A new reset leads back to programming mode. To prevent this, set the BOOT0 jumper back to 0.

Uploading via SWD (Serial Wire Debug)

Serial Wire Debug is an ARM-specific communication interface based on JTAG (Joint Test Action Group). In contrast to JTAG, SWD requires only one data line (SWDIO) and one clock line (SW(D)CLK).

To be able to use SWD, you need an ST-LINK or a J-Link programmer (from SEGGER Microcontroller), whereby the J-Link programmer is more of a professional device. There are also various SWD programmers that are advertised as “ST_LINK compatible”.

Uploading with ST-LINK/V2 Mini

The ST-LINK/V2 Mini is probably the most cost-effective SWD programmer with a price of < 10 euros. The “Mini” is usually omitted.  

ST_LINK/V2 Mini
ST_LINK/V2 Mini

The programmer has a USB-A connector under the protective cap on one side and a 10-pin socket on the other. You connect the ST-LINK/V2 to your BluePill board as follows:

BluePill - ST-Link/V2 Connection
Programming BluePill with ST-Link/V2

Make sure that you do not connect the 3.3V pin of the BluePill board to the 5.0V pin of the programmer. 

You can leave the BOOTx jumpers on the BluePill board in the zero position when programming via SWD. In the Arduino IDE, select the upload method:

  • Upload method: “STM32CubeProgrammer (SWD)”

You cannot establish a connection to the serial monitor via the SWD pins (with the ST-LINK/V2). Instead, you can use the USB port for this purpose. To do this, select in the settings:

  • USB support (if available): CDC (generic ‘Serial’ supersede U(S)ART) 

Alternatively, you could also use a USB-to-TTL adapter, but then without the USB support. 

The “big” ST-LINK/V2

ST-LINK/V2

The “actual” ST-LINK/V2 is larger. It is connected to the computer via a USB micro-connector. The 4-pin socket in the middle is an interface for STM8 microcontrollers. The 20-pin socket allows connection to STM32 microcontrollers via SWD or JTAG.

If you have boards with a 20-pin socket or you want to program via JTAG, then choosing this programmer makes sense. For most people, the “mini” version will be sufficient.

Finally, there is the ST-LINK/V2-ISOL version, which provides electrical isolation from the microcontroller. 

Only 2 of the pins plus the power supply are required for the SWD connection. You have to be a little careful not to miscount and use the wrong pins.   

SWD pins of the 20-pin socket of the ST-LINK/V2

Easiest: Uploading via HID bootloader and USB

The fiddling with the jumpers when flashing via serial can be annoying. Connecting an STM32 board to an ST-LINK/V2 (Mini) is also inconvenient (although you should always know how well off you are if you count that as one of your problems 😉 ).

It would be more convenient if you could upload your sketches just via USB. This is actually possible by flashing a suitable bootloader. We use an HID bootloader, which is so called because it communicates according to the HID (Human Interface Device) protocol. The HID protocol was developed for USB devices such as keyboards and mice. The great thing about it is that you don’t need to install a driver.

First, it should be said that this did not work for me with all BluePill boards, although the non-functioning ones were visually identical to the functioning boards, including the resistor values. I have not found out the reason yet.

Variant 1: Flashing the HID bootloader via serial

There are already a number of instructions on how to upload the bootloader to the BluePill board. You can find a detailed YouTube video here and instructions with many pictures here. And here is my own quick guide:

  1. Download the bootloader package stm32_binaries.zip from here and unzip it.
    • For the BluePill board, hid_generic_pc13.bin is the right choice. “pc13” stands for the pin that is connected to the board LED. You can find the bootloader under …\stm32_binaries\stm32_binaries\F103\low_and_medium_density.  
  2. Connect the BluePill board to the PC via a USB-to-TTL adapter as shown above. 
  3. Set the Boot0 jumper to 1 and reset the board.
  4. Open STMCubeProgrammer. On the right-hand side, select UART and set the port to which the USB-to-TTL adapter is connected. Then click on “Connect”.  
STMCubeProgrammer - Flashing the bootloader
STMCubeProgrammer – Flashing the bootloader
  1. On the left-hand side of STMCubeProgrammer, go to “Erasing & Programming”. 
  2. Enter the path to hid_generic_pc13.bin in “File path”. “Start address” is 0x08000000.
  3. Click on “Start Programming”.  Confirm the success message with OK and click on “Disconnect”, but leave the board connected to the power supply. 
  4. Set the Boot0 jumper to 0 and reset the board. Now you can disconnect the USB-to-TTL adapter from the board. However, it will not interfere if you leave it connected.
  5. Connect the board to the PC via USB. 
  6. In the Arduino IDE you set:
    • Upload Method: “HID Bootloader 2.2”.
    • USB Support (if available): “CDC (generic ‘Serial’ supersede U(S)ART)”.
    • U(S)ART support: “Enabled (generic ‘Serial’)”. However, this is not actually relevant.
      • You don’t see a port yet. That is OK.
  7. Upload a sketch. Now you can find the board under “Port” and can also use the serial monitor.  

Please let me know if any points are missing or misunderstood in these instructions. 

Variant 2 – Flashing the HID bootloader via ST-LINK/V2

If you want to flash the bootloader to the BluePill board via ST-LINK V2, there are only minor differences in the procedure:

  • Connect the ST-LINK/V2 to the BluePill board and the PC.
  • In STMCubeProgrammer, select ST-LINK instead of UART.
  • You can leave the jumpers on the BluePill in the zero position. 

Deleting the HID bootloader

If you flash sketches to your board via SWD or serial, the HID bootloader will be overwritten. This is the easiest way to get rid of the bootloader. Or you can delete the bootloader using the “Erase flash memory” function in STMCubeProgrammer. However, this only worked – at least for me – via the ST-LINK/V2, but not via Serial.

Uploading via Maple-DFU-Bootloader

I do not recommend this method because, unlike uploading via HID bootloader, you will need to install additional drivers. I am only introducing it here for the sake of completeness. By the way, DFU stands for Device Firmware Upgrade.

Here are the brief instructions:

  • Download the correct bootloader from STM32duino-bootloader. In most cases this should be generic_boot20_pc13.bin. You can find it here in the binaries directory. Double-click the file, go to the download icon, and save the file where you find it.  
  • Upload the bootloader with STM32CubeProgrammer onto your BluePill board. You do this as described above for the HID bootloader.  
  • Download the Arduino_STM32 package here. To do this, click on the green “Code” button, then on “Download ZIP”. Unzip the package (somewhere).  
  • Go to the drivers/win directory and execute install_drivers.bat. This will install the Maple drivers.
  • Connect the board to the PC via USB. BOOT0 and BOOT1 shall be set to 0.
  • In the Arduino IDE, select the correct board:
    • Select the correct port (not the one under “dfu Ports”, if something appears there).
    • Upload method: “Maple DFU Bootloader 2.0”.
    • USB support: “CDC (generic ‘Serial’ supersede U(S)ART)”.
  • Upload your sketch. You will probably get an error message at the end that the port you have set is not available. Change it. You can then upload new sketches without any further settings.

As already mentioned, I see no advantage of the Maple DFU bootloader over the HID bootloader. I was able to program the BluePill boards that could not be programmed with the HID bootloader exactly once using the Maple DFU bootloader. On the next upload, the Arduino IDE did not find the port. So no improvement here either.  

BlackPill variants

The name “BlackPill” is just as unprotected as “BluePill”. When people talk about “BlackPill”, they usually mean the design by WeAct Studio (WeAct for short). There is very little information about WeAct itself on the internet. Links to the company are classified as unsafe by Edge and Firefox. WeAct’s GitHub page and the WeAct Studio Shop on AliExpress give an impression of what WeAct does.  

The “WeAct-BlackPill” is based on the STM32F401CCU6 or the STM32F411CEU6. In addition to its black design, its three buttons “NRST,” “BOOT0,” and “KEY” are particularly striking.

BlackPill board
BlackPill with STM32F401CCU6 MCU

But, as previously mentioned, the name “BlackPill” is not protected, which is why you will come across many other variants. For example, there is an STM32F103C8T6-based model here. The model shown below, based on the STM32F401RCT6, is somewhat bizarre. Due to the unfortunate spacing of the pin headers, it does not fit on breadboards:

STM32F401RCT6-based BlackPill
STM32F401RCT6 BlackPill, fixed on one side

Otherwise the board worked (board part number: “Generic F401RCTx”).

Uploading sketches to the BlackPill board

Uploading via DFU and USB

You can program the BlackPill conveniently via USB, as you do not need to flash an additional bootloader. First, set the correct board in the Arduino IDE: STM32 MCU based boards → Generic STM32F4 series. Then select the correct variant, e.g. BlackPill 411CE.  

Select “STMCubeProgrammer (DFU)” as the upload method. If you want to access the serial monitor via USB, select “CDC (generic ‘Serial’ supersede U(S)ART)” as USB support.  

Setting example for the BlackPill
Setting example for the BlackPill

To enter “DFU mode”, do the following:

  • Press and hold the BOOT0 button.
  • In the meantime, briefly press the NRST button.
  • After 1 to 2 seconds, release the BOOT0 button. 

An entry in the category “dfu Ports” should appear in the ports. Select the port and upload your sketch.  

Under Ports, the “dfu Port” should now have disappeared. If you have opted for USB support, you should see a new port. To upload further sketches, repeat the procedure with the BOOT0 and NRST buttons and set the DFU port again.  

Unfortunately, switching to DFU mode does not always work. Windows will then display a message that the USB device was not recognized. Repeat the process until it works. Sometimes it helps to disconnect the USB cable briefly. Also, in my experience, short USB cables seem to work better than long ones.    

Uploading via serial or SWD

The upload via serial using an USB-to-TTL adapter works in the same way as with the BluePill, except that you do not move any jumpers but instead press the NRST button while holding down the BOOT0 button, as with the DFU method. Select the port of the USB-to-TTL adapter and set “STM32CubeProgrammer (Serial)” as the upload method.  

The upload via SWD using the ST-LINK/V2 works in the same way as with the BluePill, so I can save myself further explanations.  

Not Arduino-compatible: WeAct HID bootloader

If you are annoyed by pressing the NRST and BOOT0 buttons, you may be wondering whether there is an HID bootloader solution for the BlackPill board. First of all: to my knowledge, there is no really working solution, at least not for users of the Arduino IDE. Nevertheless, I would like to share my experiences.

The bootloader WeAct_HID_Bootloader_F4x1 is pre-installed on brand new WeAct BlackPill boards. When uploading sketches via DFU, SWD or serial, you overwrite it. It is also available here on GitHub. However, the bootloader is not available there as a finished bin file; instead, you have to create it first. How to do this is discussed here. One of the participants has made the final bin file available here.  

After unzipping, the file WeAct_HID_Bootloader_F4x1.bin can be loaded onto the BlackPill board with STM32CubeProgrammer. If you reset the board while pressing the KEY button, you will enter bootloader mode. However, the upload does not work with the Arduino IDE and the upload option “HID Bootloader 2.2”.

Out of curiosity, I tried the command line tool WeAct_HID_Flash-CLI.exe following these instructions. Despite a promising “Flash done!”, the sketch did not seem to have arrived on the board!

If you know a working solution (for the Arduino IDE), please shar with me!

Using the KEY button for other purposes

Even without a WeAct bootloader, the KEY button is not completely useless. PA0 is connected to GND via the KEY button. This means you can use the KEY button to trigger any actions. You can test this with the following small sketch.  

void setup() {
  Serial.begin(115200);
  pinMode(PA0, INPUT_PULLUP);
}

void loop() {
  if(!digitalRead(PA0)){ // KEY pressed
    Serial.println("KEY!");
    pinMode(LED_BUILTIN, OUTPUT); // LED on
    delay(1000); 
    pinMode(LED_BUILTIN, INPUT);  // LED off        
  }
}

Here you can also see that the board LED is connected to VCC via a resistor. On the other side, it is connected to PC13. This is why the LED lights up when PC13 is OUTPUT/LOW.  

Uploading sketches to Nucleo boards

The Nucleo boards have an integrated ST-LINK/V2 programmer. This makes program uploads via USB connection child’s play. That’s almost boring after all the challenges of the Blue- and BlackPill!

First select the board family, i.e. Nucleo-32, -64 or -144, and then the correct model (“Board part number”). Here are the other settings:

Nucleo-Board Settings
Nucleo-Board Settings

Special features of the on-board ST-LINK/V2

The ST-LINK/V2 installed on the Nucleo boards is a newer version (ST-LINK/V2-1 or higher). Two features are important here:  

  • The emulation of a USB mass storage device.
  • A “virtual COM port”, i.e. a type of integrated USB-to-TTL adapter.

The former causes the board to register as a USB mass storage device on the PC, i.e. like a USB stick or a USB hard disk. If you display your drives on the PC, the Nucleo board will appear there, e.g. the Nucleo-L432KC board as “Node-L432KC”. With the “Mass Storage” upload method, your sketch will then be copied to the board like to a drive.  

The virtual COM port is already noticeable in the Arduino IDE in that a port is always displayed when the board is connected. This was different with the Blue- and BlackPills. The virtual COM port allows you to use serial via the USB port without having to activate USB support in the settings (if you do so anyway, the serial output will not work!). On the other hand, you must activate U(S)ART support if you want to use serial.  

Since the on-board ST_LINK/V2 still supports SWD, you can alternatively select “STM32CubeProgrammer (SWD)” as the upload method. With the Nucleo-L412KB you even have to choose this method, although this board is also recognized as a USB mass storage device. This is because it is not “Arm® Mbed Enabled™”. Confusing!  

And what is the purpose of the jumper connecting D2 and GND?

Anyone who buys a Nucleo 32 board is probably wondering what the jumper on the pin header that connects pin D2 to GND is for. On virgin Nucleo-32 boards there is a demo program that makes the green LED flash. If you remove the jumper, the flashing frequency changes. I don’t know the meaning of this. You can simply remove the jumper.  

Upload sketches to the Arduino GIGA R1 WiFi board

Like all official Arduino boards, the Arduino GIGA R1 WiFi has its own Arduino board package, namely “Arduino Mbed OS Giga boards”. You install it via the boards manager. As it is an Arduino-specific package, you do not need an additional board manager URL. You connect the board to the PC via the USB-C port, select the board and the correct port in the Arduino IDE and get started. It’s as simple as that.

In this case, the upload is controlled via a pre-installed software bootloader. If you need to reinstall it, you can put the board into DFU mode using the BOOT0 and RST buttons and flash the bootloader. Follow these instructions.  

Appendix 1 – Checking the real flash size

You can check the size of the flash memory with STMCubeProgrammer. How to install the program and connect it to your board is described in the article. In the “Target information” section you will find the entry “Flash size”. However, the information is not reliable. For example, I had a BluePill board that displayed 128 kB when connected via serial, but 64 kB when connected via ST-LINK (see below). Using this example, I would like to demonstrate with two small tests how you can check the actual available flash.

The simple variant is that you try to read the memory beyond 64 kB, i.e. from address 0x08010000. To do this, go to the “Memory & File Editing” area, enter 0x08010000 as the address, set the “Size” to 0x10000 (= 65536) and then click on “Read”.  

STM32 boards - flash read above 64 KB
Reading the flash beyond 64 kB

The success message shows that the memory area between 64 and 128 KB can be read. If this should not work, you will receive the error message “Data read failed”.

As a second test, we will attempt to write (even if this is no longer actually necessary). If you want to reproduce this, download the file ascii_repeat_64kb.bin here (click on the file, then on the download symbol). It is exactly 64 kB in size and contains 256 times the extended ASCII table with 256 characters. Upload the file content, starting at the start address 0x08010000 (i.e. at 64 KB). Activate “Verify program”. If everything goes well, you will receive the message “Download verified successfully”. In the event of an error, the message will read: “failed to download the file”.

STM32-Boards - Flash Write Test above 64 KB
STM32 Flash Write Test above 64 KB

You can read the flash content via “Memory & File Editing”. If you select 8-bit as “Data width” and then click on “Read” again, it should look like this:

STM32-Boards Flash Size Test - reading the written flash
STM32 Flash Size Test – reading the written flash

2 thoughts on “STM32 boards – Part 1: Overview and Upload

  1. Wolfgang, As always, you write great articles. I have used the STM processors in the past for systems that have not need to connect to wifi, bluetooth, etc. Now though, I find myself using Espressif processors (ESP32) almost exclusively. They offer of course wifi on every chip and commonly available versions can offer upto 16M of flash and 8M of RAM. I would be great if you could position the STM processors vs the ESP processors to provide guidance on when/why one might select one family vs the other.

    1. Hi Pete, thanks for your comment! I am still exploring the STM32 boards, hence it’s maybe a little too early for me to conclude. But currently I am also in favour of the ESP32. Both the ESP32 and STM32 can be programmed quite easily with the Arduino functions. But if you want to go beyond, e.g. use PWM or timer interrupts, the ESP-IDF seems to be much simpler than the STM32 HAL. There are these extra tools STM32CubeMX and STM32CubeIDE which shall make programming easier but I am not yet sure if I want to dive into that. Let’s see.

Leave a Reply

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