libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
LPTIM peripheral API
Collaboration diagram for LPTIM peripheral API:

Functions

void lptimer_set_counter (uint32_t lptimer_peripheral, uint16_t count)
 Set lptimer Counter. More...
 
uint16_t lptimer_get_counter (uint32_t lptimer_peripheral)
 Read lptimer Counter. More...
 
void lptimer_clear_flag (uint32_t lptimer_peripheral, uint32_t flag)
 Clear lptimer Status Flag. More...
 
bool lptimer_get_flag (uint32_t lptimer_peripheral, uint32_t flag)
 Read lptimer Status Flag. More...
 
void lptimer_enable_irq (uint32_t lptimer_peripheral, uint32_t irq)
 Enable lptimer interrupts. More...
 
void lptimer_disable_irq (uint32_t lptimer_peripheral, uint32_t irq)
 Disable lptimer Interrupts. More...
 
void lptimer_enable (uint32_t lptimer_peripheral)
 Enable lptimer. More...
 
void lptimer_disable (uint32_t lptimer_peripheral)
 Disable lptimer. More...
 
void lptimer_start_counter (uint32_t lptimer_peripheral, uint32_t mode)
 Start lptimer in a given mode. More...
 
void lptimer_set_prescaler (uint32_t lptimer_peripheral, uint32_t prescaler)
 Set lptimer clock prescaler. More...
 
void lptimer_enable_trigger (uint32_t lptimer_peripheral, uint32_t trigen)
 Enable lptimer External Trigger. More...
 
void lptimer_select_trigger_source (uint32_t lptimer_peripheral, uint32_t trigger_source)
 Select lptimer Trigger Source. More...
 
void lptimer_set_compare (uint32_t lptimer_peripheral, uint16_t compare_value)
 Set lptimer counter Compare Value. More...
 
void lptimer_set_period (uint32_t lptimer_peripheral, uint16_t period_value)
 Set lptimer period. More...
 
void lptimer_enable_preload (uint32_t lptimer_peripheral)
 Enable lptimer Preload mode. More...
 
void lptimer_disable_preload (uint32_t lptimer_peripheral)
 Disable lptimer Preload mode. More...
 
void lptimer_set_internal_clock_source (uint32_t lptimer_peripheral)
 Set lptimer Internal Clock source. More...
 
void lptimer_set_external_clock_source (uint32_t lptimer_peripheral)
 Set lptimer External Clock source. More...
 
void lptimer_set_waveform_polarity_high (uint32_t lptimer_peripheral)
 Set lptimer Waveform Output Polarity High. More...
 
void lptimer_set_waveform_polarity_low (uint32_t lptimer_peripheral)
 Set lptimer Waveform Output Polarity Low. More...
 

Detailed Description

Author
© 2019 Guillaume Revaillot g.rev.nosp@m.aill.nosp@m.ot@gm.nosp@m.ail..nosp@m.com
Date
2 July 2019

LGPL License Terms libopencm3 License

Basic LPTIMER handling API.

Example: LPTIM1 with 2x clock prescaler, from internal clock (LSE), irq on match and reload.

rcc_set_peripheral_clk_sel(LPTIM1, RCC_CCIPR_LPTIM1SEL_LSE);
nvic_enable_irq(NVIC_LPTIM1_IRQ);
void nvic_enable_irq(uint8_t irqn)
NVIC Enable Interrupt.
Definition: nvic.c:57
#define LPTIM_CFGR_TRIGEN_SW
#define LPTIM_CFGR_PRESC_2
#define LPTIM_CR_CNTSTRT
CNGSTRT: Start in Continuous Mode.
#define LPTIM_IER_CMPMIE
LPTIM_IER_CMPMIE Compare match Interrupt Enable.
#define LPTIM_IER_ARRMIE
LPTIM_IER_ARRMIE Autoreload match Interrupt Enable.
#define LPTIM1
Definition: f4/lptimer.h:38
void lptimer_start_counter(uint32_t timer_peripheral, uint32_t mode)
Start lptimer in a given mode.
void lptimer_enable_irq(uint32_t timer_peripheral, uint32_t irq)
Enable lptimer interrupts.
void lptimer_set_internal_clock_source(uint32_t timer_peripheral)
Set lptimer Internal Clock source.
void lptimer_enable_trigger(uint32_t lptimer_peripheral, uint32_t trigen)
Enable lptimer External Trigger.
void lptimer_set_prescaler(uint32_t timer_peripheral, uint32_t prescaler)
Set lptimer clock prescaler.
void lptimer_set_period(uint32_t lptimer_peripheral, uint16_t period_value)
Set lptimer period.
void lptimer_set_compare(uint32_t timer_peripheral, uint16_t compare_value)
Set lptimer counter Compare Value.
void lptimer_enable(uint32_t timer_peripheral)
Enable lptimer.
void rcc_periph_clock_enable(enum rcc_periph_clken clken)
Enable Peripheral Clock in running mode.

