Low Layer Manual
Low Layer Manual
Application note
STM32 standard peripheral library to
STM32Cube low-layer migration
Introduction
Part of the STM32 value proposition is the availability of complete and full firmware libraries,
providing developers with an initial framework to build their embedded application.
The central brick of this framework is the well-known Standard Peripheral Library (SPL),
which is used by all the middleware components to access STM32 peripherals.
Over years, the STM32 portfolio has continued to grow and to offer to developers a variety
of solutions for balancing cost, power and performance, notably the STM32Cube Low Layer
(LL) drivers.
For designers of STM32 microcontroller applications, it is important to be able to easily
upgrade the microcontroller type and/or a firmware solution to another. This migration is
often needed, since the development for the SPL has stopped and when product
requirements and specifications grow, putting extra demands on the variety of used
peripherals.
This application note shows the steps to migrate from an existing STM32-based application
developed under the STM32 SPL to any one of the other microcontroller types using the
STM32Cube LL drivers.
This application note groups together all the most important information needed for a
successful migration of STM32 SPL-based application to STM32Cube LL APIs usage.
It is composed of three sections:
• STM32 SPL vs. STM32Cube LL Architecture Overview: presenting a description of both
solutions and a comparison between both.
• STM32 SPL to STM32Cube LL Manual Migration: detailing the steps to migrate manually
an application based on standard peripheral library.
• STM32 SPL to STM32Cube LL Automatic Migration: presenting the SPL2LL-Converter
migration tool as a solution for automatic migration of StdPeriph-based application.
Contents
4 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
List of tables
List of figures
This section describes the architecture of both STM32 Standard Peripheral Library (SPL)
and STM32Cube LL with a summary to comparing the main differences between the two
solutions.
1.1.1 Overview
CMSIS
The STM32 SPL’s CMSIS is composed of two layers: a Core Peripheral Access layer that
contains name definitions, address definitions and helper APIs to access core Cortex-Mx
registers and peripherals. And an STM32 Peripheral Access layer which provides definitions
for all the peripheral registers, bit fields and memory mapping for the device.
Each STM32 embedded peripheral has a source code file stm32yyxx_ppp.c and a header
file stm32yyxx_ppp.h. The stm32yyxx_ppp.c file contains all the firmware APIs required to
use the PPP peripheral.
The stm32yyxx_conf.h file is considered a user file that is intended to be customized and
tailored according to the used peripherals in the application. It is used to specify the set of
parameters to interface with the library drivers before running any application.
Table 1 regroups and describes the above files referred by the user’s STM32 SPL based
application:
1.2.1 Overview
The Low Layer (LL) drivers are a part of the STM32Cube firmware HAL and are designed to
offer a fast light-weight expert-oriented layer which is closer to the hardware than the HAL.
Contrary to the HAL, LL APIs are not provided for peripherals where optimized access is not
a key feature.
FLASH No
EXTI Yes
GPIO Yes
DMAXs Yes
System PWR Yes
RCC Yes
Cortex Yes
SYSCFG Yes
(1)
NVIC No (already covered by CMSIS)
ADC Yes
DAC Yes
Analog COMP Yes
OPAMP Yes
DFSDM No
RTC Yes
TIM Yes
Timers LPTIM Yes
HRTIM Yes
WWDG Yes
CRC Yes
CRYP No
Cryptography
HASH No
RNG Yes
I2C Yes
UART/USART/LPUART Yes
Basic connectivity SWPMI Yes
SPI/I2S Yes
SDMMC(SDIO) No
1. NVIC is covered in STM32 SPL by the misc.h/.c driver
The LL APIs reflect exactly the hardware capabilities and provide one-shot operations. The
operations must be called following the programming model described in the microcontroller
line reference manual.
As a result, the LL services do not implement any processing and do not require any
additional memory resources to save their states, counter or data pointers: all the operations
are performed by changing the associated peripheral registers content.
All the Low Layer drivers are called through their physical instances (Peripheral registers
structures mapped on the peripherals base registers) and are given in one module for each
physical peripheral located in a separate header file.
Through what the STM32Cube package provides, there are three categories for an
STM32Cube application:
• HAL application: the application is based solely on HAL drivers and following an
inclusion as highlighted by the blue arrows.
• LL application: Since the LL drivers are standalone. The user can develop his
application using only LL drivers, referring to them only from his source files. Note that
LL drivers cannot include each other but they have to include only the CMSIS device
file. Thus, there is no need for a configuration file, and the user must include the used
drivers in the entry point file on his application.
• MIX application: the application in which the user calls on HAL and LL drivers and uses
both of their APIs to develop his code. Drivers are independent from each other and
there is no interference in their inclusions approaches.
Contrary to the HAL drivers, the low level ones are not built on process model but rather in
simple access operations on registers. Thus, the low level layer has no configuration file.
– Specific Interrupt and Status flags management: handle status and register flags
operations (get, Clear, Enable, Disable) for a single item.
Example: LL_PPP_ClearFlag_XX()
These APIs are provided in the “stm32yyxx_ll_PPP.h”.
• Level 3: Global configuration and initialization functions that cover full standalone
operations on relative peripheral registers which are provided in “stm32yyxx_ll_PPP.c”.
1.3 Summary
Table 4 shows an overall comparison between the STM32 SPL and STM32Cube CMSIS
and drivers components:
The STM32Cube LL drivers offer a new set of inline functions allowing a direct and atomic
register access substituting the code snippets and the standard peripheral driver. Its
independency from the HAL drivers gives the user a standalone usage covering the
supported peripherals and their features with minimal code footprint and memory resources.
A full STM32 SPL to STM32Cube LL migration is therefore feasible.
This section describes how to migrate an application developed based on an STM32 SPL to
an equivalent application deploying STM32Cube LL that could be either on the same target
device or a different STM32 series.
Table 5. Cortex-Mx equivalences between STM32 SPL and CMSIS core driver
STM32 SPL (misc.c/.h) CMSIS (core_cmx.h) Comment
Table 5. Cortex-Mx equivalences between STM32 SPL and CMSIS core driver (continued)
STM32 SPL (misc.c/.h) CMSIS (core_cmx.h) Comment
1- NewState = ENABLE
SCB->SCR |= LowPowerMode;
2- NewState = DISABLE
SCB->SCR &=
(uint32_t)(~(uint32_t)LowPowerMod
e);
void NVIC_SystemLPConfig(uint8_t LowPowerMode: Specifies the new
LowPowerMode, FunctionalState No equivalence mode for the system to enter low
NewState); power mode. This parameter can be
one of the following values:
- NVIC_LP_SEVONPEND: Low
Power SEV on Pend.
- NVIC_LP_SLEEPDEEP: Low
Power DEEPSLEEP request.
- NVIC_LP_SLEEPONEXIT: Low
Power Sleep on Exit.
void
__STATIC_INLINE uint32_t
SysTick_CLKSourceConfig(uint32_t -
SysTick_Config(uint32_t ticks);
SysTick_CLKSource);
LL_RTC_TIME_Config(RTC, LL_RTC_TIME_FORMAT_AM_OR_24,
RTC_TimeStruct.Hours, RTC_TimeStruct.Minutes, RTC_TimeStruct.Seconds);
• No explicit API equivalent on LL. The user need to migrate using direct register
accesses:
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x1000);
↔
SCB->VTOR = 0x08000000U | (0x1000U & 0x1FFFFF80U);
target device within a given STM32 series. This gives user the freedom to even update
the current hardware platform.
Note: The STM32Cube comes with a rich set of examples (varying from 70 to 90 in total) using
either LL drivers only or mixed between LL and HAL, demonstrating how to use the different
peripherals. These examples commonly share the same application scenarios with those
provided by STM32 SPL, which makes it easy for the developer to quickly compare both
solutions and get started with STM32Cube LL.
Figure 4 illustrates the successful migration of an application based on an STM32 SPL
Template project to an STM32Cube Template_LL project.
This section presents the steps for an automatic migration using the SPL2LL-Converter
migration tool. Throughout this section, the user will have an overview about the migration
tool and its features, its series and peripherals coverage and the detailed guidelines to
successfully run it.
• C Parser
Firstly, the tool takes the user's source files as input. Through this module, it allows to
parse and scan them, line by line, and extracts source code.
The tool has the ability to differentiate between a user's comment, resulting in copying
it into the target files as it is, and the actual code.
The STM32 SPL based code is sorted and interpreted under 4 types:
– Literals: grouping the STM32 SPL defines and structures' naming.
– Structures: grouping the different structures fields in STM32 SPL drives.
– Functions: comprising all the functions provided by the STM32 SPL drivers.
– Includes: identifying the files inclusions within the code.
• Database fetcher
Within the package, the STM32 SPL2LL-Converter migration toll comes with a full set
of XML files for the STM32 peripherals supported by the STM32Cube LL drivers. This
set constitutes the XML database that serves as a source from which the migration tool
extract the LL equivalence for the initially parsed code.
The architecture of the database matches the way the previous C Parser module
interprets data.
The fetcher module parses all the database and extracts the matching LL API. It
returns for structures and literals sections only the equivalent expression, and for
features section the STM32Cube LL function naming with the corresponding
commands directing the migration process.
• Command Interpreter
Once a STM32 SPL API has been spotted in the database, the interpreter module
executes the built-in commands provided with the STM32Cube LL equivalent API in
Once execution is done, the console output is printed on the terminal. It represents the
overall details of the tool, the migration project, details about the user files and the reporting
during the process.
The following screenshots present two separate migration scenarios of the previous project:
• The first one is an In-series migration from STM32F4 to STM32F4
• The second is a Cross-series migration from STM32F4 to STM32F30.
The screenshots highlight the different parts of the user display during the migration:
Figure 11. Analogy of user project before and after automatic migration
After execution, the tool keeps the same overall hierarchy as the one of the initial project
and applies some updates. Figure 11 highlights these updates:
• Only source files (.h/.c) are migrated into the new LL project.
• Creation of a "Legacy" folder containing source files required for the migrated APIs not
supported by LL. The "legacy.h/.c" present the STM32 SPL code, "ll_includes.h" is a
part of the "stm32yyxx_conf.h" equivalence after migration and "cmsis_ref.h" contains
the CMSIS includes for all the STM32 series and is required by "legacy.h".
• The migration of "stm32yyxx_conf.h" results its substitution by the files
"stm32yyxx_hal_conf.h" and "ll_includes" for STM32Cube compliancy.
• Creation of a "log.txt" file presenting the global reporting during the migration process.
In case of need for a manual intervention, the user can check the generated log file "log.txt"
in which he can find the printed warnings and use them as guidelines to adjust the LL
source files.
However, when migration is not successful due to unavailable features in the target device,
the user must then intervene by correcting the reported errors.
The STM32 SPL-based application must therefore be aligned to be compatible with the
target present features.
Prerequisites
The user asked to download the latest version of STM32Cube package of target series
where to find the LL and CMSIS drivers.
The initial STM32 SPL based project should be error-free and fully functional, to avoid
unwanted migration troubles and to make it easier for manual updates in case of partial
migration.
Note: User should ensure to reproduce the system clock configuration already
performed in system_stm32yyxx.c by implementing manually the
SystemClock_Config() API in top of migrated main.c file.
6. Add user source files in the project.
7. Add "legacy.c" file available under the generated $Legacy/Src folder.
It is highly recommended to download the latest version of the tool for any potential bug
fixes and behaviours enhancements.
This application makes it faster and easier for users who are non-familiar with command
lines to launch the migration process. It is compatible with Windows, Linux and macOS
operating systems.
The interface is described as follows:
1. List of STM32 series/lines supporting STM32 SPL (source)
2. List of STM32 series/lines supporting STM32Cube LL (destination)
3. Source and Destination Projects paths
4. Browsing buttons for paths
5. Migration start button: calling on migration tool execution
6. Logging window: displaying the migration advancement and final status.
7. Reset button: re-initializing all GUI controls and fields
Before launching the application, you need to install Java RunTime Environment for 1.8.0 or
later.
The user can get the latest version from the Java download web page.
4 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.