HAL LPTIM Types

Enumerations

group LPTIM_Exported_Types_Group1

Enums

enum hal_lptim_t

HAL LPTIM instance.

Values:

enumerator HAL_LPTIM1

LPTIM1

enum hal_lptim_state_t

HAL LPTIM Global States definition.

Values:

enumerator HAL_LPTIM_STATE_RESET

Peripheral not yet initialized

enumerator HAL_LPTIM_STATE_INIT

Peripheral initialized but not yet configured

enumerator HAL_LPTIM_STATE_IDLE

Peripheral initialized and a global config applied

enumerator HAL_LPTIM_STATE_ACTIVE

Counter is running

enumerator HAL_LPTIM_STATE_ACTIVE_SILENT

Counter is running with Silent DMA mode

enum hal_lptim_channel_state_t

LPTIM Channel States definition.

Values:

enumerator HAL_LPTIM_CHANNEL_STATE_RESET

LPTIM Channel initial state

enumerator HAL_LPTIM_OC_CHANNEL_STATE_IDLE

LPTIM Channel ready for use as output channel

enumerator HAL_LPTIM_OC_CHANNEL_STATE_ACTIVE

An internal process is ongoing on the LPTIM output channel

enumerator HAL_LPTIM_OC_CHANNEL_STATE_ACTIVE_SILENT

An internal process is ongoing on the LPTIM output channel in DMA silent mode.

enumerator HAL_LPTIM_IC_CHANNEL_STATE_IDLE

LPTIM Channel ready for use as input channel

enumerator HAL_LPTIM_IC_CHANNEL_STATE_ACTIVE

An internal process is ongoing on the LPTIM input channel

enumerator HAL_LPTIM_IC_CHANNEL_STATE_ACTIVE_SILENT

An internal process is ongoing on the LPTIM input channel in DMA silent mode.

enum hal_lptim_channel_t

HAL LPTIM Channels identifier definition.

Values:

enumerator HAL_LPTIM_CHANNEL_1

LP Timer input/output channel 1 LPTIM input/output channel 1

enumerator HAL_LPTIM_CHANNEL_2

LP Timer input/output channel 2 LPTIM input/output channel 2

enum hal_lptim_mode_t

HAL LPTIM Counter Mode Configuration. The counter mode configuration lets us select how the counter is started and reset.

  • The counter can be in continuous counting mode or in one-shot counting mode, which defines how the counter is started.

    • Continuous mode: the timer is free-running. The timer is started from a trigger event and never stops until the timer is disabled. This mode is further divided in two submodes:

      • regular: a trigger event starts the counter, and a subsequent external trigger event is discarded.

      • Timeout: the first trigger event starts the timer, any successive trigger event resets the LPTIM counter and the repetition counter and the timer restarts.

    • One-shot mode: the timer starts from a trigger event and stops when an LPTIM update event is generated. This mode is further divided in two submodes:

      • regular: the counter is stopped on an update event once the repetition counter is 0. Then, a subsequent trigger starts a new one-shot counting cycle.

      • Set-once: the counter is only started once following the first trigger, and any subsequent trigger event is discarded.

Note

The waveform on an output channel depends on the counter mode. In one-shot mode, the output waveform is a PWM signal for the duration of the one-shot cycle (that is a pulse waveform, where the number of pulses generated depends on the repetition counter). In set-once mode, there is only one one-shot cycle. At the end of the counting period, the output level is frozen according to the configured polarity. To obtain a typical (continuous) PWM signal on an output channel, the continuous counting mode must be selected.

Values:

enumerator HAL_LPTIM_ONE_SHOT

One-shot. When the counter is stopped, a trigger event starts it. The counter is stopped on an update event. 0x00000002 Timer start in single mode LP Timer starts in single mode.

enumerator HAL_LPTIM_SET_ONCE

Set-once. A first trigger event starts the counter for a single one-shot cycle.

enumerator HAL_LPTIM_CONTINUOUS

