Um1779 User Manual: Getting Started With Stm32Cubef0 For Stm32F0 Series
Um1779 User Manual: Getting Started With Stm32Cubef0 For Stm32F0 Series
User manual
Getting started with STM32CubeF0 for STM32F0 Series
Introduction
STMCube™ is an STMicroelectronics original initiative to ease developers’ life by reducing
development efforts, time and cost. STM32Cube is the implementation of STMCube™ that
covers STM32 microcontrollers.
STM32Cube Version 1.x includes:
• The STM32CubeMX, a graphical software configuration tool that allows the generation
of C initialization code using graphical wizards.
• A comprehensive embedded software platform, delivered per series (such as
STM32CubeF0 for STM32F0 Series):
– The STM32Cube HAL, an STM32 abstraction layer embedded software ensuring
maximized portability across STM32 portfolio. The HAL is available for all
peripherals
– The low-layer APIs (LL) offering a fast light-weight expert-oriented layer which is
closer to the hardware than the HAL. The LL APIs are available only for a set of
peripherals.
– A consistent set of middleware components such as RTOS, USB, STMTouch™,
FatFS and Graphics
– All embedded software utilities coming with a full set of examples.
This user manual describes how to get started with the STM32CubeF0 firmware package.
Section 1 describes the main features of STM32CubeF0 firmware, part of the STMCube™
initiative. Section 2 and Section 3 provide an overview of the STM32CubeF0 architecture
and firmware package structure.
Contents
5 FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.1 What is the license scheme for the STM32CubeF0 firmware? . . . . . . . . 21
5.2 What boards are supported by the STM32CubeF0 firmware package? . 21
5.3 Are any examples provided with the ready-to-use toolset projects? . . . . 21
5.4 Is there any link with Standard Peripheral Libraries? . . . . . . . . . . . . . . . . 21
5.5 Does the HAL layer take benefit from interrupts or DMA?
How can this be controlled? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.6 How are the product/peripheral specific features managed? . . . . . . . . . . 22
6 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
List of tables
List of figures
&06,6
86% 7RXFKOLEUDU\ *UDSKLFV )DW)6 5726
0LGGOHZDUHOHYHO 8WLOLWLHV
+DUGZDUHDEVWUDFWLRQOD\HU$3,V
%RDUG6XSSRUW3DFNDJH%63 /RZOD\HU$3,V//
+$/
+$/DQG//$3,V
7KHVHWRIPLGGOHZDUHFRPSRQHQWVGHSHQGVRQWKHSURGXFW6HULHV 069
The STM32Cube firmware solution is built around three independent levels that can easily
interact as described in Figure 2.
>ĞǀĞůϮ (YDOXDWLRQERDUGDQG'LVFRYHU\.LWGHPRQVWUDWLRQ
$SSOLFDWLRQV
>ĞǀĞůϭ
/LEUDU\DQGSURWRFROEDVHGFRPSRQHQWV
IRUH[DPSOH)DW)6)UHH572686%'HYLFH
([DPSOHV
>ĞǀĞůϬ %63GULYHUV
+DUGZDUHDEVWUDFWLRQOD\HU+$/
,>
06Y9
2.1 Level 0
This level is divided into three sub-layers:
• Board Support Package (BSP)
• Hardware abstraction layer (HAL)
– HAL peripheral drivers
– Low-layer drivers
• Basic peripheral usage examples
2.2 Level 1
This level is divided into two sub-layers:
• Middleware components
• Examples based on the middleware components.
2.3 Level 2
This level is composed of a single layer which consist in a global real-time and graphical
demonstration based on the middleware service layer, the low-level abstraction layer and
the basic peripheral usage applications for board based features.
STM32CubeF0 features a rich set of examples and applications at all levels making it easy
to understand and use any HAL driver and/or middleware components. These examples run
on the STMicroelectronics boards listed in Table 2.
%63GULYHUVIRUWKHVXSSRUWHGERDUGV
(YDOXDWLRQERDUG
'LVFRYHU\NLW
1XFOHRNLW
'ULYHUVRIH[WHUQDOFRPSRQHQWV
&RQWDLQV670)[[
&06,6ILOHVWKDWGHILQHWKH
SHULSKHUDOUHJLVWHU
GHFODUDWLRQVELWGHILQLWLRQV
DQGDGGUHVVPDSSLQJ
670)[[+$/DQG//GULYHUV
7RXFK6HQVLQJOLEUDU\
86% 'HYLFH /LEUDU\ RIIHULQJ WKH
IROORZLQJ FODVVHV +,' 06& &'&
DQG')8
6HWRI([DPSOHV$SSOLFDWLRQVDQG 2SHQVRXUFHVPLGGOHZDUHVWDFNV
'HPRQVWUDWLRQVRUJDQL]HGE\
ERDUGDQGSURYLGHGZLWK
SUHFRQILJXUHGSURMHFWVXVHU
PRGLILDEOHILOHV
0LVFHOODQHRXVXWLOLWLHV
06Y9
1. The components files must not be modified by the user. Only the \Projects sources can be changed by the
user.
For each board, a set of examples are provided with pre-configured projects for EWARM,
MDK-ARM, and SW4STM32 toolchains.
Figure 4 shows the project structure for the NUCLEO-F072RB board.
The examples are classified depending on the STM32Cube level they apply to, and are
named as explained below:
• Level 0 examples are called Examples, Examples_LL and Examples_MIX. They use
respectively HAL drivers, LL drivers and a mix of HAL and LL drivers without any
middleware component.
• Level 1 examples are called Applications. They provide typical use cases of each
middleware component.
The template projects available in the Templates and Templates_LL directories allow to
quickly build any firmware application on a given board.
All examples have the same structure:
• \Inc folder that contains all header files.
• \Src folder for the sources code.
• \EWARM, \MDK-ARM, and \SW4STM32 folders contain the pre-configured project for
each toolchain.
• readme.txt describing the example behavior and needed environment to make it
working
Table 3 gives the number of projects available for each board.
Templates_LL 1 1 1 1 1 1 1 1 1 1 10
Templates 1 1 1 1 1 1 1 1 1 1 10
Examples_MIX 0 0 11 0 0 0 0 0 0 0 11
Examples_LL 0 0 74 0 0 0 0 0 0 0 74
Examples 46 30 45 33 17 45 29 46 17 41 349
Demonstrations 1 1 1 1 1 1 1 1 1 0 9
Applications 5 1 1 1 0 15 1 3 0 14 41
is clocked by the MSI (at this stage, the clock is not yet configured and thus the
system is running from the internal 4 MHz MSI).
c) Setting of NVIC Group Priority to 4.
d) Call of HAL_MspInit() callback function defined in stm32f0xx_hal_msp.c user file
to perform global low-level hardware initializations.
5. Configure the system clock
The system clock configuration is done by calling the two APIs described below:
a) HAL_RCC_OscConfig(): this API configures the internal and/or external
oscillators, as well as the PLL source and factors. The user can choose to
configure one oscillator or all oscillators. The PLL configuration can be skipped if
there is no need to run the system at high frequency.
b) HAL_RCC_ClockConfig(): this API configures the system clock source, the Flash
memory latency and AHB and APB prescalers.
6. Initialize the peripheral
a) First write the peripheral HAL_PPP_MspInit function. Proceed as follows:
– Enable the peripheral clock.
– Configure the peripheral GPIOs.
– Configure DMA channel and enable DMA interrupt (if needed).
– Enable peripheral interrupt (if needed).
b) Edit the stm32xxx_it.c to call the required interrupt handlers (peripheral and DMA),
if needed.
c) Write process complete callback functions if you plan to use peripheral interrupt or
DMA.
d) In your main.c file, initialize the peripheral handle structure then call the function
HAL_PPP_Init() to initialize your peripheral.
7. Develop your application
At this stage, your system is ready and you can start developing your application code.
– The HAL provides intuitive and ready-to-use APIs to configure the peripheral. It
supports polling, interrupts and DMA programming model, to accommodate any
application requirements. For more details on how to use each peripheral, refer to
the rich examples set provided in the STM32CubeF0 package.
– If your application has some real-time constraints, you can found a large set of
examples showing how to use FreeRTOS and integrate it with all middleware
stacks provided within STM32CubeF0. This can be a good starting point to
develop your application.
Caution: In the default HAL implementation, SysTick timer is used as timebase: it generates
interrupts at regular time intervals. If HAL_Delay() is called from peripheral ISR process,
make sure that the SysTick interrupt has higher priority (numerically lower) than the
peripheral interrupt. Otherwise, the caller ISR process will be blocked. Functions affecting
timebase configurations are declared as __weak to make override possible in case of other
implementations in user file (using a general purpose timer for example or other time
source). For more details, refer to HAL_TimeBase example.
4.2.2 LL application
This section describes the steps needed to create your own LL application using
STM32CubeF0.
5 FAQ
5.5 Does the HAL layer take benefit from interrupts or DMA?
How can this be controlled?
Yes. The HAL layer supports three API programming models: polling, interrupt and DMA
(with or without interrupt generation).
5.11 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 to create and use
handles for operation management while LL drivers operates directly on peripheral
registers. Mixing HAL and LL is illustrated in Examples_MIX example.
5.12 Are there any LL APIs which are not available with HAL?
Yes, there are.
A few Cortex® APIs have been added in stm32f0xx_ll_cortex.h e.g. for accessing SCB or
SysTick registers.
6 Revision history
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgement.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of Purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. All other product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.