HAL LPTIM Overview

Introducing LPTIM

group LPTIM_Introduction

  • STM32 low-power timers (LPTIM) provide ultra-low-power time base generation, periodic events, pulse counting, and low-frequency PWM while the device operates in low-power modes. They enable energy-efficient wake-up scheduling, low-speed signal measurement, and autonomous timing functions in battery-powered and power-constrained embedded systems.

  • The LPTIM HAL driver simplifies the configuration, initialization, and management of low-power timer operations by supporting polling, interrupt, and, where available, DMA modes, enabling flexible and efficient low-power timing control.

  • Additionally, it supports multiple LPTIM instances and features such as encoder mode, one-pulse mode, and external clocking, depending on the STM32 device, ensuring portability and consistency of low-power timing capabilities across different STM32 series.

Module and files

The following diagram illustrates the LPTIM module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the LPTIM module. It shows the interactions between the user application, HAL drivers, low-level drivers, and the hardware components.

@startuml

!$use_ppp_core = 0
!$use_ll_rcc = 0
!$use_ppp_ll = 1
!$use_ppp_hal = 1

!$use_api_itf = 1
!$use_hal_itf = 1
!$use_ll_itf = 1
!$use_core_itf = 1
!$use_hal_generic_dep = 0

!$use_ppp_isr = 1

!$use_hal_service = 0
!$use_hal_rcc = 1
!$use_hal_dma = 1
!$use_kernel_clock = 1

!$core = "XXX" + "_CORE"
!$ppp = "LPTIM"
!$hal_api_itf = "HAL " + $ppp + " API"
!$appli_itf = "User Callback"
!$ppp_name = "HAL_"+$ppp
!$ppp_ISR  = $ppp+" ISR"
!$ll_ppp   = "LL_"+$ppp

!$hal_dma_itf = "HAL_LPTIM_SetDMA()\nHAL_LPTIM_Start_DMA_Opt()\nHAL_LPTIM_Start_DMA()\nHAL_LPTIM_Stop_DMA()"
!if ($use_kernel_clock == 1)
!$hal_rcc_itf = "\t\t\tHAL_RCC_"+$ppp+"_GetClockFreq()\n\t\t\tHAL_RCC_"+$ppp+"_EnableClock()"
!else
!$hal_rcc_itf = "\t\t\tHAL_RCC_"+$ppp+"_EnableClock()"
!endif

!$hal_ppp_itf = "Half transfer complete\nTransfer complete\nError callback"

!$hal_generic_itf = "HAL_GetTick()"

!$ll_ppp_itf = "LL " + $ppp +" API"
!$ppp_xIRQ = $ppp+"x_IRQ"


<style>
componentDiagram {
   arrow {
      FontSize 8
   }
   interface {
      FontSize 8
   }
}
</style>

title $ppp Software Component Diagram

Package "Application Layer" #DarkMagenta {

  component [Appli]
  interface "$appli_itf" as APPLI_Interface
  [Appli] -r- APPLI_Interface
}

package "HAL" #DarkOrange {
    [$ppp_name]
    !if ($use_hal_dma == 1)
      interface "$hal_ppp_itf" as HAL_PPP_Interface
      [$ppp_name] -d- HAL_PPP_Interface
    !endif
    interface "$hal_api_itf" as HAL_PPP_APPLI_Interface
    [$ppp_name] -u- HAL_PPP_APPLI_Interface

    !if ($use_hal_service == 1)
      [HAL_SERVICE]
      interface "$hal_generic_itf" as HAL_Service_Interface
      [HAL_SERVICE] -r- HAL_Service_Interface
      [$ppp_name] -l-( HAL_Service_Interface
    !endif
    !if ($use_hal_generic_dep == 1)
          [HAL_SERVICE]
          [$ppp_name] .r.> [HAL_SERVICE]
    !endif
    !if ($use_hal_dma == 1)
      [HAL_DMA]
      interface "$hal_dma_itf" as HAL_DMA_Interface
      [HAL_DMA] -u- HAL_DMA_Interface
      [HAL_DMA] -u-( HAL_PPP_Interface
      [$ppp_name] --( HAL_DMA_Interface
    !endif
    !if ($use_hal_rcc == 1)
      [HAL_RCC]
      interface "$hal_rcc_itf" as HAL_RCC_Interface
      [HAL_RCC] -l- HAL_RCC_Interface
      [$ppp_name] -r-( HAL_RCC_Interface
    !endif

}

[Appli] -d-( HAL_PPP_APPLI_Interface
[$ppp_name] -u-( APPLI_Interface
!if ($use_ppp_core ==1)
Package "Core Layer" #Lavender{
    [$core]
    interface "core API" as Core_api_itf
    [$core] -u- Core_api_itf
}
[$ppp_name] -d-( Core_api_itf
!endif
package "Low Layer" #Technology {
    [CMSIS-Devices]
    !if ($use_ppp_ll == 1)
      [$ll_ppp]
      interface "$ll_ppp_itf" as LL_PPP_Interface
      [$ll_ppp]  -u- LL_PPP_Interface
    !endif

    !if ($use_ppp_isr == 1)
    interface "$ppp_ISR" as PPP_ISR
    [$ppp_ISR] -U- PPP_ISR
    [$ppp_ISR]
    !endif


    !if ($use_ll_rcc == 1)
      [LL_RCC]
      interface "LL RCC API" as LL_RCC_API
      [LL_RCC] -u- LL_RCC_API
      [HAL_RCC] -d-(LL_RCC_API
    !endif

    !if ($use_hal_dma == 1)
      [DMA ISR]
      interface "DMA ISR" as DMA_ISR
      [DMA ISR] -u- DMA_ISR
    !endif

}

package "HW" #LightCyan {
    [STM32_HW]
    !if ($use_ppp_isr == 1)
      interface "$ppp_xIRQ" as PPPx_IRQ
      [STM32_HW] -u- PPPx_IRQ
    !endif
    !if ($use_hal_dma == 1)
      interface "DMAx_IRQ_Ch" as DMA_IRQ_CH
      [STM32_HW] -u- DMA_IRQ_CH
      [DMA ISR] -d-( DMA_IRQ_CH
      [HAL_DMA] --( DMA_ISR
    !endif
}
!if ($use_ppp_ll == 1)
    [$ppp_name] -d-( LL_PPP_Interface
    [$ll_ppp] .r.> [CMSIS-Devices]: $ppp register def
    [STM32_HW] <.u. [$ll_ppp] : $ppp registers R/W
!else
    !if ($use_ppp_core == 1)
      [$core] .l.> [CMSIS-Devices]: $ppp register def
      [STM32_HW] <.u. [$core] : $ppp registers R/W
    !else
      [$ppp_name] .d.> [CMSIS-Devices]: $ppp register def
      [STM32_HW] <.l. [$ppp_name] : $ppp registers R/W
    !endif
!endif
!if ($use_ppp_isr == 1)
   [$ppp_ISR] -d-( PPPx_IRQ
   [$ppp_name] -d-( PPP_ISR
!endif
!if ($use_ll_rcc == 1)
   [STM32_HW] <.u. [LL_RCC] : RCC registers R/W
!endif


@enduml
*/

Configuration table

The following table lists the configuration defines for the HAL LPTIM module, specifying their locations, default values, and descriptions:

group LPTIM_Configuration_Table

Configuration inside the HAL LPTIM driver:

Config defines

Where

Default value

Note

USE_HAL_LPTIM_MODULE

hal_conf.h

1

Enable the HAL LPTIM module

USE_HAL_LPTIM_REGISTER_CALLBACKS

hal_conf.h

0

Allow the user to define custom callbacks

USE_HAL_LPTIM_CLK_ENABLE_MODEL

hal_conf.h

HAL_CLK_ENABLE_NO

Enable the gating of the peripheral clock

USE_HAL_LPTIM_USER_DATA

hal_conf.h

0

Add user data inside the HAL LPTIM handle

USE_HAL_LPTIM_GET_LAST_ERRORS

hal_conf.h

0

Enable retrieval of the last process error codes

USE_HAL_LPTIM_DMA

hal_conf.h

1

Enable DMA support inside HAL LPTIM

USE_HAL_CHECK_PARAM

hal_conf.h

0

Enable checking of vital parameters at runtime

USE_HAL_MUTEX

hal_conf.h

0

Enable semaphore usage in the HAL driver

USE_HAL_CHECK_PROCESS_STATE

hal_conf.h

0

Enable atomic access to process state checks

USE_ASSERT_DBG_PARAM

PreProc env

NONE

Enable parameter checks for HAL

USE_ASSERT_DBG_STATE

PreProc env

NONE

Enable state checks for HAL