-
Notifications
You must be signed in to change notification settings - Fork 139
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
feedback on the SYST API #59
Comments
Yeah, I screwed this up. The proposed changes all seem good to me, can you apply them? |
I'm finally visiting the details of this issue.
Where did you get this info from, @therealprof? I'm looking the official ARM documentation for Cortex-M0 devices and it says "A write of any value clears the field to 0, and also clears the SYST_CSR.COUNTFLAG bit to 0." (emphasis mine) about the CURRENT field (first 24 bits) of the CVR register. Based on that
The documentation says:
So syst.set_clock_source(SystClkSource::Core);
syst.set_reload(8_000_000 - 1);
// syst.set_current(0); // <- doesn't make any difference
syst.enable_counter();
let start = syst.get_current();
let mut cnt = 0;
while !syst.has_wrapped() {
cnt += 1;
}
asm::bkpt(); And got values of
This is indeed stated in the documentation. I would personally lean towards documenting this fact in the API docs rather than trying to do something smart like implicitly performing the subtraction in TL;DR I lean towards leaving the API as it is and documenting the "reload formula" in |
I'm not quite sure where it was mentioned you should set it to 1 but that certainly makes sense from the perspective of getting determinable timings. Also the "STM32F0xxx Cortex-M0 programming manual" contains one more sentence in the paragraph from your citing which is quite relevant:
You definitely do not want to omit the |
But the thing is that reference manual says that the value you write to RVR doesn't matter because the write operation will clear the register. I have confirmed that on hardware: any write sets the RVR value to 0.
Both the reload formula and the correct initalization sequence are being added to documentation in #75 |
better document the SYST API closes #59
"Some nits about the SYST implementation: fn clear () does not make a whole lot of sense as clearing actually disables the SysTick timer because the exception is triggered when the count changes from 1 -> 0 which is also what causes the reload. Similarly the manuals suggest you should load the counter with the value 1 (for which there's currently no safe API) to ensure that the timer will not start with some offset in the first turn and also the correct value for the reload is actually - 1."
from rust-embedded/cortex-m-quickstart#15 (comment)
cc @whitequark
The text was updated successfully, but these errors were encountered: