STM32MCU basics

Revision as of 11:37, 18 August 2020 by Registered User

On this page you will find the basic knowledge for microcontrollers

What an MCU is ? Clock.png25min
Why to use an MCU ? Clock.png20min
Which STM32 MCU to select ? Clock.png15min
How to use STM32 MCU? Clock.png15min

1 What an MCU is?

1.1 Simple definition of a Microcontroller

A microcontroller (also called μC or MCU) is an embedded computer chip that controls most of the electronic gadgets and appliances people used on a daily basis.
It is a compact integrated circuit designed to govern a specific operation in an embedded system.

1.2 Microcontroller architecture

A typical microcontroller includes a processor, memory and Input/Output (I/O) peripherals on a single chip. Its components may be extended to include: Digital I/O, Analog I/O, Timers, Communication interfaces, Watchdog (a timer that is responsible for the detection of timed out or locked instruction)...
A processor is a little chip present in the device that has the role of arranging the instructions and order the outputs. The manufacturer defines the integrated peripherals and the hardware capabilities. This is the basic layout of a microcontroller:
newchart.jpg

1.3 STM32 overview

STMicroelectronics is manufacturing the STM32 MCUs which are based on the Arm® Cortex®-M processor. They are 32-bit RISC Arm processor cores, optimized for cost and power sensitive MCUs.
RISC Arm (Reduced Instruction Set Computer) is an instruction set that allows to divide the commands into several, simple and not complicated instructions that are meant to realize small objectives. The STM32 family offers a large range of devices combining:

  • Full integration
  • Ease of development thanks to the large ecosystem and professional development tools including free ones
  • Very high performance thanks to Arm® Cortex®-M core and ST ART Accelerator™ for some families
  • Real-time capabilities
  • Digital signal processing
  • Low-power and low-voltage operation
  • Connectivity
  • Graphic features

Several applications rely on STM32 (to be detailed in next chapter):

  • Industrial control systems
  • Human interface devices
  • Smart metering
  • Motor control
  • Medical instruments
  • Buildings and security (alarms, access control, power meters…)
  • Consumer products (PC peripherals, GPS, gaming…)
  • Internet of Things
  • Connectivity

1.4 Cortex-M architecture

The Cortex-M portfolio includes different architectures where the main ones embedded in STM32 microcontrollers are the following:

The 'Nested Vectored Interrupt Controller' is used to organize the interruptions in order to reduce the suspensions.
The Wakeup Interrupt Controller (WIC) is a way to detect an interruption and wake the processor from the sleep mode
Cortex-M comparison table (from ARM):

Feature Cortex-M0 Cortex-M0+ Cortex-M3 Cortex-M4 Cortex-M33 Cortex-M7
Instruction set architecture Armv6-M Armv6-M Armv7-M Armv7-M Armv8-M Mainline Armv7-M
Thumb, Thumb-2
Pipeline stages 3 2 3 3 3 6
Memory Protection Unit No Yes Yes Yes Yes Yes
Maximum MPU regions 0 8 8 8 16 16
Trace (ETM or MTB) No MTB ETMv3 ETMv3 MTB and/or ETMv4 ETMv4
DSP No No No Yes Yes Yes
Floating point hardware No No No Yes Yes Yes
Bus protocol AHB Lite AHB Lite AHB Lite, APB AHB Lite, APB AHB5 AXI4, AHB Lite, APB, TCM
Maximum # external interrupts 32 32 240 240 480 240
CMSIS Support Yes

More details about the Cortex-M processors are available on:
Arm Cortex-M Series Processors
Cortex-M resources

1.5 STM32 Features

1.5.1 STM32 peripherals

Over the time, new peripherals are embedded to answer emergent requests on the market.
The peripheral characteristics are not frozen, the very first STM32 devices are being improved to enable new features or fix some limitations.
The peripherals like low-power voltage detector, clock security system (CSS) and watchdogs help supporting safety-critical applications.
The code security may be ensured thanks to some protection features of the Flash memory.

1.5.2 STM32 hardware setup

Power supply
It is required to power on your device to make it start working.
Oscillators
The STM32 embeds an internal RC oscillator, but it is not accurate and stable as an external crystal.
Debug
After programming the MCU, the next step is to debug the code which means to reconsider it and try to resolve any defect that may interrupt the use of the MCU, and this is realized within a software program called Debugger.
While using a software IDE, a debugger is installed by default, but once developing the application of the MCU, a hardware debugger is needed. Depending on the supported debug system, it is possible to connect a debugger to the device and here are two examples:
  • SWD (Serial Wire Debug) which can be added using 2 pins: it is designed for micro debugging
  • JTAG (Joint Test Action Group) within 5 or 4 pins: it is designed for checking faults in boards in production.

1.5.3 STM32 resources

A dedicated webpage is available on ST website for each STM32 family. It contains all relevant documents and resources to guide the end-user on how to start developing with selected STM32 device and exploit it in an efficient way for user’s application.

The main relevant documents are:

- Datasheet (DS): the document describing the electrical characteristics of the product and its pinout.

- Errata sheet (ES): the document that specifies the known limitations of the product and the ways to work them out if available.

- Reference manual (RM): the document providing the product specification and describing its registers.

1.6 Varieties of STM32 MCUs

There are already 16 Cortex-M based microcontroller families (or series).

The STM32 families are split into 4 groups divided as follows:

Family Core Max Frequency Flash
High Performance STM32H7 Cortex-M7 - Cortex-M4 480 MHz - 240 MHz 1 to 2 Mbytes
STM32F7 Cortex-M7 216 MHz 256 Kbytes to 2 Mbytes
STM32F4 Cortex-M4 180 MHz 64 Kbytes to 2 Mbytes
STM32F2 Cortex-M3 120 MHz 128 Kbytes to 1 Mbyte
Mainstream STM32G4 Cortex-M4 170 MHz 32 to 512 Kbytes
STM32F3 Cortex-M4 72 MHz 16 to 512 Kbytes
STM32F1 Cortex-M3 72 MHz 16 Kbytes to 1 Mbyte
STM32G0 Cortex-M0+ 64 MHz 16 to 512 Kbytes
STM32F0 Cortex-M0 48 MHz 16 to 256 Kbytes
Ultra-low-power STM32L5 Cortex-M33 110 MHz 256 to 512 Kbytes
STM32L4+ Cortex-M4 120 MHz 512 Kbytes to 2 Mbytes
STM32L4 Cortex-M4 80 MHz 64 Kbytes to 1 Mbyte
STM32L1 Cortex-M3 32 MHz 32 to 512 Kbytes
STM32L0 Cortex-M0+ 32 MHz 8 to 192 Kbytes
Wireless STM32WB Cortex-M4 - Cortex-M0+ 64 MHz - 32 MHz 256 Kbytes to 1 Mbyte
STM32WL Cortex-M4 48 MHz 64 Kbytes to 256 Kbytes

The STM32 portfolio continues to be extended with more integration and performance and more complex peripherals. All ones with generic or dedicated application field.

The previous table helps to select the family of MCUs suitable depending on application needs, but it’s required to review deeply the product characteristics and components to fine-tune the choice.

2 Why to use an MCU?

2.1 Microcontrollers versus Microprocessors

Though microcontrollers are looking more and more like microprocessors, they remain different.
As the typical microcontrollers (known as MCUs) are single-chip computers that contain the main elements of a small computer system (core, memory, peripherals on a single chip), they are cheaper and smaller than microprocessors. On the other part, the microprocessors have some chips that have diverse roles.
In other words, despite the MCU which has external processor along with internal memory and input/output components, the microprocessor must be connected externally to the different components.
one.jpg

The MCUs also permit the user to run an operating system, which allows different processes to run simultaneously. Even though they are less powerful, those features make them quite attractive for numerous small embedded devices.

Microcontroller Microprocessor
MCU.jpg MPU1.jpg

2.2 MCUs Application

An embedded device is a combination of:

  • Hardware which are MCU various electronics components like sensors, and
  • Software which has the role of application control to perform specific tasks like analog acquisitions for measurements and digital signal processing for controls.

As a microcontroller integrates many components on a single chip, it is well fit for small device.
Moreover, this simplifies the design while reducing the overall cost. There are lots of embedded applications available in the market that require small processing solutions.
That is why we find MCUs:

  • in our today’s life (washing machine, TV, alarm clocks, remote control, IoT, touch screen controller…)
  • for our health (heartbeat, blood glucose meters, energy meter, speedometer...)
  • security (temperature control, monitoring, cameras, alarms…).

2.3 Reasons to use an MCU?

2.3.1 Power consumption

One key point when developing such devices is the power efficiency. The goal is to have a functional behavior for the longest time as possible, sometimes many years. This implies low-power consumption. MCUs may only consume a few microwatts in an operational mode. This power consumption can go as lower as a few nanowatts in some stop or sleep modes. This makes them quite attractive for low energy application.
A long-term trend now is the growing capabilities of the MCUs, with more processing performance, sophisticated peripherals, graphics capability, RF connectivity and even artificial intelligence. This enables the building of more powerful devices, making them a competitor of MPUs for devices where applications are not so demanding regarding the performance and the memory size.

2.3.2 Cost

Due to their small design, the microcontrollers cost less to produce and to maintain. The cost to manufacture can be under $0.10 per unit, and the average price for a 32-bit microcontroller is less than 1$.
Another point is that the MCU is efficient, if it does not work correctly it can easily be reprogrammed depending on the designed application or if the application for its use needs some changes.

2.3.3 Reusable

As mentioned in the previous section, another advantage of the microcontroller is that it is programmable so the same MCU can be reusable in different cases, options and applications just by reprogramming it for debug. So, to change a parameter or some data there is no need to buy another MCU, it is just about reprogramming the same MCU.

Warning white.png Warning
It is important to say that the previously mentioned points are not the only reasons why to use an MCU, there are many others such as: the integrity of the MCU, add-ons having small size with powerful features...

3 Which STM32 MCU to select ?

STMicroelectronics offers a large variety of STM32 MCUs, based on Arm® Cortex®-M0, M0+, M3, M4, M33 and M7 cores, depending on many features and parameters.
To make the best decision on the STM32 microcontroller selection, there are several factors to consider, mainly the architecture to select, the memory and power requirements, the peripherals to support such as the communication peripherals: USB, I2C, SPI, UART and the cost to review.
The selection depends on the functional requirements of the application: ultra-low-power performance, high-performance, or wireless connectivity.


STM32H7STM32F7STM32F4STM32F2STM32G0STM32F0STM31F1STM32G4STM32F3STM32L0STM32L1STM32L5STM32L4STM32L4+STM32WBSTM32WLHigh performanceMainstreamUltra low powerWireless32MCUs.png

What factors and parameters should you consider when selecting the most suitable STM32 MCU for graphic application, low-power application, or motor control application?

3.1 Which STM32 MCU to select for graphic application?

Many factors can be taken into consideration to ensure the right choice of STM32 MCU according to the requirement of the graphics application.

graphF7.jpg

The first thing you need to identify is which core and family of MCU required? Moreover, the Flash memory and RAM sizes in microcontrollers are critical options required to select the suitable ones for graphic application. Also, it is recommended to focus on:

  • Display resolution
  • Color depth
  • Expected performance.

And all required peripherals as:

  • Chrom-ART Accelerator™ (DMA2D)
  • JPEG codec
  • Chrom-GRC™
  • LCD-TFT
  • FMC/FSMC

3.2 Which STM32 MCU to select for Low-power application?

mculow.jpg

ST offers a large range of ultra-low-power microcontrollers: STM32L0 (Arm® Cortex® M0+), STM32L1 (Cortex M3), STM32L4, STM32L4+ (Cortex M4) and STM32L5 (Cortex-M33), providing low-power consumption.
To select the best microcontroller for Low-power application, you need first to identify the processor core. Then, consider the MCU performance and energy efficiency. In addition, the choice is depending on many key factors to consider such as:

  • Power consumption
  • Memory size
  • Clocks frequency
  • Various Low-power modes: Low-power run mode, Sleep mode, Low-power sleep mode, Stop mode, and Standby mode.
  • Wake-up time
  • Wake-up sources, that allow reducing the average current consumption of the application.
  • Switched-Mode Power Supply (SMPS) to reduce MCU’s current consumption
  • Direct memory access controller (DMA), useful to improve performance and reduce the power
  • Supply voltage range

Note that for Low-power applications, it is important to take into consideration current consumption, state retention, wake-up time, wake-up sources, and any additional functionality or peripherals that can operate in low-power mode to minimize the energy consumption.

3.3 Which STM32 MCU to select for Motor control application ?

A primary requirement to select the right MCU for Motor control application is to focus on these peripherals:

  • Analog-to-digital converter (ADC)
  • Number of comparators (COMP)
    motorcontrol.jpg
  • Digital-to-analog converter (DAC)
  • HRTIM
  • Timer

Make a special note that the selection is based on multiple criteria and depends on the requirements of application and which peripherals do you need:

  • Performance
  • Memory requirements
  • Number of Motor and Advanced Timer
  • OPAMP (Operational voltage amplifier)
  • Motor speed
  • Does it require a 16-bit Timer
  • Graphical display, so you need LCD peripheral

3.4 ST-MCU-FINDER

Thanks to the ST-MCU-FINDER tool that allows an easy search of STM32 MCU with multiple criteria including core type, CPU frequency, memory, price, package, temperature grade and peripherals such as control, timers, analog, connectivity, multimedia and security.
The ST-MCU-FINDER tool offers a graphic selector and simulator features that allows you to achieve the desired performance and optimization required to select the MCU or MPU that best fits your application needs.
In addition, this tool offers the possibility to access to data and technical documentation for a selected device (including datasheets, reference manuals, application notes, user manuals, programming manuals, errata sheets).
ST-MCU-FINDER tool is integrated in STM32CubeIDE and STM32CubeMX tools to select an MCU or a development board.
stFinder.jpg

You can select the device you need based on many choices as MCU Selector, Board Selector or Cross selector and according to the requirement of your application. For example, the selection of MCU for TouchGFX application using ST-MCU-FINDER requires the following peripherals:

  • DMA2D
  • CRC
  • FMC SDRAM
  • LTDC

ST-MCU-FINDER-PC is available for free download from the ST website.
Please note that it is possible via ST-MCU-FINDER tool to:

  • select the "'MCU Selector"', which is recommended when using custom hardware to filter by Part Number Search, Core, Series, Line, Package, price, IOs, Eeprom, Flash, RAM, Frequency and Peripheral.
  • use the "'Board Selector'" for ST Discovery or Evaluation boards to match the right MCU on the board and filter by criteria such as: Part Number Search, Type (Discovery, Evaluation Board, Nucleo), MCU Series, Price, Oscillator Frequency and Peripheral.
  • use the Cross selector (PC version only) to make a comparison of a reference MCU with approaching MCUs.
  • buy devices online from any mobile device or directly from the developer’s desktop environment.

It is important for the microcontroller selection to look at the electrical characteristics, available in the datasheet. However, this is not enough, as it is recommended to review the evaluation platform and software tools available for an MCU.

4 How to use STM32 MCU?

4.1 Ways to use STM32 MCU

There are two ways to use an STM32 MCU which are:

  • Developing your own board
  • Using existing STMicroelectronics boards

4.2 Boards type

4.2.1 STM32 Nucleo boards

The highly affordable STM32 Nucleo boards are low-cost and easy-to-use platform developments which allow to try out new ideas and to quickly create prototypes with any STM32 MCU because:

  • Cheaper
  • Software examples available
  • Extension connectors give access to most of the device’s I/Os and make the connection of add-on hardware possible.
  • ST-Link debugger/programmer integrated
  • Access directly to GPIO
  • ARDUINO® connector compliant

ST Nucleo Board

4.2.2 STM32 Discovery kits

STM32 Discovery kits allow users to easily develop applications with the high-performance microcontrollers. They allow either for beginners or for experienced users to get quickly started.
They are as well a cheap and complete solution for the evaluation of the outstanding capabilities of STM32 MCUs and MPUs. They carry out the necessary infrastructure for a demonstration of specific device characteristics; and comprehensive software examples allow to fully benefit from the devices features and added values:

  • Extension connectors give access to most of the device’s I/Os and make the connection of add-on hardware possible.
  • Software examples available
  • ARDUINO® connector compliant
  • Dedicated to a STM32 version
  • ST-Link debugger/programmer integrated
  • Function used to exploit main STM32 hardware functions
  • Display available on some boards

ST Discovery Board

4.2.3 STM32 Eval boards

The STM32 Eval boards have been designed as a complete demonstration and development platform for the STM32 MCUs and MPUs. They are meant to be used to execute a comprehensive evaluation of STMicroelectronics solutions. They carry external circuitry, such as transceivers, sensors, memory interfaces, displays and many more. The evaluation boards can be considered as a reference design for application development:

  • Dedicated to a STM32 version
  • Software examples available
  • ST-Link debugger/programmer integrated
  • Function used to exploit main STM32 hardware functions
  • Display available on some boards
  • Able to use every function of STM32

ST Eval Board

4.2.4 Board Features

Board ST-Link ARDUINO connector Display
Custom
No
STM32 Nucleo
Yes (V2.1/V3)
x
STM32 Discovery
Yes (V2.1/V3)
x
x
STM32 Eval
Yes (V2.1/V3)
x
x

4.3 How to program STM32 MCUs

4.3.1 Software Tools

STMicroelectronics offers some software programs that allow the users to program and allow the application using the boards and the MCUs:

  • STM32CubeIDE
  • STM32CubeMX
  • STM32CubeMonitor
  • X-CUBE-MCSDK...
STM32CubeMXSTM32CubeIDESTM32CubeProgSTM32CubeMonitorSTM32Ecosystem flow.jpg

But STM32 is also compliant with:

4.3.2 STM32Cube firmware

STM32Cube is a set of tools and embedded software bricks available free of charge to enable fast and easy development on the STM32 platform which simplifies and speeds up developers’ work.

  • HAL(High Abstraction Layer)
  • LL(Low Layer)
  • Examples
  • Readme files

4.3.3 Hardware tools

The ST-LINK/V3 is an in-circuit debugger for the STM8 and STM32 microcontrollers. Most of the time it is embedded on the board. If not you can use the STLinks-V3mini or STLinks-V3SET standalone devices.
ST-Link