Continuous. The timer is started from a trigger event and never stops until it is disabled. 0x00000004 Timer start in continuous mode LP Timer starts in continuous mode.

enumerator HAL_LPTIM_TIMEOUT

Timeout. Similar to ‘Continuous’ mode, except that any new trigger after the start resets the counter.

Note

The value for the timeout is set using HAL_LPTIM_OC_SetConfigChannel() or HAL_LPTIM_OC_SetChannelPulse().

enum hal_lptim_ic_src_t

HAL LPTIM input channel sources.

Values:

enumerator HAL_LPTIM_INPUT_GPIO

connected to GPIO

enumerator HAL_LPTIM_INPUT_LSI

connected to LSI

enumerator HAL_LPTIM_INPUT_LSE

connected to LSE

enumerator HAL_LPTIM_INPUT_COMP1_OUT

connected to COMP1

enumerator HAL_LPTIM_INPUT_MCO1

connected to MCO1

enumerator HAL_LPTIM_INPUT_RCC_HSE_1MHZ

connected to RCC_HSE_1MHZ

enumerator HAL_LPTIM_INPUT_EVENTOUT

connected to Eventout

enum hal_lptim_clk_src_presc_t

HAL LPTIM Clock Source Prescaler definition.

Note

In encoder mode the prescaler division factor must be set to 1.

Values:

enumerator HAL_LPTIM_CLK_SRC_DIV1

Prescaler division factor is set to 1 Prescaler division factor is set to 1.

enumerator HAL_LPTIM_CLK_SRC_DIV2

Prescaler division factor is set to 2 0x00000200 Prescaler division factor is set to 2.

enumerator HAL_LPTIM_CLK_SRC_DIV4

Prescaler division factor is set to 4 0x00000400 Prescaler division factor is set to 4.

enumerator HAL_LPTIM_CLK_SRC_DIV8

Prescaler division factor is set to 8 Prescaler division factor is set to 8.

enumerator HAL_LPTIM_CLK_SRC_DIV16

Prescaler division factor is set to 16 0x00000800 Prescaler division factor is set to 16.

enumerator HAL_LPTIM_CLK_SRC_DIV32

Prescaler division factor is set to 32 Prescaler division factor is set to 32.

enumerator HAL_LPTIM_CLK_SRC_DIV64

Prescaler division factor is set to 64 Prescaler division factor is set to 64.

enumerator HAL_LPTIM_CLK_SRC_DIV128

Prescaler division factor is set to 128 0x00000E00 PRESC[2:0] bits (Clock prescaler) Prescaler division factor is set to 128.

enum hal_lptim_input1_polarity_t

HAL LPTIM Input1 (IN1) Polarity definition. When LPTIM_IN1 is used as an external clock source (HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS or HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS), the active edge of the signal can be selected.

Note

For encoder mode the polarity of Input1 is configured by selecting the encoder submode (HAL_LPTIM_CLK_ENCODER_SUBMODE_[1|2|3]).

Note

If both edges are configured to be active, an internal clock signal must also be provided.

Values:

enumerator HAL_LPTIM_INPUT1_RISING

The rising edge is the active edge used for counting The rising edge is the active edge used for counting

enumerator HAL_LPTIM_INPUT1_FALLING

The falling edge is the active edge used for counting 0x00000002 The falling edge is the active edge used for counting

enumerator HAL_LPTIM_INPUT1_RISING_FALLING

Both edges are active edges. This is valid only if an internal clock is provided. That is, the clock source is HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS. The internal clock signal frequency must be at least four times higher than the external clock signal frequency. 0x00000004 Both edges are active edges

enum hal_lptim_input1_src_t

HAL LPTIM Input1 source definition.

When LPTIM is clocked by an external clock signal injected on LPTIM_IN1 or configured in Encoder mode, it is possible to select the source connected to Input1. (

HAL_LPTIM_SetInput1Source()).

Values:

enumerator HAL_LPTIM_INPUT1_GPIO

For LPTIM1

