HAL LPTIM Functions

LP Timer Initialization/Deinitialization function

group LPTIM_Exported_Functions_Group1

This section provides a set of function allowing to:

Functions

hal_status_t HAL_LPTIM_Init ( hal_lptim_handle_t * hlptim , hal_lptim_t instance )

Initialization function. Initialize the LPTIM handle and associate an instance.

Parameters :
  • hlptim – Pointer to the handler of the LPTIM instance.

  • instance – One of the values of the hal_lptim_t enumeration.

Return values :
  • HAL_OK

  • HAL_INVALID_PARAM – Input parameter is invalid (only if USE_HAL_CHECK_PARAM == 1)

void HAL_LPTIM_DeInit ( hal_lptim_handle_t * hlptim )

Reset function.

Stop all current operations and reset states.

Hence:

.

  • stop the counter

  • disable interrupts / DMA transfers

  • clear status flags

  • set channels’ states to RESET

  • set global state to RESET

Warning

Be careful if you used an external clock to have called HAL_LPTIM_SetConfigInput1() before Deinit!

Parameters :

hlptim – Pointer to the handler of the LPTIM instance.

Return values :
  • HAL_OK – Operation completes successfully

  • HAL_ERROR – In case of timeout.

hal_status_t HAL_LPTIM_SetDMA ( hal_lptim_handle_t * hlptim , hal_lptim_dma_index_t dma_idx , hal_dma_handle_t * hdma )

Link a DMA handle to a DMA request.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • dma_idx – Index of the DMA request.

  • hdma – Pointer to a handle of the DMA instance.

Return values :

HAL_OK – In case of DMA Set correctly.

LP Timer Peripheral State, Error functions

group LPTIM_Exported_Functions_Group2

This group gathers the functions for the states and error management.

This section provides a set of functions for the states and error management.

Functions

hal_lptim_state_t HAL_LPTIM_GetState ( const hal_lptim_handle_t * hlptim )

Get the low power timer state.

Parameters :

hlptim – Pointer to the handler of the LPTIM instance.

Return values :

hal_lptim_state_t – HAL LPTIM state

hal_lptim_channel_state_t HAL_LPTIM_GetChannelState ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get the state of a channel.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – Channel of interest

Return values :

hal_lptim_channel_state_t – LPTIM channel state

uint32_t HAL_LPTIM_GetLastErrorCodes ( const hal_lptim_handle_t * hlptim )

Retrieve the HAL LPTIM Last Errors.

Parameters :

hlptim – Pointer to the handler of the LPTIM instance.

Return values :

uint32_t

HAL LPTIM Bit Mapped Last Errors.

Values can be:

HAL_LPTIM_ERROR_NONE HAL_LPTIM_ERROR_DMA HAL_LPTIM_ERROR_TIMEOUT

LP Timer Timebase configuration and control.

group LPTIM_Exported_Functions_Group3

This group contains the functions used to configure and control the time base unit.

Note

When the clock source is HAL_LPTIM_CLK_ENCODER_SUBMODE_[1|2|3] selection of the sources (2 signals from quadrature encoders) is done with HAL_LPTIM_SetConfigEncoder() .

Functions

hal_status_t HAL_LPTIM_SetConfig ( hal_lptim_handle_t * hlptim , const hal_lptim_config_t * p_config )

Configure the low power timer’s time-base unit.

Note

Writing CNTSTRT or SNGSTRT of the CR register is done in the process function HAL_LPTIM_Start()

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_config – Pointer to the time-base unit configuration structure.

Return values :
  • HAL_OK – Configuration correctly set

  • HAL_ERROR – Set configuration failed.

  • HAL_INVALID_PARAM – Input parameter is invalid (only if USE_HAL_CHECK_PARAM == 1)

void HAL_LPTIM_GetConfig ( const hal_lptim_handle_t * hlptim , hal_lptim_config_t * p_config )

Get the configuration of the low power timer’s time-base unit.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_config – Pointer to a time-base unit configuration structure to fill.

hal_status_t HAL_LPTIM_SetMode ( hal_lptim_handle_t * hlptim , hal_lptim_mode_t mode )

Set the mode of the low power timer’s time-base unit.

Note

Setting the mode on-the-fly is supported by the HW but we are not doing it (i.e. calling HAL_LPTIM_SetMode() is valid only in state HAL_LPTIM_STATE_IDLE.)

Note

Writing CNTSTRT or SNGSTRT of the CR register and TIMEOUT or WAVE of the CFGR register is done in the process function ( HAL_LPTIM_Start() ))

Warning

Calling this function while the clock source is HAL_LPTIM_CLK_ENCODER_SUBMODE_x has no effect.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • mode – Mode in which to run the timer.

Return values :

HAL_OK – Mode set correctly

hal_lptim_mode_t HAL_LPTIM_GetMode ( const hal_lptim_handle_t * hlptim )

Get the mode of the low power timer’s time-base unit.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_mode_t – Mode in which the low power timer runs.

hal_status_t HAL_LPTIM_SetClockSource ( const hal_lptim_handle_t * hlptim , hal_lptim_clk_src_t clk_src )

Set the clock source of the low power timer’s time-base unit.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • clk_src – Clock source of the LPTIM instance.

Return values :

HAL_OK – Clock Source set correctly

hal_lptim_clk_src_t HAL_LPTIM_GetClockSource ( const hal_lptim_handle_t * hlptim )

Get the clock source of the low power timer’s time-base unit.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_clk_src_t – Clock source of the LPTIM instance.

hal_status_t HAL_LPTIM_SetClockSourcePrescaler ( const hal_lptim_handle_t * hlptim , hal_lptim_clk_src_presc_t clk_src_presc )

Set the clock source prescaler of the low power timer.

Note

  • Clock prescaler setting has no effect if the clock source is HAL_LPTIM_CLK_ENCODER_SUBMODE_[1|2|3].

  • The prescaler must not be used (DIV1) when the LPTIM external Input1 is sampled with the internal clock (HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS).

Warning

Setting the clock source prescaler is authorized only if the clock source is HAL_LPTIM_CLK_INTERNAL or HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS (but in this last case it has no effect).

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • clk_src_presc – Clock source prescaler of the LPTIM instance.

Return values :

HAL_OK – Clock Source Prescaler set correctly

hal_lptim_clk_src_presc_t HAL_LPTIM_GetClockSourcePrescaler ( const hal_lptim_handle_t * hlptim )

Get the clock source prescaler of the low power timer.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_clk_src_presc_t – Clock source prescaler of the LPTIM instance.

hal_status_t HAL_LPTIM_SetPeriod ( const hal_lptim_handle_t * hlptim , uint32_t period )

Set the period of the low power timer’s time-base unit.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • period – Period for the time base unit.

Return values :
  • HAL_OK – Period set correctly

  • HAL_ERROR – Set period failed.

uint32_t HAL_LPTIM_GetPeriod ( const hal_lptim_handle_t * hlptim )

Get the period of the low power timer.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Returns :

uint32_t Period Value

hal_status_t HAL_LPTIM_SetRepetitionCounter ( const hal_lptim_handle_t * hlptim , uint32_t repetition_counter )

Set the repetition counter of the low power timer’s time-base unit.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • repetition_counter – Repetition value for the time base unit.

Return values :
  • HAL_ERROR – Set repetitioncounter failed.

  • HAL_OK – Repetition Counter set correctly

uint32_t HAL_LPTIM_GetRepetitionCounter ( const hal_lptim_handle_t * hlptim )

Get the value of the repetition counter of the low power timer.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

uint32_t – Value of the repetition counter.

uint32_t HAL_LPTIM_GetCounter ( const hal_lptim_handle_t * hlptim )

Get Counter Register (LPTIMx_CNT) value.

Warning

When the LPTIM instance is running, reading the LPTIMx_CNT register can return unreliable values. So in this case it is necessary to perform two consecutive read accesses and verify that the two returned values are identical.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

uint32_t – Counter register value.

hal_status_t HAL_LPTIM_ResetCounter ( const hal_lptim_handle_t * hlptim )

