Skip to content
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

RTC 'calibration' #469

Open
Rutherther opened this issue Aug 1, 2023 · 0 comments
Open

RTC 'calibration' #469

Rutherther opened this issue Aug 1, 2023 · 0 comments

Comments

@Rutherther
Copy link
Contributor

It's possible that if LSE crystal is used, the crystal won't have the exact frequency of 32.768 kHz. It looks to me that Rtc::select_frequency is not enough, as it allows only to set whole number frequencies. If I want to have RTC with 1 Hz, and the clock gets ahead by a second or two per day, the prescaler for RTC should be different than 1 Hz based precisely on 32.768 kHz. (should not be 32.768 / 1 - 1)

This HAL currently does not support adding or subtracting from the prescaler. This may be solved by writing to prlh and prll directly, but I would say that implementing support for some kind of a calibration like this is not out of scope of this HAL and could be implemented in Rtc.

What do you think about this? And what do you think the implementation should be? The best I came up with is making something like Rtc::select_precise_frequency(&mut self, frequency: Hertz, adjustment: u32), where adjustment would just be added to the prescaler.

I am up to PR this, but I am unsure 1. if this is in the scope of this HAL, 2. if the implementation I proposed makes sense, maybe it could be done better

x1b6e6 added a commit to x1b6e6/stm32f1xx-hal that referenced this issue Oct 9, 2024
Fix `select_frequency` method with non LSE clock.
Allow custom frequencies for LSE and LSI clocks.

Fix stm32-rs#469

Signed-off-by: Timofey Denisenko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant