STM32 - Beginner microcontroller

Ad Code

STM32 - Beginner microcontroller

The STM32 microcontroller is a popular and highly demanded platform that allows you to create professional solutions for automation in a wide variety of areas . Unlike the available Arduino, the STM32 requires a deeper dive into the details, it is more difficult for beginners, there are fewer textbooks in Russian for it. In this article we will try to give basic information about the platform, its history, show you where you can download programs and libraries, how to write the first sketch.

Contents hide ]

  • 1 What is STM32
    • 1.1 History of appearance
    • 1.2 Pros and cons of STM32
  • 2 Comparison of STM32 with Arduino
  • 3 Overview of product lines
  • 4 Software for working with the controller
  • 5 STM32 Discovery
  • 6 What is required to connect STM32 to a computer
  • 7 First program

What is STM32

STM32 is a platform based on STMicroelectronics microcontrollers based on an ARM processor, various modules and peripherals, as well as software solutions (IDE) for working with hardware. Solutions based on stm are actively used due to the performance of the microcontroller, its successful architecture, low power consumption, and low price. Currently, STM32 already consists of several lines for a variety of purposes.

History of appearance

The STM32 series was released in 2010. Before that, STMicroelectronics had already produced 4 families of ARM-based microcontrollers, but they were inferior in their characteristics. STM32 controllers turned out to be optimal in terms of properties and price. Initially, they were produced in 14 variants, which were divided into 2 groups - with a clock frequency of up to 2 MHz and a frequency of up to 36 MHz. The software for both groups is the same, as is the arrangement of the contacts. The first products were manufactured with built-in 128KB flash memory and 20KB RAM. Now the line has expanded significantly, new representatives have appeared with increased values ​​of RAM and Flash memory.

Pros and cons of STM32

Main advantages:

  • Low cost;
  • The convenience of use;
  • Large selection of development environments;
  • Chips are interchangeable - if the resources of one microcontroller are not enough, it can be replaced with a more powerful one without changing the circuit itself and the board;
  • High performance;
  • Convenient debugging of the microcontroller.


  • High threshold of entry;
  • There is not much literature on STM32 at the moment;
  • Most of the libraries created are already outdated, it is easier to create your own.

The disadvantages of STM32 do not yet allow the microcontroller to become a replacement for Arduino.

Comparing STM32 to Arduino

Comparing STM32 to Arduino
Comparing STM32 to Arduino

In terms of technical characteristics, Arduino loses to STM32. The clock frequency of Arduino microcontrollers is lower - 16 MHz versus 72 MHz STM32. The number of GRIO pins in STM32 is larger. The memory capacity of the STM32 is also higher. It is impossible not to note the pin-to-pin compatibility of STM32 - you do not need to change the board to replace one product with another. But competitors cannot completely replace arduino. This is primarily due to the high entry threshold - to work with STM32, you need to have a basis. Arduino boards are more common, and if the user has a problem, you can find a solution on the forums. Also, various shields and modules have been created for Arduino, expanding the functionality. Despite the advantages, STM32 wins in terms of price / quality ratio.

The STM32 family of microcontrollers differs from its competitors in excellent behavior at temperatures from -40C to +80 C. High performance does not decrease, unlike Arduino. You can also find products that work at temperatures up to 105C.

Overview of product lines


The STM32 family has a wide range of products that differ in memory size, performance, power consumption and other characteristics.

STM32F-1, STM32F-2 and STM32L series are fully compatible. Each of the series has dozens of microcircuits that can be easily exchanged for other products. The STM32F-1 was the first line, its performance was limited. Because of this, in terms of characteristics, the controllers quickly caught up with the products of the Stellaris and LPC17 families. Later, the STM32F-2 was released with improved characteristics - the clock frequency reached 120 MHz. It features high processing power, which is achieved thanks to the new 90 nm production technology. The STM32L line is represented by models that are manufactured according to a special technological process. Leakage from transistors is minimal due to which the instruments show the best values.

It is important to note that STM32W line controllers do not have pin-to-pin compatibility with STM32F-1, STM32F-2 and STM32L. The reason is that the line was developed by the company that provided the RF part. This placed development constraints for ST.


The STM32F100R4 microcircuit has a minimal set of functions. Flash memory is 16 KB, RAM - 4K, clock speed is 12 MHz. If you need a faster device with more flash memory up to 128KB, the STM32F101RB will do. The USB interface is available for the STM32F103RE product. There is a similar device, but with lower power consumption - this is the STM32L151RB.

Controller software

Keil uvision 4
Keil uvision 4

Many development environments have been developed for the ARM architecture. The most famous and expensive tools are Keil and IAR System. The programs of these companies offer the most advanced toolkits for code optimization. Also, there are additionally various systems - USB stacks, TCP / IP stacks and others. By using Keil systems, the user receives a good level of technical support.

Also for STM32, the Eclipse development environment and the Atollic TrueStudio (paid) and CooCox IDE (CoIDE) (free) systems built on it are used. The latter is usually used. Its advantages over other development environments:

  • Free software;
  • The convenience of use;
  • There are many examples available for download.

The only drawback of the CooCox IDE is that the assembly is available only for Windows.

STM32 Discovery

STM32 Discovery
STM32 Discovery

It's better to start learning the STM32 microcontroller from the Discovery board. This is due to the fact that this board has a built-in programmer. It can be connected to a computer via a USB cable and used both as a programmable microcontroller and for external devices. The Discovery board has a full pinout from the controller to the pins of the board. Various sensors, microphones and other peripheral devices can be connected to the board.

What is required to connect STM32 to a computer

To get started, you need the following components:

  • The STM32 Discovery board itself;
  • Datasheet for the selected model;
  • Reference manual for the microcontroller;
  • The development environment installed on the computer.

As an example, the first program will be considered in the CooCox IDE.

First program

CooCox IDE
CooCox CoIDE

Learning should start with the simplest - Hello World. First you need to install CooCox IDE on your computer. Installation is standard:

  • The program is downloaded from the official site;
  • There you need to enter your email address and start downloading the file with the .exe extension;
  • Open the CooCox IDE Project tab, Select Toolchain Path;
  • Specify the path to the file;
  • Open the development environment again and click View -> Configuration on the Debugger tab;
  • Now you can record your program.

When the program is installed, you need to open it. Go to the Browse in Repository tab and select ST - your microcontroller.

Next, a list of libraries that can be connected will appear on the screen. The first program will require the system CMSIS core and CMSIS Boot, a library for working with the RCC clock system, GPIO for working with pins.

The program itself is written as for Arduino, you need to know the basics of the C language.

In the Project window, open main.c. In the code at the very beginning, you should connect libraries other than CMSIS (they are already automatically connected). They are added as follows:

#include "stm32f10x_gpio.h"

#include "stm32f10x_rcc.h".

// To blink the LED, you need to set the delay:

void Delay (int i) {

for (; i! = 0; i--);


Then we add the clocking of the port in the main function main. Which contact is responsible for what can be viewed in the datasheet for the microcontroller.

RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOC, ENABLE);

To configure the parameters of the pins, you should write down its name and put a full stop. The pop-up menu will show all the characteristics. They can be corrected.

After that, you need to loop in while so that the LED blinks until the power is turned off.

Once the program is written, it can be loaded into the controller. If you have a debug board, you need to connect it via a USB cable and click Download Code To Flash. If the board is missing, an adapter is required, which must be connected to the computer port. The BOOT 0 contact is connected to the plus of the controller's power supply, and then the MK power itself is turned on. After that, the firmware will start.

To download the program to the microcontroller, you need to follow the instructions from the application. First, the code of the port to which the microcontroller is connected is written. The speed is also indicated. It is advised to take a small value so that there are no failures. The program will find the microcontroller, and you will need to press the "next" button. In the Download to device tab, select the written program in the Download from file field and click "next".

After that, you need to turn off the power to the STM32 controller, close the Flash Loader Demonstrator, turn off the adapter. Now you can turn on the microcontroller again as usual. When the program is loaded, the LED will start blinking.

Working in other programs is similar. The necessary libraries are also selected, and the code is written. Paid utilities have more functionality, and you can create more complex projects.

Close Menu