Reset Counter Register (LPTIMx_CNT) value.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK – Reset counter done correctly

hal_status_t HAL_LPTIM_EnableResetCounterAfterRead ( const hal_lptim_handle_t * hlptim )

Enable Reset Counter After read, Register (LPTIMx_RSTARE) value.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK – Reset counter after read enabled correctly

hal_status_t HAL_LPTIM_DisableResetCounterAfterRead ( const hal_lptim_handle_t * hlptim )

Disable Reset Counter After read, Register (LPTIMx_RSTARE) value.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK – Reset counter after read disabled correctly

hal_lptim_reset_after_read_status_t HAL_LPTIM_IsEnableResetCounterAfterRead ( const hal_lptim_handle_t * hlptim )

Check Reset Counter After read, Register (LPTIMx_RSTARE) value.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_reset_after_read_status_t – Registers update mode.

hal_status_t HAL_LPTIM_EnablePreload ( const hal_lptim_handle_t * hlptim )

Enable the preload (registers ARR, RCR and CCRx are updated at the end of the current LPTIM period).

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK – Preload enabled correctly

hal_status_t HAL_LPTIM_DisablePreload ( const hal_lptim_handle_t * hlptim )

Disable the preload (registers ARR, RCR and CCR are updated after each APB bus access.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK – Preload disabled correctly

hal_lptim_preload_status_t HAL_LPTIM_IsEnabledPreload ( const hal_lptim_handle_t * hlptim )

Check preload state.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_preload_status_t – Registers update mode.

hal_status_t HAL_LPTIM_SetConfigInput1 ( const hal_lptim_handle_t * hlptim , const hal_lptim_input1_config_t * p_config )

Configure Input1.

Note

When Input1 is used as external clock, configure the clock source as either HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS or HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS).

Warning

- This function must be called only after the clock source is configured.

  • if the clock is HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS but the filter is not HAL_LPTIM_FDIV1, or the polarity is HAL_LPTIM_INPUT1_RISING_FALLING then an auxiliary clock (one of the Low power oscillator) must be active.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_config – Pointer to the input1 configuration structure.

Return values :
  • HAL_OK – Config input 1 has been correctly configured

  • HAL_ERROR – When called with clock source different from HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS or HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS.

void HAL_LPTIM_GetConfigInput1 ( const hal_lptim_handle_t * hlptim , hal_lptim_input1_config_t * p_config )

Get Input1 configuration.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_config – Pointer to the input1 configuration structure to fill.

hal_status_t HAL_LPTIM_SetInput1Source ( const hal_lptim_handle_t * hlptim , hal_lptim_input1_src_t input1_src )

Set Input1 source.

Warning

This function must be called only after the clock source is configured.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • input1_src – Source of Input1.

Return values :
  • HAL_OK – SetInput1Source has been correctly configured

  • HAL_ERROR – When called with clock source different from HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS or HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS.

hal_lptim_input1_src_t HAL_LPTIM_GetInput1Source ( const hal_lptim_handle_t * hlptim )

Get Input1 source.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_input1_src_t – Input1 source.

hal_status_t HAL_LPTIM_SetInput1Polarity ( const hal_lptim_handle_t * hlptim , hal_lptim_input1_polarity_t polarity )

Set Input1 polarity.

Warning

- This function must be called only after the clock source is configured.

  • An auxiliary clock (one of the Low power oscillator) must be active if the polarity is HAL_LPTIM_INPUT1_RISING_FALLING.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • polarity – polarity of Input1.

Return values :
  • HAL_OK – Input 1 Polarity has been correctly configured

  • HAL_ERROR – When called with clock source different from HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS or HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS.

hal_lptim_input1_polarity_t HAL_LPTIM_GetInput1Polarity ( const hal_lptim_handle_t * hlptim )

Get Input1 polarity.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_input1_polarity_t – Input1 active edge(s).

hal_status_t HAL_LPTIM_SetInput1Filter ( const hal_lptim_handle_t * hlptim , hal_lptim_filter_t filter )

Set Input1 filter.

Note

If filtering is used, an auxiliary clock must be active.

Warning

- This function must be called only after the clock source is configured.

  • An auxiliary clock (one of the Low power oscillator) must be active if the value of the filter is different from HAL_LPTIM_FDIV1.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • filter – Filter for Input1.

Return values :
  • HAL_OK – Input 1 Filter has been correctly configured

  • HAL_ERROR – When called with clock source different from HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS or HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS.

hal_lptim_filter_t HAL_LPTIM_GetInput1Filter ( const hal_lptim_handle_t * hlptim )

Get Input1 filter.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Returns :

hal_lptim_filter_t Filter value applied to Input1.

Low power timer starts services functions.

group LPTIM_Exported_Functions_Group4

This section provides a set of function to Start and Stop LPTIM services

Functions

hal_status_t HAL_LPTIM_Start ( hal_lptim_handle_t * hlptim )

Start the low power timer in polling mode.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :
  • HAL_OK – LPTIM has been correctly started

  • HAL_ERROR – When there is a mismatch between the mode and the current clock source.

hal_status_t HAL_LPTIM_Stop ( hal_lptim_handle_t * hlptim )

Stop the low power timer that was started in polling mode.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK – LPTIM has correctly been stopped

hal_status_t HAL_LPTIM_Start_IT ( hal_lptim_handle_t * hlptim )

Start the low power timer in interrupt mode.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :
  • HAL_OK – LPTIM with IT has correctly been start

  • HAL_ERROR – When there is a mismatch between the mode and the current clock source, or when enabling the interrupts failed.

hal_status_t HAL_LPTIM_Stop_IT ( hal_lptim_handle_t * hlptim )

Stop the low power timer that was started in interrupt mode.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :
  • HAL_OK – LPTIM with IT has correctly been stopped

  • HAL_ERROR – When disabling the interrupts failed.

hal_status_t HAL_LPTIM_Start_DMA_Opt ( hal_lptim_handle_t * hlptim , const void * p_data , uint32_t size_byte , uint32_t interrupts )

Start the low power timer in DMA mode.

Warning

HAL_LPTIM_SetDMA() is to be called with the correct DMA index (see hal_lptim_dma_index_t ) before calling this function.

Parameters :
Return values :
  • HAL_OK – LPTIM with DMA has correctly been started

  • HAL_ERROR – Failed to start the DMA transfer.

  • HAL_INVALID_PARAM – Input parameter is invalid (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_Start_DMA ( hal_lptim_handle_t * hlptim , const void * p_data , uint32_t size_byte )

Start the low power timer in DMA mode.

Warning

HAL_LPTIM_SetDMA() is to be called with the correct DMA index (see hal_lptim_dma_index_t ) before calling this function.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_data – Pointer to the data buffer.

  • size_byte – Data buffer size (in bytes).

Return values :
  • HAL_OK – LPTIM with DMA has correctly been started

  • HAL_ERROR – Failed to start the DMA transfer.

  • HAL_INVALID_PARAM – Input parameter is invalid (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_Stop_DMA ( hal_lptim_handle_t * hlptim )

Stop the timer that was started in DMA mode.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK – LPTIM with DMA has correctly been stopped

Low power timer Output Channel functions

group LPTIM_Exported_Functions_Group5

This group contains the functions used to configure and control the output stage of the LP Timer’s capture/compare channels.

Functions

hal_status_t HAL_LPTIM_OC_SetConfigChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , const hal_lptim_oc_config_t * p_config )

Configure the Output channel/Output Compare.

Parameters :
Return values :
  • HAL_OK – LPTIM driver has been correctly configured

  • HAL_INVALID_PARAM – When p_config pointer is NULL

  • HAL_ERROR – When LPTIM driver set pwm failed

void HAL_LPTIM_OC_GetConfigChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_oc_config_t * p_config )

Get the actual configuration.

Parameters :
hal_status_t HAL_LPTIM_OC_SetChannelPolarity ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_oc_polarity_t polarity )

Set output channel’s polarity.

Warning