enumerator HAL_LPTIM_INPUT1_COMP1_OUT

0x00000001 For LPTIM1

enum hal_lptim_input2_src_t

HAL LPTIM Input2 source definition.

When LPTIM is configured in Encoder mode, it is possible to select the source connected to Input2 using

the function that configures the encoder ( HAL_LPTIM_SetConfigEncoder()).

Values:

enumerator HAL_LPTIM_INPUT2_GPIO

For LPTIM1

enum hal_lptim_clk_src_t

HAL LPTIM Clock Source selection.

Values:

enumerator HAL_LPTIM_CLK_INTERNAL

LPTIM is clocked by an internal clock source (APB clock or any of the embedded oscillators).

The counter is incremented following each internal clock pulse.

enumerator HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS

The LPTIM external Input1 is sampled with the internal clock (APB clock or any of the embedded oscillators) provided to the LPTIM.

It is possible to configure the external clock source (Input1 signal conditioning) through dedicated functions:

enumerator HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS

The signal injected on the LPTIM external Input1 is used as the system clock for the LPTIM.

It is possible to configure the external clock source (Input1 signal conditioning) through dedicated functions:

Note

If the polarity is configured on ‘both edges’, or if filtering is used, an auxiliary clock (one of the low-power oscillators) must be active. 0x00000001 Clock selector LPTIM is clocked by an external clock source through the LPTIM external Input1

enumerator HAL_LPTIM_CLK_ENCODER_SUBMODE_1

Quadrature encoder sub-mode 1: rising edge is the active edge.

Count Down when:

  • a rising edge on Input1 when Input2 is high

  • a rising edge on Input2 when Input1 is low

Count Up when:

  • a rising edge on Input1 when Input2 is low

  • a rising edge on Input2 when Input1 is high

enumerator HAL_LPTIM_CLK_ENCODER_SUBMODE_2

Quadrature encoder sub-mode 2: falling edge is the active edge.

Count Down when:

  • a falling edge on Input1 when Input2 is low

  • a falling edge on Input2 when Input1 is high

Count Up when:

  • a falling edge on Input1 when Input2 is high

  • a falling edge on Input2 when Input1 is low

enumerator HAL_LPTIM_CLK_ENCODER_SUBMODE_3

Quadrature encoder sub-mode 3: both edges are active.

Count Down with:

  • a rising edge on Input1 when Input2 is high

  • a rising edge on Input2 when Input1 is low

  • a falling edge on Input1 when Input2 is low

  • a falling edge on Input2 when Input1 is high

Count Up with:

  • a rising edge on Input1 when Input2 is low

  • a rising edge on Input2 when Input1 is high

  • a falling edge on Input1 when Input2 is high

  • a falling edge on Input2 when Input1 is low

enum hal_lptim_dma_index_t

LPTIM DMA Handle Index.

Values:

enumerator HAL_LPTIM_DMA_ID_UPDATE

Index of the DMA handle used for Update DMA requests

enumerator HAL_LPTIM_DMA_ID_CC1

Index of the DMA handle used for input capture event 1 DMA requests

enumerator HAL_LPTIM_DMA_ID_CC2

Index of the DMA handle used for input capture event 2 DMA requests

enum hal_lptim_ext_trig_src_t

HAL LPTIM External Trigger Selection.

Values:

enumerator HAL_LPTIM_EXT_TRIG_GPIO

External input trigger is connected to TIMx_ETR input

enumerator HAL_LPTIM_EXT_TRIG_RTC_ALRA_TRG

External input trigger is connected to RTC Alarm A

enumerator HAL_LPTIM_EXT_TRIG_RTC_ALRB_TRG

External input trigger is connected to RTC Alarm B

enumerator HAL_LPTIM_EXT_TRIG_TAMP_TRG1

External input trigger is connected to RTC Tamper 1

enumerator HAL_LPTIM_EXT_TRIG_TAMP_TRG2

External input trigger is connected to RTC Tamper 2

enumerator HAL_LPTIM_EXT_TRIG_LPDMA_CH1_TC

External input trigger is connected to GPDMA CH1 transfer complete

enumerator HAL_LPTIM_EXT_TRIG_COMP1_OUT

External input trigger is connected to COMP1 output

enumerator HAL_LPTIM_EXT_TRIG_EVENTOUT

External input trigger is connected to EventOUT

enum hal_lptim_ext_trig_polarity_t

HAL LPTIM External Trigger Polarity.

Values:

enumerator HAL_LPTIM_TRIG_RISING

LPTIM counter starts when a rising edge is detected 0x00020000 LPTIM counter starts when a rising edge is detected

enumerator HAL_LPTIM_TRIG_FALLING

LPTIM counter starts when a falling edge is detected 0x00040000 LPTIM counter starts when a falling edge is detected

enumerator HAL_LPTIM_TRIG_RISING_FALLING

LPTIM counter starts when a rising or a falling edge is detected 0x00060000 TRIGEN[1:0] bits (Trigger enable and polarity) LPTIM counter starts when a rising or a falling edge is detected

enum hal_lptim_filter_t

HAL LPTIM Digital Filter definition. The LPTIM inputs, either external (connected to GPIOs) or internal (connected to other built-in peripherals), are protected by digital filters that prevent glitches and noise perturbations from propagating inside the LPTIM.

The digital filters are divided into three groups:

  • The first group of digital filters protects the LPTIM internal or external inputs. The digital filter sensitivity is controlled by the CKFLT bits,

  • The second group of digital filters protects the LPTIM internal or external trigger inputs. The digital filter sensitivity is controlled by the TRGFLT bits.

  • The third group of digital filters protects the LPTIM internal or external input captures. The digital filter sensitivity is controlled by the ICxF bits.

Note

Internal clock signal must be provided to the LPTIM.

Values:

enumerator HAL_LPTIM_FDIV1

No filter

enumerator HAL_LPTIM_FDIV1_N2

Active level change must be stable for at least 2 clock periods before it is considered a valid level.

enumerator HAL_LPTIM_FDIV1_N4

Active level change must be stable for at least 4 clock periods before it is considered a valid level.

enumerator HAL_LPTIM_FDIV1_N8

Active level change must be stable for at least 8 clock periods before it is considered valid.

enum hal_lptim_preload_status_t

HAL LPTIM Preload Status. When preload is enabled, the update of the autoreload and repetition counter of the compare values is done at the end of the current period.

Note

If the repetition counter is used, preload must be enabled; otherwise, unpredictable behavior can occur.

Values:

enumerator HAL_LPTIM_PRELOAD_DISABLED

LPTIMx ARR/RCR/CCRx registers are not preloaded. Registers are updated after each APB bus write access. Preload is disabled: registers are updated after each APB bus write access.

enumerator HAL_LPTIM_PRELOAD_ENABLED

LPTIMx ARR/RCR/CCRx registers are preloaded. Registers are updated at next LPTIM update event, if the timer has been already started. 0x00400000 Reg update mode Preload is enabled: registers are updated at the end of the current LPTIM period.

enum hal_lptim_reset_after_read_status_t

HAL LPTIM Reset counter after read Status. When reset counter after read is enabled, the counter is reset after each HAL_LPTIM_GetCounter call.

Values:

enumerator HAL_LPTIM_RESET_AFTER_READ_DISABLED
enumerator HAL_LPTIM_RESET_AFTER_READ_ENABLED
enum hal_lptim_oc_polarity_t

HAL LPTIM Output Channel Polarity.

Values:

enumerator HAL_LPTIM_OC_HIGH

Output Channel active high. The LPTIM output reflects the compare results between LPTIM_ARR and LPTIM_CCRx registers. The LPTIM output reflects the compare results between LPTIMx_ARR and LPTIMx_CCRx registers.

enumerator HAL_LPTIM_OC_LOW

Output Channel active low. The LPTIM output reflects the inverse of the compare results between LPTIMx_ARR and LPTIMx_CCx registers. 0x00000004 The LPTIM output reflects the inverse of the compare results between LPTIMx_ARR and LPTIMx_CCx registers.

enum hal_lptim_ic_polarity_t

HAL LPTIM Input Channel Polarity.

Values:

enumerator HAL_LPTIM_IC_RISING

Rising edges are detected on the input channel. Capture/Compare input rising polarity.

enumerator HAL_LPTIM_IC_FALLING

Falling edges are detected on the input channel. 0x00000004 Capture/Compare input falling polarity.

enumerator HAL_LPTIM_IC_RISING_FALLING

Both rising and falling edges are detected on the input channel. Capture/Compare input rising and falling polarities.

enum hal_lptim_ic_prescaler_t

HAL LPTIM Input Channel Prescaler.

Values:

enumerator HAL_LPTIM_IC_DIV1

Capture is performed each time an edge is detected on the input channel. Capture performed each time an edge is detected on the capture input.

enumerator HAL_LPTIM_IC_DIV2

Capture is performed once every 2 events. 0x00000100 Capture performed once every 2 events.

enumerator HAL_LPTIM_IC_DIV4

Capture is performed once every 4 events. 0x00000200 Capture performed once every 4 events.

enumerator HAL_LPTIM_IC_DIV8

Capture is performed once every 8 events. Capture performed once every 8 events.

Structures

group LPTIM_Exported_Types_Group2

Typedefs

typedef struct hal_lptim_handle_s hal_lptim_handle_t

Typedef for HAL LPTIM time-base handle type declaration.

typedef void ( * hal_lptim_cb_t ) ( hal_lptim_handle_t * )

HAL LPTIM generic callback pointer definition

typedef void ( * hal_lptim_channel_cb_t ) ( hal_lptim_handle_t * , hal_lptim_channel_t )

HAL LPTIM callback pointer definition with channel parameter

struct hal_lptim_handle_s
#include <stm32c5xx_hal_lptim.h>

HAL LPTIM time-base handle structure definition.

Public Members

hal_lptim_t instance

HAL LPTIM instance

hal_lptim_mode_t mode

LPTIM mode

volatile hal_lptim_state_t global_state

LPTIM global state

hal_dma_handle_t * hdma [ 3U ]

DMA handlers array. (Handlers can be indexed with hal_lptim_dma_index_t)

volatile hal_lptim_channel_state_t channel_states [ 2U ]

LPTIM channels state array

const void * p_user_data

User data pointer.

volatile uint32_t last_error_codes

Store last error codes.

hal_lptim_cb_t error_callback

LPTIM Error callback

hal_lptim_cb_t stop_callback

LPTIM Update DMA stop callback

hal_lptim_channel_cb_t input_capture_stop_callback

LPTIM capture/compare DMA stop callback

hal_lptim_cb_t update_callback

LPTIM Update callback

hal_lptim_cb_t update_half_cplt_callback

LPTIM update half-complete callback.

hal_lptim_cb_t auto_reload_update_callback

LPTIM auto-reload update callback

hal_lptim_cb_t auto_reload_match_callback

LPTIM auto-reload match callback

hal_lptim_cb_t rep_update_callback

LPTIM repetition update callback

hal_lptim_cb_t trigger_callback

LPTIM Trigger callback

hal_lptim_channel_cb_t compare_match_callback

LPTIM Compare Match callback

hal_lptim_channel_cb_t compare_update_callback

LPTIM Compare Update callback

hal_lptim_channel_cb_t input_capture_callback

LPTIM Input Capture callback

hal_lptim_channel_cb_t input_capture_half_cplt_callback

LPTIM Input Capture Half Complete callback

hal_lptim_channel_cb_t input_over_capture_callback

Over-capture callback

hal_lptim_cb_t direction_up_callback

LPTIM Direction up change callback

hal_lptim_cb_t direction_down_callback

LPTIM Direction down change callback

struct hal_lptim_input1_config_t
#include <stm32c5xx_hal_lptim.h>

HAL LPTIM Input1 configuration structure definition.

Public Members

hal_lptim_input1_src_t src

Select the source connected to Input1.

hal_lptim_input1_polarity_t polarity

Select the active edge(s) of the signal.

hal_lptim_filter_t filter

Select a digital filter protection.

struct hal_lptim_ic_config_t
#include <stm32c5xx_hal_lptim.h>

LPTIM input channel configuration structure definition.

Public Members

hal_lptim_ic_src_t source

Specify source selected for IC channel.

hal_lptim_ic_polarity_t polarity

Specify the active edge of the input signal.

hal_lptim_filter_t filter

Specify the input channel filter.

hal_lptim_ic_prescaler_t prescaler

Specify the input channel prescaler.

struct hal_lptim_oc_config_t
#include <stm32c5xx_hal_lptim.h>

HAL LPTIM output channel configuration.

Public Members

uint32_t pulse

Duration (in clock cycles) of the pulse generated on the output channel.

hal_lptim_oc_polarity_t polarity

Polarity of the output channel

struct hal_lptim_ext_trig_config_t
#include <stm32c5xx_hal_lptim.h>

HAL LPTIM external trigger configuration structure definition.

Public Members

hal_lptim_ext_trig_src_t source

Specify the external trigger input source.

hal_lptim_ext_trig_polarity_t polarity

Specify the external trigger input polarity.

hal_lptim_filter_t filter

Specify the external trigger input filter (Trigger Sample Time).

struct hal_lptim_encoder_config_t
#include <stm32c5xx_hal_lptim.h>

HAL LPTIM encoder configuration structure definition.

When the low-power timer (LPTIM) is configured in encoder mode, it operates as follows:

  • External Input Signals: The LPTIM uses two external input signals, referred to as Input1 and Input2.

  • Clock Signal Generation: These input signals generate a clock signal that is used to clock the LPTIM counter. The clock source is specified by the parameter HAL_LPTIM_CLK_ENCODER_SUBMODE_[1|2|3].

  • Quadrature Encoder Signals: The two signals from quadrature encoders can be filtered to ensure accurate counting and noise reduction.

Public Members

hal_lptim_input1_src_t input1

Selection of the first input of the encoder.

hal_lptim_input2_src_t input2

Selection of the second input of the encoder.

hal_lptim_filter_t filter

Filter for the encoder inputs.

Note

The digital filter sensitivity is controlled by groups. Therefore, it is not possible to configure each digital filter sensitivity separately for Input1 and Input2.

struct hal_lptim_config_t
#include <stm32c5xx_hal_lptim.h>

HAL LPTIM time-base configuration structure definition.

Public Members

hal_lptim_clk_src_t clock_source

Clock selection.

Specify the source of the clock feeding the timer’s prescaler.

hal_lptim_mode_t mode

Counter mode selection.

Specify how the counter counts.

hal_lptim_clk_src_presc_t prescaler

Specify the prescaler value used to divide the LPTIM clock.

This parameter is valid only if the clock is either HAL_LPTIM_CLK_INTERNAL or HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS (for the latter, it has no effect).

When the clock is HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS the prescaler division factor is set to 1. In encoder mode (HAL_LPTIM_CLK_ENCODER_SUBMODE_[1|2|3]) the prescaler division factor is set to 1.

uint32_t period

Specify the period value to be loaded into the active auto-reload register.

This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF.

uint32_t repetition_counter

Specify the repetition counter value.

If the repetition counter is used, the update event (UEV) is generated after upcounting is repeated for the number of times programmed in the repetition counter register (RCR).

Otherwise, the update event is generated at each counter overflow. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF.

Warning

When using the repetition counter with PRELOAD = 0, the LPTIM_RCR register must be changed at least five counter cycles before the autoreload match event; otherwise, unpredictable behavior can occur. Therefore, it is strongly advised to enable preload in order to avoid unpredictable behavior when using the repetition counter.