Timer support.
Contents
The timer register map type, unlike that for most other peripherals in libmaple, is a union rather than a struct. This is due to the fact that there are advanced, general purpose, and basic timers. Thus, each kind of timer has a register map type, and a union timer_reg_map ties it all together.
Advanced control timer register map type.
Public Members
- __io uint32 CR1
Control register 1.
- __io uint32 CR2
Control register 2.
- __io uint32 SMCR
Slave mode control register.
- __io uint32 DIER
DMA/Interrupt enable register.
- __io uint32 SR
Status register.
- __io uint32 EGR
Event generation register.
- __io uint32 CCMR1
Capture/compare mode register 1.
- __io uint32 CCMR2
Capture/compare mode register 2.
- __io uint32 CCER
Capture/compare enable register.
- __io uint32 CNT
Counter.
- __io uint32 PSC
Prescaler.
- __io uint32 ARR
Auto-reload register.
- __io uint32 RCR
Repetition counter register.
- __io uint32 CCR1
Capture/compare register 1.
- __io uint32 CCR2
Capture/compare register 2.
- __io uint32 CCR3
Capture/compare register 3.
- __io uint32 CCR4
Capture/compare register 4.
- __io uint32 BDTR
Break and dead-time register.
- __io uint32 DCR
DMA control register.
- __io uint32 DMAR
DMA address for full transfer.
General purpose timer register map type.
Public Members
- __io uint32 CR1
Control register 1.
- __io uint32 CR2
Control register 2.
- __io uint32 SMCR
Slave mode control register.
- __io uint32 DIER
DMA/Interrupt enable register.
- __io uint32 SR
Status register.
- __io uint32 EGR
Event generation register.
- __io uint32 CCMR1
Capture/compare mode register 1.
- __io uint32 CCMR2
Capture/compare mode register 2.
- __io uint32 CCER
Capture/compare enable register.
- __io uint32 CNT
Counter.
- __io uint32 PSC
Prescaler.
- __io uint32 ARR
Auto-reload register.
- const uint32 RESERVED1
Reserved.
- __io uint32 CCR1
Capture/compare register 1.
- __io uint32 CCR2
Capture/compare register 2.
- __io uint32 CCR3
Capture/compare register 3.
- __io uint32 CCR4
Capture/compare register 4.
- const uint32 RESERVED2
Reserved.
- __io uint32 DCR
DMA control register.
- __io uint32 DMAR
DMA address for full transfer.
Basic timer register map type.
Public Members
- __io uint32 CR1
Control register 1.
- __io uint32 CR2
Control register 2.
- const uint32 RESERVED1
Reserved.
- __io uint32 DIER
DMA/Interrupt enable register.
- __io uint32 SR
Status register.
- __io uint32 EGR
Event generation register.
- const uint32 RESERVED2
Reserved.
- const uint32 RESERVED3
Reserved.
- const uint32 RESERVED4
Reserved.
- __io uint32 CNT
Counter.
- __io uint32 PSC
Prescaler.
- __io uint32 ARR
Auto-reload register.
Timer type.
Type marker for timer_dev.
See: | timer_dev |
---|
Values:
Advanced type.
General purpose type.
Basic type.
Timer device type.
Public Members
- timer_reg_map regs
Register map.
- rcc_clk_id clk_id
RCC clock information.
- timer_type type
Timer’s type.
- voidFuncPtr handlers[]
User IRQ handlers.
Used to configure the behavior of a timer channel.
Note that not all timers can be configured in every mode.
Values:
In this mode, the timer stops counting, channel interrupts are detached, and no state changes are output.
PWM output mode.
This is the default mode for pins after initialization.
In this mode, the timer counts from 0 to its reload value repeatedly; every time the counter value reaches one of the channel compare values, the corresponding interrupt is fired.
Timer channel numbers.
Values:
Channel 1.
Channel 2.
Channel 3.
Channel 4.
Timer interrupt number.
Not all timers support all of these values; see the descriptions for each value.
Values:
Update interrupt, available on all timers.
Capture/compare 1 interrupt, available on general and advanced timers only.
Capture/compare 2 interrupt, general and advanced timers only.
Capture/compare 3 interrupt, general and advanced timers only.
Capture/compare 4 interrupt, general and advanced timers only.
COM interrupt, advanced timers only.
Trigger interrupt, general and advanced timers only.
Break interrupt, advanced timers only.
Timer DMA base address.
Defines the base address for DMA transfers.
Values:
Base is control register 1.
Base is control register 2.
Base is slave mode control register.
Base is DMA interrupt enable register.
Base is status register.
Base is event generation register.
Base is capture/compare mode register 1.
Base is capture/compare mode register 2.
Base is capture/compare enable register.
Base is counter.
Base is prescaler.
Base is auto-reload register.
Base is repetition counter register.
Base is capture/compare register 1.
Base is capture/compare register 2.
Base is capture/compare register 3.
Base is capture/compare register 4.
Base is break and dead-time register.
Base is DMA control register.
Base is DMA address for full transfer.
Timer output compare modes.
Values:
Frozen: comparison between output compare register and counter has no effect on the outputs.
OCxREF signal is forced high when the count matches the channel capture/compare register.
OCxREF signal is forced low when the counter matches the channel capture/compare register.
OCxREF toggles when counter matches the cannel capture/compare register.
OCxREF is forced low.
OCxREF is forced high.
PWM mode 1.
In upcounting, channel is active as long as count is less than channel capture/compare register, else inactive. In downcounting, channel is inactive as long as count exceeds capture/compare register, else active.
PWM mode 2.
In upcounting, channel is inactive as long as count is less than capture/compare register, else active. In downcounting, channel is active as long as count exceeds capture/compare register, else inactive.
Timer output compare mode flags.
See: | timer_oc_set_mode() |
---|
Values:
Output compare clear enable.
Output compare preload enable.
Output compare fast enable.
Timer 1 device (advanced).
Timer 2 device (general-purpose).
Timer 3 device (general-purpose).
Timer 4 device (general-purpose).
Timer 5 device (general-purpose).
Timer 6 device (basic).
Timer 7 device (basic).
Timer 8 device (advanced).
Initialize a timer, and reset its register map.
Parameters: |
|
---|
Initialize all timer devices on the chip.
Disable a timer.
The timer will stop counting, all DMA requests and interrupts will be disabled, and no state changes will be output.
Parameters: |
|
---|
Disables all timers on the device.
Sets the mode of an individual timer channel.
Note that not all timers can be configured in every mode. For example, basic timers cannot be configured to output compare mode. Be sure to use a timer which is appropriate for the mode you want.
Parameters: |
|
---|
Call a function on timer devices.
Parameters: |
|
---|
Returns the timer’s counter value.
This value is likely to be inaccurate if the counter is running with a low prescaler.
Parameters: |
|
---|
Sets the counter value for the given timer.
Parameters: |
|
---|
Stop a timer’s counter from changing.
Does not affect the timer’s mode or other settings.
Parameters: |
|
---|
Start a timer’s counter.
Does not affect the timer’s mode or other settings.
Parameters: |
|
---|
Generate an update event for the given timer.
Normally, this will cause the prescaler and auto-reload values in the PSC and ARR registers to take immediate effect. However, this function will do nothing if the UDIS bit is set in the timer’s CR1 register (UDIS is cleared by default).
Parameters: |
|
---|
Returns the given timer’s prescaler.
Note that if the timer’s prescaler is set (e.g. via timer_set_prescaler() or accessing a TIMx_PSC register), the value returned by this function will reflect the new setting, but the timer’s counter will only reflect the new prescaler at the next update event.
Parameters: |
|
---|---|
See: |
Set a timer’s prescale value.
The new value will not take effect until the next update event.
Parameters: |
|
---|---|
See: |
Returns a timer’s reload value.
Parameters: |
|
---|
Set a timer’s reload value.
Parameters: |
|
---|---|
See: |
Attach a timer interrupt.
Parameters: |
|
---|---|
See: |
Detach a timer interrupt.
Parameters: |
|
---|---|
See: |
Enable a timer interrupt.
Parameters: |
|
---|---|
See: |
Disable a timer interrupt.
Parameters: |
|
---|---|
See: |
Get the compare value for the given timer channel.
Parameters: |
|
---|
Set the compare value for the given timer channel.
Parameters: |
|
---|
Enable a timer channel’s capture/compare signal.
If the channel is configured as output, the corresponding output compare signal will be output on the corresponding output pin. If the channel is configured as input, enables capture of the counter value into the input capture/compare register.
Parameters: |
|
---|
Disable a timer channel’s output compare or input capture signal.
Parameters: |
|
---|---|
See: |
Get a channel’s capture/compare output polarity.
Parameters: |
|
---|---|
Return: | Polarity, either 0 or 1. |
See: | timer_cc_set_polarity() |
Set a timer channel’s capture/compare output polarity.
If the timer channel is configured as output: polarity == 0 means the output channel will be active high; polarity == 1 means active low.
If the timer channel is configured as input: polarity == 0 means capture is done on the rising edge of ICn; when used as an external trigger, ICn is non-inverted. polarity == 1 means capture is done on the falling edge of ICn; when used as an external trigger, ICn is inverted.
Parameters: |
|
---|
Configure a channel’s output compare mode.
Parameters: |
|
---|---|
See: |
Enable a timer’s trigger DMA request.
Parameters: |
|
---|
Disable a timer’s trigger DMA request.
Parameters: |
|
---|
Enable a timer channel’s DMA request.
Parameters: |
|
---|
Get a timer’s DMA burst length.
Parameters: |
|
---|---|
Return: | Number of bytes to be transferred per DMA request, from 1 to 18. |
Set a timer’s DMA burst length.
Parameters: |
|
---|
Get the timer’s DMA base address.
Some restrictions apply; see ST RM0008.
Parameters: |
|
---|---|
Return: | DMA base address |
Set the timer’s DMA base address.
Some restrictions apply; see ST RM0008.
Parameters: |
|
---|
Timer 1 register map base pointer.
Timer 2 register map base pointer.
Timer 3 register map base pointer.
Timer 4 register map base pointer.
Timer 5 register map base pointer.
Timer 6 register map base pointer.
Timer 7 register map base pointer.
Timer 8 register map base pointer.