-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LinkedTimer: Implement initial version #115
Conversation
b612f91
to
f603d85
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks you, @dbrgn! I don't have the time for a full review, but I took a quick look and it looks good. Since it looks like you've done your homework here, I'd be happy to approve and merge, unless anyone else objects.
CI is failing though, due to the RTFM -> RTIC rename. It probably makes sense to fix this in a separate PR, then rebase this one.
Yep, I meant to do that (but it was already late yesterday). I'll provide a PR tonight, afterwards we can rebase. |
A `LinkedTimer` is initialized with two hardware timers (either TIM2/TIM3 or TIM21/TIM22). The two timers are configured in master/slave mode so that an overflow of the master timer triggers an update on the slave timer. This way, two 16 bit timers can be combined to a single 32 bit timer.
Updated, now with reset 🙂 I discovered that this cannot be used for RTIC (since the RTIC monotonic timer must be initialized statically), but it may be useful nevertheless. |
Looks like this was left un-merged for no good reason. Merging. |
Implementation of #114.
A
LinkedTimer
impl is initialized with two hardware timers (either TIM2/TIM3 or TIM21/TIM22). The two timers are configured in master/slave mode so that an overflow of the master timer triggers an update on the slave timer. This way, two 16 bit timers can be combined to a single 32 bit timer. (The STM32L0 does not have 32 bit timers.)Such a linked timer allows implementing the
Monotonic
trait for the RTIC scheduler with high timer precision.Right now the implementation does not add logic for detecting an overflow, that is left to the user. Furthermore, no prescaler is configured. And not all possible timer combinations have been implemented.
An example is provided (tested on the STM32L071KBTx). Here's the serial output:
Let me know whether this is useful, and whether the implementation looks correct. This was my first STM32 timer deep-dive, I spent quite a few hours looking through the reference manual to figure out how to link timers 🙂
The relevant information in the reference manual (RM0377) is in section 16.3.15 "Timer synchronization". Here's the section that describes timer linking: