stm32-rs / stm32f1xx-hal

A Rust embedded-hal HAL impl for the STM32F1 family based on japarics stm32f103xx-hal
Apache License 2.0
564 stars 177 forks source link

Fix RTC selection of frequency for LSI and HSE #468

Open Rutherther opened 1 year ago

Rutherther commented 1 year ago

So far, Rtc::select_frequency did not consider frequencies other than LSE_HERTZ, which was valid only for LSE with 32.768 kHz. For LSI, which has 40 kHz, and HSE, which may have an arbitrary frequency in a given range, the frequency was selected based on the wrong RTC frequency.

This PR aims to fix that. I've also refactored the new methods a bit, using the select_frequency instead of repeating the same code.

I've solved this by adding frequency field to the Rtc, there is no other way I could think of, as HSE frequency may be different depending on the crystal selected for specific application. As far as I understand it, LSE does not necessarily have to be 32.768 kHz, so maybe adding the possibility to change the frequency of LSE could prove useful as well? Adding the frequency field unfortunately introduces redundancy for LSI and (maybe) LSE.

Rutherther commented 1 year ago

In my previous PR #466, I forgot to add the change to CHANGELOG.md, this PR adds that change to CHANGELOG as well.