Skip to content

Commit

Permalink
drivers: rtc: stm32: Fixes RTC issues related to device runtime pm
Browse files Browse the repository at this point in the history
When device runtime pm is enabled, Backup Domain protection is active
most of the time. RTC driver need this protection to be disabled in
order to set the time or calibration. This fix disable the protection in
set time and set calibration functions.

Fixes: 62843
Signed-off-by: Petr Hlineny <[email protected]>
  • Loading branch information
coran21 authored and carlescufi committed Jan 4, 2024
1 parent 21e3749 commit 4a45435
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions drivers/rtc/rtc_ll_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ static int rtc_stm32_init(const struct device *dev)

err = rtc_stm32_configure(dev);

#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
LL_PWR_DisableBkUpAccess();
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */

return err;
}

Expand Down Expand Up @@ -208,10 +212,18 @@ static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *t
}

LOG_INF("Setting clock");

#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
LL_PWR_EnableBkUpAccess();
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */

LL_RTC_DisableWriteProtection(RTC);

err = rtc_stm32_enter_initialization_mode(true);
if (err) {
#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
LL_PWR_DisableBkUpAccess();
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */
k_mutex_unlock(&data->lock);
return err;
}
Expand All @@ -237,6 +249,10 @@ static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *t

LL_RTC_EnableWriteProtection(RTC);

#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
LL_PWR_DisableBkUpAccess();
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */

k_mutex_unlock(&data->lock);

return err;
Expand Down Expand Up @@ -359,12 +375,20 @@ static int rtc_stm32_set_calibration(const struct device *dev, int32_t calibrati
return -EIO;
}

#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
LL_PWR_EnableBkUpAccess();
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */

LL_RTC_DisableWriteProtection(RTC);

MODIFY_REG(RTC->CALR, RTC_CALR_CALP | RTC_CALR_CALM, calp | calm);

LL_RTC_EnableWriteProtection(RTC);

#if defined(PWR_CR_DBP) || defined(PWR_CR1_DBP) || defined(PWR_DBPCR_DBP) || defined(PWR_DBPR_DBP)
LL_PWR_DisableBkUpAccess();
#endif /* PWR_CR_DBP || PWR_CR1_DBP || PWR_DBPR_DBP */

return 0;
}

Expand Down

0 comments on commit 4a45435

Please sign in to comment.