the channel is supposed to be disabled

Parameters :
  • hlptim – Pointer to a hal_lptim_handle_t

  • channel – Output channel of interest to enable.

  • polarity – output channel’s polarity

Return values :

HAL_OK – LPTIM output channel’s polarity correctly setup

hal_lptim_oc_polarity_t HAL_LPTIM_OC_GetChannelPolarity ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get output channel’s polarity.

Parameters :
Returns :

hal_lptim_oc_polarity_t output channel’s polarity mode

hal_status_t HAL_LPTIM_OC_SetChannelPulse ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , uint32_t pulse )

Set output channel’s pulse.

Parameters :
  • hlptim – Pointer to a hal_lptim_handle_t

  • channel – Output channel of interest to enable.

  • pulse – value pulse width needs to compare it

Return values :
  • HAL_ERROR – if pulse set failed

  • HAL_OK – output channel’s pulse correctly setup

uint32_t HAL_LPTIM_OC_GetChannelPulse ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get output channel’s pulse.

Parameters :
Returns :

uint32_t pulse value from channel number

hal_status_t HAL_LPTIM_OC_StartChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Start a LP-Timer’s output channel in polling mode.

Parameters :
Return values :

HAL_OK – output channel has been correctly started

hal_status_t HAL_LPTIM_OC_StopChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Stop channel LPTIM driver with output channel/output compare.

Parameters :
Return values :

HAL_OK – output channel has been correctly stopped

hal_status_t HAL_LPTIM_OC_StartChannel_IT ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Start channel LPTIM driver output channel/output compare with interrupt.

Parameters :
Return values :
  • HAL_ERROR – No flag has been given

  • HAL_OK – output channel has been correctly started

hal_status_t HAL_LPTIM_OC_StopChannel_IT ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Stop channel LPTIM driver output channel/output compare with interrupt compare.

Parameters :
Return values :
  • HAL_ERROR – No flags have been given

  • HAL_OK – output channel has been correctly stopped

Low Power Timer Input Channel functions.

group LPTIM_Exported_Functions_Group6

This group contains the functions used to configure and control the input stage of the timer’s capture/compare channels.

Functions

hal_status_t HAL_LPTIM_IC_SetConfigChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , const hal_lptim_ic_config_t * p_config )

Configure the Input channel/Input Capture.

Parameters :
Return values :
  • HAL_OK – LPTIM driver has been correctly configured

  • HAL_INVALID_PARAM – When p_config pointer is NULL

  • HAL_ERROR – When LPTIM driver set pwm failed

void HAL_LPTIM_IC_GetConfigChannel ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_ic_config_t * p_config )

Get the Input channel configuration.

Parameters :
hal_status_t HAL_LPTIM_IC_SetChannelSource ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_ic_src_t source )

Set input channel’s source.

Warning

the channel is supposed to be disabled

Parameters :
  • hlptim – Pointer to a hal_lptim_handle_t

  • channel – Output channel of interest to enable.

  • source – input channel’s source

Return values :

HAL_OK – LPTIM input channel’s source correctly setup

hal_lptim_ic_src_t HAL_LPTIM_IC_GetChannelSource ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get input channel’s source.

Warning

the channel is supposed to be disabled

Parameters :
Return values :

hal_lptim_ic_src_t – channel input sources

hal_status_t HAL_LPTIM_IC_SetChannelPolarity ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_ic_polarity_t polarity )

Set input channel’s polarity.

Warning

the channel is supposed to be disabled

Parameters :
  • hlptim – Pointer to a hal_lptim_handle_t

  • channel – Output channel of interest to enable.

  • polarity – input channel’s polarity

Return values :

HAL_OK – LPTIM input channel’s polarity correctly setup

hal_lptim_ic_polarity_t HAL_LPTIM_IC_GetChannelPolarity ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get input channel’s polarity.

Parameters :
Returns :

hal_lptim_ic_polarity_t input channel’s polarity mode

hal_status_t HAL_LPTIM_IC_SetChannelFilter ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_filter_t filter )

Set input channel’s filter.

Warning

the channel is supposed to be disabled

Parameters :
  • hlptim – Pointer to a hal_lptim_handle_t

  • channel – Output channel of interest to enable.

  • filter – input channel’s filter

Return values :

HAL_OK – LPTIM input channel’s filter correctly setup

hal_lptim_filter_t HAL_LPTIM_IC_GetChannelFilter ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get input channel’s filter.

Parameters :
Returns :

hal_lptim_filter_t input channel’s filter mode

hal_status_t HAL_LPTIM_IC_SetChannelPrescaler ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_ic_prescaler_t prescaler )

Set input channel’s prescaler.

Warning

the channel is supposed to be disabled

Parameters :
  • hlptim – Pointer to a hal_lptim_handle_t

  • channel – Output channel of interest to enable.

  • prescaler – input channel’s prescaler

Return values :

HAL_OK – LPTIM input channel’s prescaler correctly setup

hal_lptim_ic_prescaler_t HAL_LPTIM_IC_GetChannelPrescaler ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get input channel’s prescaler.

Parameters :
Returns :

hal_lptim_ic_prescaler_t input channel’s prescaler mode

hal_status_t HAL_LPTIM_IC_StartChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Start channel LPTIM driver with input channel/input capture.

Parameters :
Return values :

HAL_OK – input channel has been correctly started

hal_status_t HAL_LPTIM_IC_StopChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Stop channel LPTIM driver with input channel/input capture.

Parameters :
Return values :

HAL_OK – input channel has been correctly stopped

hal_status_t HAL_LPTIM_IC_StartChannel_IT ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Start channel LPTIM driver input channel/input capture with interrupt.

Parameters :
Return values :
  • HAL_ERROR – No flag has been given

  • HAL_OK – input channel has been correctly started

hal_status_t HAL_LPTIM_IC_StopChannel_IT ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Stop channel LPTIM driver input channel/input capture with interrupt compare.

Parameters :
Return values :
  • HAL_ERROR – No flags have been given.

  • HAL_OK – input channel has been correctly stopped

hal_status_t HAL_LPTIM_IC_StartChannel_DMA ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , const void * p_data , uint32_t size_byte )

Start channel LPTIM driver input channel/input capture with DMA.

Parameters :
  • hlptim – Pointer to a hal_lptim_handle_t

  • channel – Output channel of interest to enable.

  • p_data – pointer to the data buffer

  • size_byte – data buffer size

Return values :
  • HAL_ERROR – No flag has been given

  • HAL_OK – input channel has been correctly started

hal_status_t HAL_LPTIM_IC_StartChannel_DMA_Opt ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , const void * p_data , uint32_t size_byte , uint32_t interrupts )

Start channel LPTIM driver input channel/input capture with DMA.

Parameters :
Return values :
  • HAL_ERROR – No flag has been given

  • HAL_OK – input channel has been correctly started

hal_status_t HAL_LPTIM_IC_StopChannel_DMA ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Stop a timer’s input channel that was started in DMA mode.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – Input Channel of interest.

Return values :

HAL_OK – Input Capture with DMA has correctly been stopped

uint32_t HAL_LPTIM_IC_ReadChannelCapturedValue ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Read value captured of timer’s input channel.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – Input Channel of interest.

Return values :

uint32_t – Value captured of timer’s input channel

Low Power Timer Encoder functions.

group LPTIM_Exported_Functions_Group7

This group contains the functions used to configure the encoder stage of the timer.

Functions

hal_status_t HAL_LPTIM_SetConfigEncoder ( const hal_lptim_handle_t * hlptim , const hal_lptim_encoder_config_t * p_encoder )

Configure the encoder interface.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_encoder – Pointer to the encoder configuration structure.

Return values :

HAL_OK – Configuration correctly set.

void HAL_LPTIM_GetConfigEncoder ( const hal_lptim_handle_t * hlptim , hal_lptim_encoder_config_t * p_encoder )

Get encoder interface configuration.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_encoder – Pointer to the encoder configuration structure.

Config external trigger

group LPTIM_Exported_Functions_Group8

This section provides a set of function to configure external trigger

Functions

hal_status_t HAL_LPTIM_SetConfigExtTrigInput ( const hal_lptim_handle_t * hlptim , const hal_lptim_ext_trig_config_t * p_config )

Configure External Trigger (ETR) input.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_config – Pointer to the ETR configuration structure.

Return values :

HAL_OK – Configuration correctly set.

void HAL_LPTIM_GetConfigExtTrigInput ( const hal_lptim_handle_t * hlptim , hal_lptim_ext_trig_config_t * p_config )

Get the External Trigger (ETR) input configuration.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_config – Pointer to the ETR configuration structure.

hal_status_t HAL_LPTIM_SetExtTrigInputSource ( const hal_lptim_handle_t * hlptim , hal_lptim_ext_trig_src_t source )

Set the External Trigger (ETR) input source.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • source – Source selection for the ETR.

Return values :

HAL_OK – External Trigger Input Src has been configured correctly

hal_lptim_ext_trig_src_t HAL_LPTIM_GetExtTrigInputSource ( const hal_lptim_handle_t * hlptim )

Get the External Trigger (ETR) input source.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_ext_trig_src_t – Source selected for the ETR.

hal_status_t HAL_LPTIM_SetExtTrigInputPolarity ( const hal_lptim_handle_t * hlptim , hal_lptim_ext_trig_polarity_t polarity )

Set the External Trigger (ETR) input polarity.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • polarity – Polarity of the ETR input.

Return values :

HAL_OK – External Trigger Input Polarity has configured correctly

hal_lptim_ext_trig_polarity_t HAL_LPTIM_GetExtTrigInputPolarity ( const hal_lptim_handle_t * hlptim )

Get the External Trigger (ETR) input polarity.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_ext_trig_polarity_t – External trigger polarity.

hal_status_t HAL_LPTIM_SetExtTrigInputFilter ( const hal_lptim_handle_t * hlptim , hal_lptim_filter_t filter )

Set the External Trigger (ETR) input filter.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • filter – Filter the ETR input.

Return values :

HAL_OK – External Trigger Input Filter has configured correctly

hal_lptim_filter_t HAL_LPTIM_GetExtTrigInputFilter ( const hal_lptim_handle_t * hlptim )

Get the External Trigger (ETR) input filter.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_filter_t – Filter value for the ETR input.

Low Power Timer IRQ Handler and Callbacks functions

group LPTIM_Exported_Functions_Group9

This section provides LPTIM IRQ Handler and callback function called within the IRQ Handler

IRQ Handler:

And there register callback:

Functions

void HAL_LPTIM_IRQHandler ( hal_lptim_handle_t * hlptim )

Handler IRQ global.

  • Capture/Compare 1 interrupt

  • Capture/Compare 2 interrupt

  • Compare update interrupt

  • Over Capture 1 & 2 interrupt

  • Autoreload matched interrupt

  • Autoreload update interrupt

  • Trigger detected interrupt

  • Direction counter changed from down to up

  • Direction counter changed from up to down

  • Repetition counter underflowed or == 0 and LPTIM counter overflow

  • Successful APB bus write to repetition counter register

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_CC_IRQHandler ( hal_lptim_handle_t * hlptim )

Handler IRQ for interrupt’s capture and compare.

  • Capture/Compare 1 interrupt

  • Capture/Compare 2 interrupt

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_UPD_IRQHandler ( hal_lptim_handle_t * hlptim )

Handler IRQ for Update interrupt’s.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_TRGI_IRQHandler ( hal_lptim_handle_t * hlptim )

Handler IRQ for trigger and direction change interrupt’s.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_UpdateHalfCpltCallback ( hal_lptim_handle_t * hlptim )

Update Half Complete callback.

Function called when the DMA transfer triggered by the timer update DMA request is half completed.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_ErrorCallback ( hal_lptim_handle_t * hlptim )

DMA Error callback.

This function is called in case of a DMA transfer error.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_StopCallback ( hal_lptim_handle_t * hlptim )

DMA Stop callback.

