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>
This commit is contained in:
parent
26faf74d52
commit
e4f59a0020
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue