-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cpu/cortexm_common: implement SysTick timer, add option to use it for XTIMER #14553
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
Conversation
3670475
to
8df5548
Compare
Last time I tried something with the systick timer, I found out that the timer is stopped during CPU standby. Probably because the CPU clock is stopped during those standby times. Is that the reason why power consumption increased when using the systick timer? |
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.
See inline comments
But that's true for most periph timers too, usually only RTT will keep running during standby. But we are getting more interrupts as SysTick will overflow after 350ms at 48 MHz. |
IMO, power saving is just broken with With |
Needs a rebase. Feel free to squash, btw. |
I still think that frequency conversion is better left to the upper layer. At least |
d97eed8
to
2e77327
Compare
I've moved the use of the prescaler to the |
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.
I think the compiler won't be able to detect that now_offset
is only needed when module systick_prescaler
is used. So maybe the suggested changes would result in slimmer code in that case?
* | ||
* To comply with the RIOT timer interface that expects an up-counting, monotonic | ||
* timer, SysTick is augmented by software to fulfill these requirements. | ||
* This also adds a software prescaler to simulate arbitrary frequencies and introduces |
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.
Is this necessary and / or desirable?
We already have two higher level timer implementations that do exactly that, and more.
There are quite some challenges to overcome to get this right.
As is, I'd probably cut out the guts and re-implement as ztimer backend.
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.
The issue was that xtimer cannot handle arbitrary frequencies: #14553 (comment)
I'm personally fine with having this a ztimer
only. IMO, xtimer
is on the way out anyway.
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.
I found it useful to just being able to use xtimer_on_systick
to free up the periph timer and not having to configure ztimer as well.
I don't think the conditional overflow handling adds much to the code, and it's pretty minimal when enabled.
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.
ztimer still expects the timer to be up-counting, right?
In cpu/cortexm_common/vectors_cortexm.c:476, there is a comment saying that SysTick interrupt is unused. You want to remove or update it. |
Thank you, updated. |
b007a80
to
42bfeb6
Compare
bb6789d
to
333143f
Compare
This introduces the `xtimer_on_systick` pseudo-module that can be used to source the xtimer clock from SysTick, available on every Cortex-M CPU.
333143f
to
9b16b84
Compare
Co-authored-by: Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
Why not handle the hardware prescaler by 8 (CLKSOURCE=0) ? It seems confusing to me to see an option as xtimer_on_systick or filenames as systick.c or systick.h in a tickless operating system so why not use another name as "core_timer" for exemple ? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Contribution description
SysTick is a 24 bit down-counting timer that is implemented on every Cortex-M processor.
It runs at the same frequency as the CPU and can generate an interrupt when it reaches 0.
It allows to free up hardware timers for other uses and accelerates bring-up of new Cortex-M platforms since SysTick is implemented the same everywhere.
To comply with the RIOT timer interface (xtimer & ztimer) that expect an up-counting, monotonic timer,
SysTick is augmented by software to fulfill these requirements.
This also adds a software prescaler to simulate arbitrary frequencies and introduces a virtual, 32 bit counter.
That allows for longer intervals than would be possible with the SysTick hardware peripheral alone and makes it possible to use it as a backed for xtimer.
I initially hoped to see some power savings by not running a timer peripheral, but on
examples/timer_periodic_wakeup
power draw went up from 2.35 mA with the periph timer to 2.37 mA with the SysTick timer as source for the xtimer clock.Testing procedure
A basic test is included with
tests/periph_systick
.But it is possible to run any test or application that uses xtimer off SysTick by adding
to the application Makefile.
This should work on any Cortex-M processor.
Issues/PRs references