"We are stuck with technology when what we really want is just stuff that works."
Douglas Adams, "The Salmon of Doubt".
All content in this project group is licensed under the terms of the unlicense unless otherwise noted.
I am not affiliated in any way with ST Microelectronics, but I like their STM32 MCUs.
For first contact with STM32 MCUs, use the vendor's free Eclipse based fully integrated IDE: STM32CubeIDE
- Video "How to use STM32CubeIDE" and STM32 youtube channel
- Read the docs, especially
- MOOC - STM32CubeIDE basics
- STM Education
Note that STM32CubeIDE suggests generating a HAL (hardware abstraction layer) or LL (low level) code skeleton from a graphical MCU configuration tool (formerly known as STM32CubeMX). But, you can write the complete code yourself at any level, say register level, as well. The fully integrated IDE conveniently supports code browsing, source and instruction level debugging, inspection of peripheral registers, debugging by tracing etc.. So, give it a try, at least for the first projects to familiarize yourself with the hardware.
GNU arm-none-eabi toolchain with Makefile
These tools are also used by STM32CubeIDE under the hood. It may be worthwhile to study the use of these command line tools (compiler flags, linker scripts, debugger integration, ...) from STM32CubeIDE sample projects. STM32CubeMX can also generate Makefile projects. The toolchain comes already bundled with STM32CubeIDE, check for the plugin folders. You may also install and use them independently. See Makefile Blinky example.
STM Nucleo Boards
Having a known-good reference board is a must for development. There are many low priced STM Nucleo boards available, the examples mostly use the
All newer boards contain the STLINK/V2.1 debug interface over USB. The debug interface on the larger boards can be used separately for debugging custom hardware. Besides the SWD debug interface, the USB connection integrates
- the power supply for the board
- a USB VCP (virtual COM port) for board communication
- "MBED microcontroller USB device" a USB MSC (mass storage class) USB-stick/disk/disk for easy flashing (programming) the board by simply copying a .bin file to the USB drive The USB MSC driver is a standard driver supplied by the OS without installing any specific software/driver.
For each board you have, you should read (at least: browse) the docs
- board ressources (like https://www.st.com/en/evaluation-tools/nucleo-f446re.html#resource)
- chip data sheet (like https://www.st.com/resource/en/datasheet/stm32f446re.pdf)
- chip reference manual (like https://www.st.com/resource/en/reference_manual/dm00135183.pdf)
Lab equipment is always helpful. A low-cost USB logic analyzer helps detecting issues and verifying assumptions.
Blinky - The embedded "Hello World"
- HAL Blinky (STM Hardware Abstraction Layer)
- Register-Level Blinky (ARM CMSIS)
- Bare-Metal Assembler Blinky
- Makefile Blinky using command line tools
The STM AN4989 Application note "STM32 microcontroller debug toolbox" gives a very good and complete overview.
A very useful article about The Best and Worst GCC Compiler Flags For Embedded
Some topics are covered under Debugging.
Programming the STM32 Peripherals
HAL Drivers (Firmware) and Example Projects
The firmware contains:
- STM32Fxxx_HAL_Driver: the firmware (chip level driver) sources for two abstration levels: HAL and LL
- CMSIS: ARM vendor-independent hardware abstraction layer, see also below
- BSP (board support packages): board level hardware abstraction for LEDs, buttons, and more components like MEMS.
- Projects: per board examples
- documentation at Documentation/STM32CubeFxGettingStarted.pdf
- STM32F0: https://github.com/STMicroelectronics/STM32CubeF0
- STM32F4: https://github.com/STMicroelectronics/STM32CubeF4
- STM32F7: https://github.com/STMicroelectronics/STM32CubeF7
- STM32L4: https://github.com/STMicroelectronics/STM32CubeL4
- STM32L5: https://github.com/STMicroelectronics/STM32CubeL5
- STM32G0: https://github.com/STMicroelectronics/STM32CubeG0
- STM32G4: https://github.com/STMicroelectronics/STM32CubeG4
The firmware packages are also downloaded and managed by the STM32Cube tools. For a default installation, check:
ARM vendor-independent hardware abstraction layer
Other Libraries and Blogs
Tilen Majerle maintains a huge collection of well documented tibraries and tutorials for the STM32Fxxx series: https://stm32f4-discovery.net/
Vivonomicon Blog https://vivonomicon.com/category/stm32_baremetal_examples/
How to handle 5V peripherals/interfaces
The STM32 has many 5V tolerant IO pads. See STM Application note AN 4899 "STM32 GPIO configuration for hardware settings and low-power consumption"
STM32 Peripheral Examples
PWM Input Mode
- using HAL_UART_Receive_IT for parsing NMEA GPS telegrams
- advanced UART receiving using DMA and idle interrupt
- w25qxx SPI flash Library for STM32 by Nima Askari: https://github.com/nimaltd/w25qxx
- STM AN4678 Application note "Full duplex SPI emulation for STM32F4 microcontrollers"
- Trigger SPI DMA transfer from Timer https://community.st.com/s/question/0D50X0000C4MPwQSQW/trigger-spi-dma-transfer-from-timer-directly
Ethernet / lwIP
- Mastering the FreeRTOS Real Time Kernel – a Hands On Tutorial Guide FreeRTOS V10.0.0 Reference Manual
- discussion of issues and fixes for malloc/free http://www.nadler.com/embedded/newlibAndFreeRTOS.html
Hardware (Board) Development
Example of an easy to solder prototype on a bread board:
Read the STM "Getting started with STM32xx Series hardware development" app notes carefully. Read the schematics and layout of a related STM Nucleo or Discovery Board for reference. Connect all VDD, VDDA and GND pins. Consider letting the following pins be accessible:
- BOOT0 boot mode pin (or more BOOTx pins) with pull-down (rarely pull-up) R's or switches for setting the desired boot mode. Most common default boot mode: boot from internal flash.
- NRST (reset) - which is a low-active bidir IO pin. Maybe left open, but use a 100nF C to GND to avoid parasitic spontaneuos reboots.
- SWDIO and SWCLK (serial wire debug) including SWO if present.
- an USART serial port for logging.
- an in-the-field updates cabalbe peripheral interface if that is required, see STM AN2606 Application note "STM32 microcontroller system memory boot mode".
If the pincount is getting low: most pins can be re-defined in firmware after the MCU has booted.
- a KICAD design of a minimal STM32 board: https://vivonomicon.com/2018/05/05/your-own-hardware-designing-an-stm32-development-board/
- a video tutorial on bringing-up a custom board: https://youtu.be/x_5rYfAyqq0