Note: LPTIM internal clock source selection is device specific, see clock tree and rcc section of reference manual.

Function Documentation

◆ lptimer_clear_flag()

void lptimer_clear_flag ( uint32_t  lptimer_peripheral,
uint32_t  flag 
)

Clear lptimer Status Flag.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)
[in]flagStatus Register clear flag (LPTIM_ICR Interrupt Clear Register)

Definition at line 90 of file lptimer_common_all.c.

References LPTIM_ICR.

◆ lptimer_disable()

void lptimer_disable ( uint32_t  lptimer_peripheral)

Disable lptimer.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)

Definition at line 141 of file lptimer_common_all.c.

References LPTIM_CR, and LPTIM_CR_ENABLE.

◆ lptimer_disable_irq()

void lptimer_disable_irq ( uint32_t  lptimer_peripheral,
uint32_t  irq 
)

Disable lptimer Interrupts.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)
[in]irqLogical or of all interrupt enable bits to be cleared (LPTIM_IER Interrupt Enable Register)

Definition at line 123 of file lptimer_common_all.c.

References LPTIM_IER.

◆ lptimer_disable_preload()

void lptimer_disable_preload ( uint32_t  lptimer_peripheral)

Disable lptimer Preload mode.

Disable lptimer preload mode, ensureing updated period and compare registers values are taken in account immediatly.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)

Definition at line 246 of file lptimer_common_all.c.

References LPTIM_CFGR, and LPTIM_CFGR_PRELOAD.

◆ lptimer_enable()

void lptimer_enable ( uint32_t  lptimer_peripheral)

Enable lptimer.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)

Definition at line 132 of file lptimer_common_all.c.

References LPTIM_CR, and LPTIM_CR_ENABLE.

◆ lptimer_enable_irq()

void lptimer_enable_irq ( uint32_t  lptimer_peripheral,
uint32_t  irq 
)

Enable lptimer interrupts.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)
[in]irqLogical or of all interrupt enable bits to be set (LPTIM_IER Interrupt Enable Register)

Definition at line 112 of file lptimer_common_all.c.

References LPTIM_IER.

◆ lptimer_enable_preload()

void lptimer_enable_preload ( uint32_t  lptimer_peripheral)

Enable lptimer Preload mode.

Enable lptimer preload mode, delaying update of period and compare registers to the end of current period.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)

Definition at line 234 of file lptimer_common_all.c.

References LPTIM_CFGR, and LPTIM_CFGR_PRELOAD.

◆ lptimer_enable_trigger()

void lptimer_enable_trigger ( uint32_t  lptimer_peripheral,
uint32_t  trigen 
)

Enable lptimer External Trigger.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)
[in]trigenEnable Trigger

Definition at line 181 of file lptimer_common_all.c.

References LPTIM_CFGR, LPTIM_CFGR_TRIGEN_MASK, and LPTIM_CFGR_TRIGEN_SHIFT.

◆ lptimer_get_counter()

uint16_t lptimer_get_counter ( uint32_t  lptimer_peripheral)

Read lptimer Counter.

Read back the value of lptimer counter.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)
Returns
Counter value.

Definition at line 80 of file lptimer_common_all.c.

References LPTIM_CNT.

◆ lptimer_get_flag()

bool lptimer_get_flag ( uint32_t  lptimer_peripheral,
uint32_t  flag 
)

Read lptimer Status Flag.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)
[in]flagStatus Register flag (LPTIM_ISR Interrupt and Status Register)
Returns
flag set.

Definition at line 101 of file lptimer_common_all.c.

References LPTIM_ISR.

◆ lptimer_select_trigger_source()

void lptimer_select_trigger_source ( uint32_t  lptimer_peripheral,
uint32_t  trigger_source 
)

Select lptimer Trigger Source.

Select timer external trigger source.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)
[in]trigger_sourceTrigger selector (LPTIM_CFGR TRIGSEL Trigger selector)

Definition at line 195 of file lptimer_common_all.c.

References LPTIM_CFGR, LPTIM_CFGR_TRIGSEL_MASK, and LPTIM_CFGR_TRIGSEL_SHIFT.

◆ lptimer_set_compare()

void lptimer_set_compare ( uint32_t  lptimer_peripheral,
uint16_t  compare_value 
)

Set lptimer counter Compare Value.

Set the timer compare value. Must only be set with timer enabled.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)
[in]compare_valueCompare value.

Definition at line 209 of file lptimer_common_all.c.

References LPTIM_CMP.

◆ lptimer_set_counter()

void lptimer_set_counter ( uint32_t  lptimer_peripheral,
uint16_t  count 
)

Set lptimer Counter.

Set the value of a lptimer counter.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)
[in]countCounter value.

Definition at line 68 of file lptimer_common_all.c.

References LPTIM_CNT.

◆ lptimer_set_external_clock_source()

void lptimer_set_external_clock_source ( uint32_t  lptimer_peripheral)

Set lptimer External Clock source.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)

Definition at line 265 of file lptimer_common_all.c.

References LPTIM_CFGR, and LPTIM_CFGR_CKSEL.

◆ lptimer_set_internal_clock_source()

void lptimer_set_internal_clock_source ( uint32_t  lptimer_peripheral)

Set lptimer Internal Clock source.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)

Definition at line 256 of file lptimer_common_all.c.

References LPTIM_CFGR, and LPTIM_CFGR_CKSEL.

◆ lptimer_set_period()

void lptimer_set_period ( uint32_t  lptimer_peripheral,
uint16_t  period_value 
)

Set lptimer period.

Set the timer period in the auto-reload register. Must only be set with timer enabled.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)
[in]period_valueAutoreload value. Must be greater that CMP value.

Definition at line 222 of file lptimer_common_all.c.

References LPTIM_ARR.

◆ lptimer_set_prescaler()

void lptimer_set_prescaler ( uint32_t  lptimer_peripheral,
uint32_t  prescaler 
)

Set lptimer clock prescaler.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)
[in]prescalerClock prescaler (LPTIM_CFGR PRESC Clock prescaler)

Definition at line 169 of file lptimer_common_all.c.

References LPTIM_CFGR, LPTIM_CFGR_PRESC_MASK, and LPTIM_CFGR_PRESC_SHIFT.

◆ lptimer_set_waveform_polarity_high()

void lptimer_set_waveform_polarity_high ( uint32_t  lptimer_peripheral)

Set lptimer Waveform Output Polarity High.

Set lptimer waveform output to reflect compare result between LPTIN_CNT and LPTIM_CMP.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)

Definition at line 277 of file lptimer_common_all.c.

References LPTIM_CFGR, and LPTIM_CFGR_WAVPOL.

◆ lptimer_set_waveform_polarity_low()

void lptimer_set_waveform_polarity_low ( uint32_t  lptimer_peripheral)

Set lptimer Waveform Output Polarity Low.

Set lptimer waveform output to reflect the inverse of the compare result between LPTIN_CNT and LPTIM_CMP.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)

Definition at line 289 of file lptimer_common_all.c.

References LPTIM_CFGR, and LPTIM_CFGR_WAVPOL.

◆ lptimer_start_counter()

void lptimer_start_counter ( uint32_t  lptimer_peripheral,
uint32_t  mode 
)

Start lptimer in a given mode.

Starts the timer in specified mode - Either Single (LPTIM_CR_SNGSTRT) or Continuous mode (LPTIM_CR_CNTSTRT). In Single mode, the timer will stop at next match on compare or period value. If LPTIM_CR_SNGSTRT is set while timer is started in countious mode, it will stop at next match on compare or period value. If Software trigger is disabled, start will be delayed until programmed triggers is detected.

Parameters
[in]lptimer_peripherallptimer base address (Low Power Timer register base addresses)
[in]modelptimer start mode (LPTIM_CR_SNGSTRT or LPTIM_CR_CNTSTRT)

Definition at line 159 of file lptimer_common_all.c.

References LPTIM_CR.