HAL LPTIM How to Use

group LPTIM_How_To_Use

Use the LPTIM HAL driver as follows:

(Non-optional call) Call HAL_LPTIM_Init() to initialize the LPTIM driver by establishing a link with

the LPTIM physical instance.

(Non-optional call) Call HAL_LPTIM_SetConfig() to configure the timebase unit:

If needed, call HAL_LPTIM_DeInit() to reset the driver.

When an external clock is used, configure LPTIM Input1 by calling HAL_LPTIM_SetConfigInput1().

Select the usage:

- To use an LPTIM instance as a simple counter:

- To generate a PWM signal:

- To generate a one-pulse signal:

- To generate a set once signal:

- To capture an input signal:

- To use the LPTIM timeout feature:

- To use the LPTIM encoder interface:

Callbacks definition in interrupt or DMA mode

  • When the compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 1, the user can configure the driver callbacks dynamically using their own method:

Callback name

Default callback

Register callback

ErrorCallback

HAL_LPTIM_ErrorCallback

HAL_LPTIM_RegisterErrorCallback

StopCallback

HAL_LPTIM_StopCallback

HAL_LPTIM_RegisterStopCallback

InputCaptureStopCallback

HAL_LPTIM_InputCaptureStopCallback

HAL_LPTIM_RegisterChannelStopCallback

UpdateCallback

HAL_LPTIM_UpdateCallback

HAL_LPTIM_RegisterUpdateCallback

UpdateHalfCpltCallback

HAL_LPTIM_UpdateHalfCpltCallback

HAL_LPTIM_RegisterUpdateHalfCpltCallback

RepUpdateCallback

HAL_LPTIM_RepUpdateCallback

HAL_LPTIM_RegisterRepUpdateCallback

TriggerCallback

HAL_LPTIM_TriggerCallback

HAL_LPTIM_RegisterTriggerCallback

InputCaptureCallback

HAL_LPTIM_InputCaptureCallback

HAL_LPTIM_RegisterInputCaptureCallback

InputCaptureHalfCpltCallback

HAL_LPTIM_InputCaptureHalfCpltCallback

HAL_LPTIM_RegisterInputCaptureHalfCpltCallback

InputOverCaptureCallback

HAL_LPTIM_InputOverCaptureCallback

HAL_LPTIM_RegisterOverCaptureCallback

CompareMatchCallback

HAL_LPTIM_CompareMatchCallback

HAL_LPTIM_RegisterCompareMatchCallback

CompareUpdateCallback

HAL_LPTIM_CompareUpdateCallback

HAL_LPTIM_RegisterCompareUpdateCallback

AutoReloadMatchCallback

HAL_LPTIM_AutoReloadMatchCallback

HAL_LPTIM_RegisterAutoReloadMatchCallback

AutoReloadUpdateCallback

HAL_LPTIM_AutoReloadUpdateCallback

HAL_LPTIM_RegisterAutoReloadUpdateCallback

DirectionDownCallback

HAL_LPTIM_DirectionDownCallback

HAL_LPTIM_RegisterDirectionDownCallback

DirectionUpCallback

HAL_LPTIM_DirectionUpCallback

HAL_LPTIM_RegisterDirectionUpCallback

To unregister a callback, register the default callback via the registration function.

By default, after HAL_LPTIM_Init() and when the state is HAL_LPTIM_STATE_INIT, all callbacks are set to the corresponding default weak functions.

Callbacks can be registered in the handle global state HAL_LPTIM_STATE_INIT and HAL_LPTIM_STATE_IDLE.

When the compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 0 or is not defined, the callback registration feature is not available and weak callbacks are used, represented by the default value in the table above.

Note

If needed, some configuration parameters can be changed on the fly (e.g., period HAL_LPTIM_SetPeriod()).

Note

If needed, some configuration parameters can be changed on the fly (e.g., PWM duty cycle HAL_LPTIM_OC_SetChannelPulse()).

Note

In case of software start (external trigger not configured), call HAL_LPTIM_Start()

to start the LPTIM counter for one-shot counting.

In one-pulse mode, the output waveform is similar to the PWM mode for the first pulse. Then the output is permanently reset.

Note

If needed, some configuration parameters can be changed on the fly (e.g., PWM duty cycle HAL_LPTIM_OC_SetChannelPulse()).

Note

If needed, some configuration parameters can be changed on the fly (e.g., PWM duty cycle HAL_LPTIM_OC_SetChannelPulse()).

Note

If needed, some configuration parameters can be changed on the fly (e.g., period HAL_LPTIM_SetPeriod()).