1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
Commit Graph

18 Commits

Author SHA1 Message Date
Joshua DeWeese
f24fc69118 cpu/stm32/periph/timer: fix whitespace style 2024-11-19 21:50:23 -05:00
Joshua DeWeese
4e357d410c cpu/stm32/periph/timer: prevnt spurious IRQs
This patch hardens the STM32 timer driver against some possible causes
of spurious IRQs.
2024-10-18 15:51:42 -04:00
Marian Buschsieweke
3868a7fa10
cpu/stm32: implement periph_timer_query_freqs 2023-12-07 16:15:06 +01:00
Marian Buschsieweke
7c0a4b8390
cpu/stm32/periph_timer: Support timers with channels != 4
The assumption that all STM32 timers have exactly four channels no
longer holds. E.g. the STM32L4 has the following general purpose timers:

- TIM2: 32 bit, 4 channels
- TIM15: 16 bit, 2 channels
- TIM16: 16 bit, 1 channel

Hence, a new field is added to the timer configuration to also contain
the number of timer channels. Due to alignment the `struct` previously
was padded by 16 bit, so adding another 8 bit field doesn't increase
its size.

For backward compatibility, a value of `0` is considered as alias for
`TIMER_CHANNEL_NUMOF` (or 4), so that the number of timer channels
only needs to be set when the timer is different from the typical 4
channel timer. This helps backward compatibility.
2023-05-30 12:55:29 +02:00
Joshua DeWeese
dea25437c7 cpu/stm32/periph/timer: fix clobered IRQ flag
The STM32 periph_timer driver reads the timer's status flags, then
clears them all. It is possible that a timer interrupt could occur
between reading the flag and clearing it. This would lead to a lost
interrupt.

The timer's status flags can be cleared by software, but can only be set
by the hardware. This patch takes advantage of this by only clearing the
flags it knows are set. The rest of the flags are set, which doesn't
actually change their state.
2023-03-13 14:01:48 -04:00
Joshua DeWeese
eeb359e80c cpu/stm32/periph/timer: fix execution flow
The implmentation of `timer_set_absolute()` has The following problems.
First, it attempts to restore the auto reload register (ARR) to it's
default if the ARR was previosly set by `timer_set_periodic()` by
comparing it to the channel's capture compare (CC) register _after_ it
has already set the CC register. Secondly, it clears spurious IRQs
_after_ the CC register has been set. If the value being set is equal to
the timer's current count (or the two become equal before the supurios
IRQ clearing happens), this could cause a legitimate IRQ to be cleared.

The implmentation of `timer_set()` has the same error in handling the
ARR as described above.

This patch reorders the operations of both functions to do:

1. handle ARR
2. clear spurious IRQs
3. set channel's CC
4. enable IRQ

Additionally, the calulation of `value` in `timer_set()` is moved
earlier in the function's exec path as a pedantic measure.
2023-03-07 11:52:16 -05:00
Joshua DeWeese
6488fe7cb3 cpu/stm32/periph/timer: remove unneeded header
I see no reason this header should be included. It does not exist in
RIOT's source tree. This patch removes the include.
2023-03-07 11:25:23 -05:00
Joshua DeWeese
289814edcf cpu/stm32/periph/timer: don't stop counter
If a timer's channel was set with a really small realtive duration from
now, such that it would be missed (underflowed), the driver would stop
the timer, potentially causing missed ticks. It was stopped to ensure
that the channel's output-compare register could be set to the current
counter value, before re-enabling the timer's counter. This is a
condition that will ensure that the underflow won't happen again and the
interrupt will fire, at the cost of losing some ticks for very high
speed clocks.

This patch replaces the logic that stopped the timer. Instead it uses a
register provided by the timer hardware to trigger timer interrupts via
software.
2023-02-08 14:08:56 -05:00
Marian Buschsieweke
b8cc222e76
cpu/stm32/periph_timer: implement timer_set()
The fallback implementation of timer_set() in `drivers/periph_common`
is known to fail on short relative sets. This adds a robust
implementation.
2023-01-03 15:51:06 +01:00
Marian Buschsieweke
20fc71dd65
cpu/stm32/periph_timer: fix spurious IRQs 2022-11-24 22:34:10 +01:00
Marian Buschsieweke
93c5755649
cpu/stm32/periph_timer: fix race conditions
Allow two threads to share the same timer - provided they use distinct
sets of timer channels - without occasionally corrupting registers or
state flags.
2022-11-24 22:34:03 +01:00
Benjamin Valentin
d6b5bf33b2 cpu/stm32: timer: implement TIM_FLAG_SET_STOPPED 2022-04-28 13:27:59 +02:00
Marian Buschsieweke
125c892c03
drivers/periph/timer: Use uint32_t for frequency
For all currently supported platforms `unsigned long` is 32 bit in width. But
better use `uint32_t` to be safe.
2020-10-30 22:02:12 +01:00
Benjamin Valentin
a0972c9e0c cpu/stm32: implement periph_timer_periodic
Seems like the Interrupt flag for a Capture/Compare channel gets set when

- the CC-value is reached
- the timer resets before the CC value is reached.

We only want the first event and ignore the second one. Unfortunately I did
not find a way to disable the second event type, so it is filtered in software.

That is we need to

 - ignore the CC-interrupts when the COUNT register register is reset
 - ignore the CC-interrupts > TOP value/ARR (auto-reload register)
2020-08-09 22:55:22 +02:00
Benjamin Valentin
06cdd30fcb cpu/stm32: use TIMER_CHANNEL_NUMOF for consistency 2020-06-24 12:58:38 +02:00
2dc0ec00a1
cpu/stm32: adapt timer driver to common CMSIS timer structure 2020-05-29 18:22:00 +02:00
b6d2231d6d
cpu/stm32: adapt Doxygen documentation 2020-05-20 13:39:11 +02:00
5c810d8535
cpu/stm32: introduce unique directory for stm32 cpus 2020-05-20 13:39:10 +02:00