This function is called after stopping a DMA transfer triggered by the timer update event.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_InputCaptureStopCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

DMA Channel Stop callback.

This function is called after stopping a DMA transfer triggered by a capture/compare event.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – Input Channel of interest.

void HAL_LPTIM_UpdateCallback ( hal_lptim_handle_t * hlptim )

Update callback.

Function called when the timer update interrupt is generated or when the DMA transfer triggered by the timer update DMA request is completed.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_RepUpdateCallback ( hal_lptim_handle_t * hlptim )

Repetition Update Callback.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_TriggerCallback ( hal_lptim_handle_t * hlptim )

Trigger callback.

Function called when the timer trigger interrupt is generated or when the DMA transfer triggered by the timer trigger DMA request is completed.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_InputCaptureCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Input Capture Callback.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – input channel of interest to enable.

void HAL_LPTIM_InputCaptureHalfCpltCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Callback for the DMA Half Complete transfer triggered by an Input Capture event.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – input channel of interest to enable.

void HAL_LPTIM_InputOverCaptureCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Input Over Capture callback.

Function called when an input over capture interrupt is generated.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – input channel of interest to enable.

void HAL_LPTIM_CompareMatchCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Compare match Callback.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – Output channel of interest to enable.

void HAL_LPTIM_CompareUpdateCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Compare update Callback.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – Output channel of interest to enable.

void HAL_LPTIM_AutoReloadMatchCallback ( hal_lptim_handle_t * hlptim )

AutoReload Match callback.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_AutoReloadUpdateCallback ( hal_lptim_handle_t * hlptim )

Autoreload Update callback.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_DirectionUpCallback ( hal_lptim_handle_t * hlptim )

Direction UP callback.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_DirectionDownCallback ( hal_lptim_handle_t * hlptim )

Direction Down callback.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

hal_status_t HAL_LPTIM_RegisterErrorCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the DMA Error.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterStopCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Stop callback.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterChannelStopCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_cb_t fct )

Callback registration for the Channel Stop callback.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterUpdateCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Update Event.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterUpdateHalfCpltCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the DMA Half Complete transfer triggered on Update event.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterRepUpdateCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for Repetition Update.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterTriggerCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Trigger event.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterInputCaptureCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_cb_t fct )

Callback registration for the Input Capture event.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterInputCaptureHalfCpltCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_cb_t fct )

Callback registration for the Input Capture Half Complete.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterOverCaptureCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_cb_t fct )

Callback registration for Over Capture.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterCompareMatchCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_cb_t fct )

Callback registration for the Compare Match.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterCompareUpdateCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_cb_t fct )

Callback registration for the Compare Update.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterAutoReloadUpdateCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Autoreload Update.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterAutoReloadMatchCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Autoreload Match.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterDirectionUpCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Direction UP changes.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterDirectionDownCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Direction Down changes.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

void HAL_LPTIM_CompareMatchHalfCpltCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Low Power Timer Setter and Getter of the user data.

group LPTIM_Exported_Functions_Group10

The user data pointer, *p_user_data, in the HAL LPTIM handle allows user to associate applicative user data to the HAL LPTIM handle. The two functions in this group give an application the possibility to store and retrieve user data pointer into and from the handle.

Functions

void HAL_LPTIM_SetUserData ( hal_lptim_handle_t * hlptim , const void * p_user_data )

Store User Data pointer into the handle.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_user_data – Pointer to the user data.

const void * HAL_LPTIM_GetUserData ( const hal_lptim_handle_t * hlptim )

Retrieve User Data pointer from the handle.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

Pointer – to the user data.

Peripheral clock frequency for LPTIMx

group LPTIM_Exported_Functions_Group11

Get clock frequency depends on instance used.

Functions

uint32_t HAL_LPTIM_GetClockFreq ( hal_lptim_handle_t * hlptim )

Return the peripheral clock frequency for LPTIMx.

Parameters :

hlptim – Pointer to a hal_lptim_handle_t structure

Return values :
  • uint32_t – Frequency in Hz

  • 0 – source clock of the lptimx not configured or not ready