mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 19:50:30 +01:00
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:
@@ -339,11 +339,7 @@ STATIC HAL_StatusTypeDef PYB_RTC_Init(RTC_HandleTypeDef *hrtc) {
|
|||||||
hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << 16);
|
hrtc->Instance->PRER |= (uint32_t)(hrtc->Init.AsynchPrediv << 16);
|
||||||
|
|
||||||
// Exit Initialization mode
|
// Exit Initialization mode
|
||||||
#if defined(STM32G4) || defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ)
|
LL_RTC_DisableInitMode(hrtc->Instance);
|
||||||
hrtc->Instance->ICSR &= (uint32_t) ~RTC_ICSR_INIT;
|
|
||||||
#else
|
|
||||||
hrtc->Instance->ISR &= (uint32_t) ~RTC_ISR_INIT;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ)
|
#if defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ)
|
||||||
// do nothing
|
// 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;
|
RTC->CR &= ~RTC_CR_WUTE;
|
||||||
|
|
||||||
// wait until WUTWF is set
|
// wait until WUTWF is set
|
||||||
#if defined(STM32G4) || defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ)
|
while (!LL_RTC_IsActiveFlag_WUTW(RTC)) {
|
||||||
while (!(RTC->ICSR & RTC_ICSR_WUTWF)) {
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
while (!(RTC->ISR & RTC_ISR_WUTWF)) {
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
// program WUT
|
// program WUT
|
||||||
|
|||||||
Reference in New Issue
Block a user