Overview of STM32L4 Low Layer (LL) library

When developing embedded applications on STM32 MCU with STM32Cube, several tools and software libraries are provided. In addition to the CMSIS software layer (for the Cortex M4 core), two types of software libraries are provided: High Abstraction Layer (HAL) and Low Layer (LL). The purpose of this page is to give a brief overview of the LL library. While HAL offers high-level, high-portability APIs, which hide the MCU and peripheral complexity, LL provides low-level APIs at register level. In spite of a lower portability, it ensures a better optimization which is essential to optimize the energy consumption ! As LL library is close to the MCU register level, it require deep knowledge of the MCU and peripheral specifications. The reading of the reference manual of the MCU is mandatory ( Reference manual of STM32L476).

The STM32Cube MCU Package for STM32L4 series (STM32CubeL4) can be downloaded here.

All the information about LL contents (functions, defines, macros) can be found in the User manual "Description of STM32L4/L4+ HAL and low-layer drivers".

Organization of LL library

The low-layer drivers provide hardware services based on the available features of the STM32 peripherals. These services reflect exactly the hardware capabilities and provide one-shot operations. All the operations are performed by changing the associated peripheral registers content. The LL drivers aim at: The low-layer drivers are built around header and C files (one per each supported peripheral "ppp") plus five header files for some System and Cortex related features. File name follows the nomenclature: stm32l4xx_ll_ppp.c/.h, where ppp is related to the peripheral. Details of the five header files are given in the following table:

FileDecription
stm32l4xx_ll_bus.hh-source file for core bus control and peripheral clock activation and deactivation
stm32l4xx_ll_cortex.hCortex-M related register operation APIs including the Systick, Low power (LL_SYSTICK_xxxxx, LL_LPM_xxxxx "Low Power Mode" ...)
stm32l4xx_ll_utils.h/.cgeneric APIs: Read of device unique ID and electronic signature, timebase and delay management, system clock configuration.
stm32l4xx_ll_system.hSystem related operations (e.g. LL_SYSCFG_xxx, LL_DBGMCU_xxx and LL_FLASH_xxx and LL_VREFBUF_xxx)
stm32_assert_template.hThis file is required only when the LL drivers are used in standalone mode (without calling the HAL APIs). It should be copied to the application folder and renamed to stm32_assert.h.

The files stm32l4xx_ll_ppp.c/.h offer a set of inline functions for direct atomic register access, with the format: __STATIC_INLINE return_type LL_PPP_Function (PPPx_TypeDef *PPPx, args). The “Function” naming is defined depending to the action category:

The main APIs for the Low Power software lab

The following table gives brief details about the most important driver files for the project. All the details about the provided functions and defines are given in the mentioned chapter of the User Manual of LL library.

PeripheralDriver filesBrief decription
LL BUS Generic Driverstm32l4xx_ll_bus.h (chapter 81)Functions to enable/disable the different peripheral clock buses of the MCU (AHB, APB) according to the Run/low power mode.
Example: LL_APB1_GRP1_EnableClock( LL_APB1_GRP1_PERIPH_PWR ): to enable the clock (APB1 clock bus) on the power control system (low power mode management, supervision, voltage scaling…)
LL Cortex Driverstm32l4xx_ll_cortex.h (Chapter 83)Generic APIs that can be used, among others, to configure SYSTICK timer or low power modes (LPM).
Example: LL_LPM_EnableSleep() : to activate sleep mode as low-power mode for the processor.
LL GPIO Driverstm32l4xx_ll_gpio.h/.c (chapter 91)Functions to configure GPIOs (pin mode, output type, pull-up/down, alternate function…), set and reset output pin or port.
Example: __STATIC_INLINE void LL_GPIO_SetPinMode (GPIO_TypeDef * GPIOx, uint32_t Pin, uint32_t Mode): to set the mode of a GPIO pin of a dedicated port.
Example: __STATIC_INLINE void LL_GPIO_SetOutputPin (GPIO_TypeDef * GPIOx, uint32_t PinMask): set GPIO pin to ‘1’.
LL Power Generic Driverstm32l4xx_ll_pwr.h/.c (chapter 98)Configuration of the power control module, especially the run and low-power modes, the regulator voltage scaling and the power of backup domain.
Example: __STATIC_INLINE void LL_PWR_SetPowerMode (uint32_t LowPowerMode): to set the low power mode (STOP0/1/2, STANDBY, SHUTDOWN). It does not force the entry in low power mode !
LL RCC (Reset and Clock Control) Generic Driverstm32l4xx_ll_rcc.h/.c (chapter 99)Configuration of reset and clock control module: activate/configure oscillators, PLL, set clock sources of peripheral clocks, prescalers of clock buses, MSI calibration, enable/disable RTC, backup domain reset…
Example: __STATIC_INLINE void LL_RCC_SetSysClkSource (uint32_t Source): configure the system clock source.
Example: __STATIC_INLINE void LL_RCC_MSI_SetRange (uint32_t Range): set the frequency range of the MSI oscillator.
LL RTC Generic Driverstm32l4xx_ll_rtc.h/.c (chapter 101)Configuration of the RTC: initialization mode, enable/disable write protection, set prescaler, wakeup configuration, date, hour and alarm configuration.
Example: __STATIC_INLINE void LL_RTC_EnableInitMode (RTC_TypeDef * RTCx): Enable initialization mode of RTC, to configure prescaler, date and hour.