summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-02-04 08:30:39 +1100
committerDamien George <damien@micropython.org>2022-02-04 08:35:14 +1100
commite4f59a00201b31903b11a6d30dddedc1457ed2ff (patch)
treec2b719ad129c9deb7f8bbd3e61eeda16fc003f66
parent26faf74d52e3e953c9ddbcd800a2f9e117477ce7 (diff)
stm32/rtc: Use LL_RTC functions to simplify some MCU-specific code.
This also fixes a possible race condition when exiting initialisation mode: reading then writing to ISR (via ISR &= ~RTC_ISR_INIT) will clear any flags that were set by the hardware between the read and the write. The correct way to clear just the INIT bit is to just do a single write via ISR = ~RTC_ISR_INIT, which will not clear any other flags (they must be written to 0 to clear), and that is exactly what LL_RTC_DisableInitMode does. Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/stm32/rtc.c13
1 files changed, 2 insertions, 11 deletions
diff --git a/ports/stm32/rtc.c b/ports/stm32/rtc.c
index 2d6459e23..1164e71e0 100644
--- a/ports/stm32/rtc.c
+++ b/ports/stm32/rtc.c
@@ -339,11 +339,7 @@ STATIC HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc) {
hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << 16);
// Exit Initialization mode
- #if defined(STM32G4) || defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ)
- hrtc->Instance->ICSR &= (uint32_t) ~RTC_ICSR_INIT;
- #else
- hrtc->Instance->ISR &= (uint32_t) ~RTC_ISR_INIT;
- #endif
+ LL_RTC_DisableInitMode(hrtc->Instance);
#if defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ)
// do nothing
@@ -702,13 +698,8 @@ mp_obj_t pyb_rtc_wakeup(size_t n_args, const mp_obj_t *args) {
RTC->CR &= ~RTC_CR_WUTE;
// wait until WUTWF is set
- #if defined(STM32G4) || defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ)
- while (!(RTC->ICSR & RTC_ICSR_WUTWF)) {
+ while (!LL_RTC_IsActiveFlag_WUTW(RTC)) {
}
- #else
- while (!(RTC->ISR & RTC_ISR_WUTWF)) {
- }
- #endif
if (enable) {
// program WUT