um1730-getting-started-with-stm32cubef4-for-stm32f4-series-mcus-stmicroelectronics
um1730-getting-started-with-stm32cubef4-for-stm32f4-series-mcus-stmicroelectronics
User manual
Introduction
STM32Cube is an STMicroelectronics original initiative to improve designer productivity significantly by reducing development
effort, time, and cost. STM32Cube covers the whole STM32 portfolio.
STM32Cube includes:
• A set of user-friendly software development tools to cover project development from conception to realization, among
which are:
– STM32CubeMX, a graphical software configuration tool that allows the automatic generation of C initialization code
using graphical wizards
– STM32CubeIDE, an all-in-one development tool with peripheral configuration, code generation, code compilation,
and debug features
– STM32CubeCLT, an all-in-one command-line development toolset with code compilation, board programming, and
debug features
– STM32CubeProgrammer (STM32CubeProg), a programming tool available in graphical and command-line
versions
– STM32CubeMonitor (STM32CubeMonitor, STM32CubeMonPwr, STM32CubeMonRF, STM32CubeMonUCPD),
powerful monitoring tools to fine-tune the behavior and performance of STM32 applications in real time
• STM32Cube MCU and MPU Packages, comprehensive embedded-software platforms specific to each microcontroller
and microprocessor series (such as STM32CubeF4 for the STM32F4 series), which include:
– STM32Cube hardware abstraction layer (HAL), ensuring maximized portability across the STM32 portfolio
– STM32Cube low-layer APIs, ensuring the best performance and footprints with a high degree of user control over
hardware
– A consistent set of middleware components such as RTOS, USB, TCP/IP, graphics, and FAT file system
– All embedded software utilities with full sets of peripheral and applicative examples
• STM32Cube Expansion Packages, which contain embedded software components that complement the functionalities of
the STM32Cube MCU and MPU Packages with:
– Middleware extensions and applicative layers
– Examples running on some specific STMicroelectronics development boards
This user manual describes how to get started with the STM32CubeF4 MCU Package.
Section 2 describes the main features of STM32CubeF4 MCU package.
Section 3 and Section 4 provide an overview of the STM32CubeF4 architecture and MCU package structure.
1 General information
The STM32CubeF4 MCU package runs on STM32F4 series series 32-bit microcontrollers based on the Arm®
Cortex®-M4 processor.
Note: Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
The STM32CubeF4 MCU package runs on STM32 microcontrollers based on the Arm® Cortex®-M4 processor.
STM32CubeF4 gathers all generic embedded software components required to develop an application on
STM32F4 microcontrollers in a single package. In line with the STMCube initiative, this set of components is
highly portable, not only within the STM32F4 series but also on other STM32 series.
STM32CubeF4 is fully compatible with the STM32CubeMX code generator for generating initialization code. The
package includes low-layer (LL) and hardware abstraction layer (HAL) APIs that cover the microcontroller
hardware, with an extensive set of examples running on STMicroelectronics boards. The HAL and LL APIs are
available in an open-source BSD license for user convenience.
The STM32CubeF4 MCU package also contains a set of middleware components with the corresponding
examples. They come with very permissive license terms:
• A full USB host and device stack supporting many classes:
– Host classes: HID, MSC, CDC, Audio, MTP.
– Device classes: HID, MSC, CDC, Audio, DFU.
• Graphics:
– STemWin, a professional graphical stack solution available in binary format and based on the emWin
solution from the STMicroelectronics' partner Segger.
– ST-TouchGFX, an STMicroelectronics professional graphical stack solution available in binary format.
– LibJPEG, an open-source implementation on STM32 for JPEG image encoding and decoding.
• CMSIS-RTOS implementation with a FreeRTOS™ open-source solution.
• FAT file system based on an open-source FatFS solution.
• TCP/IP stack based on an open-source LwIP solution.
• SSL/TLS secure layer based on the open-source mbedTLS.
A demonstration implementing all these middleware components is also provided in the STM32CubeF4 package.
Board Support Package (BSP) Low Layer (LL) Hardware Abstraction Layer (HAL)
HAL and LL APIs
DT73655V1
The STM32CubeF4 firmware solution is built around three independent levels that can easily interact with each
other as described in the following figure:
Applications
Level 1
Examples
BSP drivers
Level 0
Hardware abstraction layer (HAL)
DT73656V1
HAL
3.1 Level 0
This level is divided into three sublayers:
• Board support package (BSP).
• Hardware abstraction layer (HAL).
• Low layer (LL).
3.2 Level 1
This level is divided into two sublayers:
• Middleware components.
• Examples based on the middleware components.
Middleware components
The middleware components are a set of libraries covering USB host and device libraries, STemWin, ST-
TouchGFX, LibJPEG, FreeRTOS™, FatFS, LwIP, and mbedTLS. Horizontal interactions between the components
of this layer are done directly by calling the feature APIs, while the vertical interaction with the low-level drivers is
done through specific callbacks and static macros implemented in the library system call interface. For example,
FatFS implements the disk I/O driver to access the microSD™ drive or the USB mass storage class.
The main features of each middleware component are as follows:
• USB host and device libraries:
– Several USB classes are supported (Mass-Storage, HID, CDC, DFU, AUDIO, MTP).
– Support multipacket transfer features: allow sending large amounts of data without splitting them into
maximum packet size transfers.
– Use configuration files to change the core and the library configuration without changing the library
code (read-only).
– Include 32-bit aligned data structures to handle DMA-based transfer in high-speed modes.
– Support multi-USB OTG core instances from user level through configuration file (allow operations
with more than one USB host/device peripheral).
– RTOS and standalone operation.
– The link with the low-level driver is done through an abstraction layer using the configuration file to
avoid any dependency between the library and the low-level drivers.
3.3 Level 2
This level is composed of a single layer, which is a global real-time and graphical demonstration based on the
middleware service layer, the low-level abstraction layer, and the applications that make basic use of the
peripherals for board-based functions.
STM32CubeF4 features a rich set of examples and demonstrations at all levels, making it easy to understand and
use HAL drivers and/or middleware components. These examples run on the STMicroelectronics boards listed in
the following table:
STM32429I-EVAL STM32F429xx
STM32439I-EVAL STM32F439xx
STM3240G-EVAL STM32F407xx
STM3241G-EVAL STM32F417xx
STM32F4DISCOVERY STM32F407xx
32F401CDISCOVERY STM32F401xC
32F429IDISCOVERY STM32F429xx
NUCLEO-F401RE STM32F401xE
NUCLEO-F411RE STM32F411xE
STM32446E-EVAL STM32F446xx
NUCLEO-F446xE STM32F446xx
STM32469I-EVAL STM32F469xx
32F469IDISCOVERY STM32F469xx
NUCLEO-F410RB STM32F410xx
NUCLEO-F429ZI STM32F429ZI
NUCLEO-F446ZE STM32F446ZE
32F411EDISCOVERY STM32F411xE
32F412GDISCOVERY STM32F412Zx
NUCLEO-F412ZG STM32F412Zx
NUCLEO-F413ZH STM32F413ZH
32F413HDISCOVERY STM32F413ZH
STM32F4 supports both Nucleo-64 and Nucleo-144 boards. These boards support Adafruit LCD, the ARDUINO®
Uno shields that embed a microSD™ connector and a joystick in addition to the LCD.
The ARDUINO® shield drivers are provided within the BSP component. Their usage is illustrated by a
demonstration firmware.
The STM32CubeF4 firmware can run on any compatible hardware. If the user’s board has the same hardware
features as the STMicroelectronics board (LED, LCD display, push-buttons, etc.), the user only has to update the
BSP drivers to port the provided examples onto their board.
Contains
STM32F4xx
CMSIS files that
defines
Peripheral's
registers
declarations, bits
definition and the BSP drivers for the
address mapping supported boards
STemWin
professional stack STM32F4xx HAL
coming from and LL drivers
SEGGER and
available in binary
form
USB Device
USB Host Library Library supporting
supporting both both OTG FS and
OTG FS and HS HS cores and
cores and offering offering the
the following following classes:
classes: HID, MSC, HID, MSC, CDC,
CDC, Audio, and Audio, and DFU
MTP
Set of examples
organized by board and
provided with
Miscellaneous
preconfigured projects.
utilities
WIN32 directory
contains Windows-
based simulation
project for STemWin.
DT73657V1
For each board, a set of examples is provided with preconfigured projects for EWARM, MDK-ARM™, and
STM32CubeIDE toolchains.
Figure 4 shows the project structure for the STM32F411RE-Nucleo board. The structure is identical for other
boards.
DT73658V1
The examples are classified depending on the STM32Cube level they apply to, and are named as follows:
STM32429IEVAL
1 1 87 NA NA 79 3
STM32439IEVAL
STM3240GEVAL
1 1 72 NA NA 54 1
STM3241GEVAL
STM32F4DISCOVERY 1 1 27 NA NA 3 1
32F401CDISCOVERY 1 1 24 NA NA 3 1
NUCLEO-F401RE 1 1 7 NA NA NA NA
NUCLEO-F411RE 1 1 9 62 12 NA 1
32F411EDISCOVERY 1 1 24 NA NA 3 1
32F429IDISCOVERY 1 1 30 NA NA 28 3
NUCLEO-F429ZI 1 1 27 7 1 7 1
STM32446E-EVAL 1 1 71 NA NA 38 1
NUCLEO-F446ZE 1 1 27 NA NA 6 1
STM32469I-EVAL 1 1 94 NA NA 64 3
32F469IDISCOVERY 1 1 46 NA NA 46 3
NUCLEO-F410RB 1 1 16 2 NA 1 NA
32F412GDISCOVERY 1 1 50 NA NA 24 1
NUCLEO-F412ZG 1 1 42 NA NA 10 1
NUCLEO-F413ZH 1 1 48 NA NA 18 1
32F413HDISCOVERY 1 1 27 NA NA 20 1
6. Peripheral initialization
a. Start by writing the peripheral HAL_PPP_MspInit function. For this function, proceed as follows:
◦ Enable the peripheral clock.
◦ Configure the peripheral GPIOs.
◦ Configure the DMA channel and enable DMA interrupt (if necessary).
◦ Enable peripheral interrupt (if necessary).
b. Edit the stm32f4xx_it.c file to call the required interrupt handlers (peripheral and DMA), if
necessary.
c. Write process complete callback functions if the user plans to use peripheral interrupt or DMA.
d. In the main.c file, initialize the peripheral handle structure and call the HAL_PPP_Init() function to
initialize the peripheral.
7. Develop an application process.
At this stage, the system is ready and the user can start developing the application code.
a. The HAL provides intuitive and ready-to-use APIs for configuring the peripheral, and supports polling,
interrupt, and DMA programming models to accommodate any application requirements. For more
details on how to use each peripheral, refer to the rich example set provided.
b. If the application has any real-time constraints, the user can find a large set of examples showing how
to use the FreeRTOS™ and integrate it with the middleware stacks provided in STM32CubeF4. This
can be a good starting point for a first development.
Note: In the default HAL implementation, the SysTick timer is the timebase source. It is used to generate interrupts at
regular time intervals. If HAL_Delay() is called from the peripheral ISR process, the SysTick interrupt must have
higher priority (numerically lower) than the peripheral interrupt. Otherwise, the caller ISR process is blocked.
Functions affecting timebase configurations are declared as __Weak to make overrides possible in case of other
implementations in the user file (using a general purpose timer, for example, or another time source). For more
details, refer to the HAL_TimeBase example.
5.2.2 LL application
This section describes the steps required to create your own LL application using STM32CubeF4.
• Create your project.
To create a new project, either start with the Templates_LL project provided for each board in the \\Proje
cts\\<STM32xxx_yyy>\\Templates_LL folder, or with any available project in the \\Projects\\<ST
M32xxy_yyy>\\Examples_LL folder (<STM32xxx_yyy> refers to the board name, such as
STM32F411RE-Nucleo).
The template project provides an empty main loop function, making it a good starting point to get familiar
with the project settings for STM32CubeF4.
The main template characteristics are as follows:
– It contains the source code of LL and CMSIS drivers, which are the minimal components to develop
code on any given board.
– It contains the include paths for all the required firmware components.
– It selects the supported STM32F4 device and allows the configuration of the CMSIS and LL drivers
accordingly.
– It provides ready-to-use user files that are preconfigured as follows:
◦ main.h: LED & USER_BUTTON definition abstraction layer.
◦ main.c: system clock configuration for maximum frequency.
6 FAQs
Does the HAL take benefit from interrupts or DMA? How can this be controlled?
Yes, it does. The HAL supports three API programming models: polling, interrupt, and DMA (with or without
interrupt generation).
How can I include LL drivers in my environment? Is there any LL configuration file as for HAL drivers?
There is no configuration file. The source code must directly include the necessary stm32f4xx_ll_ppp.h
file(s).
Can I use HAL and LL drivers together? If yes, what are the constraints?
It is possible to use both HAL and LL drivers. One can handle the IP initialization phase with HAL and then
manage the I/O operations with LL drivers.
The major difference between HAL and LL is that HAL drivers require the creation and use of handles for
operation management, while LL drivers operate directly on peripheral registers. Mixing HAL and LL is illustrated
in the Examples_MIX example.
Are there any LL APIs that are not available with HAL?
A few Arm® Cortex® APIs have been added to stm32f4xx_ll_cortex.h, for example, for accessing SCB or
SysTick registers.
Revision history
Table 4. Document revision history
Contents
1 General information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 STM32CubeF4 main features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 STM32CubeF4 architecture overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.1 Level 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.2 Level 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.3 Level 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4 STM32CubeF4 MCU package overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.1 Supported STM32F4 devices and hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.2 MCU package overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5 Getting started with STM32CubeF4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12
5.1 How to run a first example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.2 How to develop an application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.2.1 HAL application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.2.2 LL application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.3 Using STM32CubeMX for generating the initialization C code . . . . . . . . . . . . . . . . . . . . . . . . 15
5.4 How to get STM32CubeF4 release updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.4.1 How to install and run the STM32CubeUpdater program . . . . . . . . . . . . . . . . . . . . . . . . . 15
6 FAQs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
List of tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
List of figures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22
List of tables
Table 1. Macros for STM32F4 series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 2. Evaluation and Discovery boards for STM32F4 series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Table 3. Number of examples and applications available for each board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Table 4. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
List of figures
Figure 1. STM32CubeF4 firmware components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Figure 2. STM32CubeF4 firmware architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Figure 3. STM32CubeF4 MCU package structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 4. STM32CubeF4 examples overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10