Um1860 Getstart Stm32cubel4 Mcu Pack
Um1860 Getstart Stm32cubel4 Mcu Pack
User manual
Getting started with STM32CubeL4 MCU Package
for STM32L4 Series and STM32L4+ Series
Introduction
STM32Cube is an STMicroelectronics original initiative to significantly improve designer's
productivity 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
the conception to the 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
– 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 STM32CubeL4 for
the STM32L4 Series and STM32L4+ 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 FAT file system, RTOS, USB
Host and Device, Touch library, and Graphics
– 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 STM32CubeL4 MCU Package.
Section 1 describes the main features of the STM32CubeL4 MCU Package, part of the
STM32Cube initiative. Section 2 and Section 3 provide an overview of the STM32CubeL4
architecture and MCU Package structure.
Contents
5 FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.1 What is the license scheme for the STM32CubeL4 firmware? . . . . . . . . 25
5.2 Which boards are supported by the STM32CubeL4 MCU Package? . . . 25
5.3 Are there any examples provided with the ready-to-use toolset projects? 25
5.4 Is there any link with Standard Peripheral Libraries? . . . . . . . . . . . . . . . . 25
5.5 Do the HAL drivers take benefit from interrupts or DMA?
How can this be controlled? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
6 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
List of tables
List of figures
Board support package (BSP) Low-layer APIs (LL) Hardware abstraction layer APIs (HAL)
(1) The set of middleware components depends on the product Series. MSv37858V10
a. Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and or elsewhere.
The STM32Cube firmware solution is built around three independent levels that interact
easily as described in Figure 2.
Applications
Level 1
Examples
HAL
MSv34990V3
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.
STM32CubeL4 features a rich set of examples and applications that facilitate the use of the
HAL drivers and middleware components. These examples run on the STMicroelectronics
boards listed in Table 3 and in Table 4.
STM32L476G-EVAL STM32L476xx
32L476GDISCOVERY STM32L476xx
NUCLEO-L476RG STM32L476xx
NUCLEO-L412KB STM32L412xx
NUCLEO-L412RB-P STM32L412xx
NUCLEO-L432KC STM32L432xx
NUCLEO-L433RC-P STM32L433xx
NUCLEO-L452RE STM32L452xx
NUCLEO-L452RE-P STM32L452xx
NUCLEO-L496ZG STM32L496xx
NUCLEO-L4P5ZG STM32L4P5xx
32L4P5GDISCOVERY STM32L4P5xx
STM32L4R9I-EVAL STM32L4R9xx
32L4R9IDISCOVERY STM32L4R9xx
NUCLEO-L4R5ZI STM32L4R5xx
NUCLEO-L4R5ZI-P STM32L4R5xx
B-L4S5I-IOT01A STM32L4S5xx
1. The library files in brown must not be modified by the user, while the files in blue can be modified.
For each board, a set of examples is provided with pre-configured projects for EWARM,
MDK-ARM and SW4STM32, except for the 32L4P5GDISCOVERY, NUCLEO-L4P5ZG and
B-L4S5I-IOT01A boards where SW4STM32 is replaced by STM32CubeIDE.
Figure 4 shows the projects structure for the NUCLEO-L476RG board.
The examples are classified depending on the STM32Cube level to which they apply, 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 the
quick build of 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, \SW4STM32 and \STM32CubeIDE folders contain the pre-
configured project for each toolchain.
• readme.txt describing the example behavior and environment needed to make it work.
Table 5 gives the number of projects available for each board.
32L496GDISCOVERY
32L476GDISCOVERY
32L4R9IDISCOVERY
NUCLEO-L433RC-P
NUCLEO-L412RB-P
NUCLEO-L452RE-P
NUCLEO-L496ZG-P
STM32L476G-EVAL
NUCLEO-L4R5ZI-P
STM32L4R9I-EVAL
NUCLEO-L4P5ZG
NUCLEO-L476RG
NUCLEO-L432KC
NUCLEO-L412KB
NUCLEO-L496ZG
NUCLEO-L452RE
NUCLEO-L4R5ZI
B-L475E-IOT01A
B-L4S5I-IOT01A
Level Total
Templates_LL 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 20
Templates 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 20
Examples_MIX 0 0 0 0 1 0 10 12 0 0 0 0 2 2 0 0 0 0 2 0 29
Examples_LL 0 0 0 0 10 0 94 91 0 0 0 0 15 7 0 0 0 1 1 0 219
Examples 51 87 3 52 55 3 97 71 3 82 3 62 43 20 0 1 17 26 23 17 718
UM1860 Rev 14
Demonstrations 1 1 0 1 0 0 1 1 0 1 0 1 1 1 0 1 1 1 1 1 14
Applications 12 27 0 5 0 0 10 2 0 15 0 5 15 1 3 11 6 2 11 5 130
Total 66 117 5 60 68 5 214 179 5 100 5 70 78 33 5 15 26 32 40 25 1148
UM1860
UM1860 Getting started with STM32CubeL4
To open, build and run an example with the supported toolchains follow the steps below:
• EWARM
a) Under the example folder, open \EWARM sub-folder.
b) Launch the Project.eww workspace(a).
c) Rebuild all files: Project->Rebuild all.
d) Load project image: Project->Debug.
e) Run program: Debug->Go(F5).
• MDK-ARM
a) Under the example folder, open \MDK-ARM sub-folder.
b) Launch the Project.uvprojx workspace(a).
c) Rebuild all files: Project->Rebuild all target files.
d) Load project image: Debug->Start/Stop Debug Session.
e) Run program: Debug->Run (F5).
• SW4STM32
a) Open the SW4STM32 toolchain
b) Click File->Switch Workspace->Other and browse to the SW4STM32
workspace directory
c) Click File->Import, select General->Existing Projects into Workspace and then
click Next.
d) Browse to the SW4STM32 workspace directory and select the project.
e) Rebuild all project files: select the project in the Project explorer window then
click the Project->build project menu.
f) Run program: Run->Debug (F11)
• STM32CubeIDE
a) Open the STM32CubeIDE toolchain.
b) Click File->Switch Workspace->Other and browse to STM32CubeIDE
workspace directory.
c) Click File->Import, select General->Existing Projects into Workspace and then
click Next.
d) Browse to the STM32CubeIDE workspace directory, select the project.
e) Rebuild all project files: select the project in the Project explorer window then
click the Project->build project menu.
f) Run program: Run->Debug (F11).
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 stm32l4xx_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 chooses 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 peripheral interrupt or DMA is used.
d) In the main.c file, initialize the peripheral handle structure then call the function
HAL_PPP_Init() to initialize the peripheral.
7. Develop the application
At this stage, the system is ready and the user can start developing the 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 STM32CubeL4 package.
– If the application has some real-time constraints, the user finds a large set of
examples showing how to use FreeRTOS™ and how integrate it with all
middleware stacks provided within STM32CubeL4. This is a good starting point to
develop the 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 a LL application using STM32CubeL4.
1. Create the project
To create a new project, the user can either start from the Templates_LL project
provided for each board under \Projects\<STM32xxx_yyy>\Templates_LL or from any
available project under \Projects\<STM32xxy_yyy>\Examples_LL (<STM32xxx_yyy>
refers to the board name, such as NUCLEO-L476RG).
The Template project provides an empty main loop function, however it is a good
starting point to get familiar with project settings for STM32CubeL4.
The template main characteristics are the following:
– It contains the source code of LL and CMSIS drivers that are the minimal
components to develop a code on a given board.
– It contains the include paths for all the required firmware components.
– It selects the supported STM32L4 Series or STM32L4+ Series device and allows
the configuration of CMSIS and LL drivers accordingly.
– It provides ready-to-use user files, that are pre-configured as follows:
main.h: LED & USER_BUTTON definition abstraction layer
main.c: System clock configuration for maximum frequency.
2. Port an existing project to another board
To port an existing project to another target board, start from the Templates_LL project
provided for each board and available under
\Projects\<STM32xxx_yyy>\Templates_LL:
a) Select an LL example
To find the board on which LL examples are deployed, refer to the list of LL
examples in STM32CubeProjectsList.html, to Table 5: Number of examples
available for each board, or to application note “STM32Cube firmware examples
for STM32L4 Series and STM32L4+ Series” (AN4726).
b) Port the LL example
– Copy/paste the Templates_LL folder to keep the initial source or directly update
the existing Templates_LL project.
– Then LL example porting consists mainly of replacing Templates_LL files by the
Examples_LL targeted project.
– Keep all board specific parts. For reasons of clarity, board specific parts have been
flagged with specific tags:
/* =========== BOARD SPECIFIC CONFIGURATION CODE BEGIN =========== */
/* ============ BOARD SPECIFIC CONFIGURATION CODE END ============= */
Thus the main porting steps are the following:
– Replace stm32l4xx_it.h file
– Replace stm32l4xx_it.c file
– Replace main.h file and update it: keep the LED and user button definition of the
LL template under "BOARD SPECIFIC CONFIGURATION" tags.
5 FAQ
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 handles 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.
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. For additional information about ST trademarks, please refer to www.st.com/trademarks. 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.