drivers: rtc: stm32: fix error handling
re-enable Write Protection when Init Mode errors. Signed-off-by: Abderrahmane Jarmouni <abderrahmane.jarmouni-ext@st.com>
This commit is contained in:
parent
d9a49cb761
commit
4d038fb523
1 changed files with 3 additions and 8 deletions
|
@ -392,9 +392,7 @@ static int rtc_stm32_init(const struct device *dev)
|
||||||
static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *timeptr)
|
static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *timeptr)
|
||||||
{
|
{
|
||||||
struct rtc_stm32_data *data = dev->data;
|
struct rtc_stm32_data *data = dev->data;
|
||||||
|
|
||||||
uint32_t real_year = timeptr->tm_year + TM_YEAR_REF;
|
uint32_t real_year = timeptr->tm_year + TM_YEAR_REF;
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (real_year < RTC_YEAR_REF) {
|
if (real_year < RTC_YEAR_REF) {
|
||||||
|
@ -423,11 +421,8 @@ static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *t
|
||||||
ErrorStatus status = LL_RTC_EnterInitMode(RTC);
|
ErrorStatus status = LL_RTC_EnterInitMode(RTC);
|
||||||
|
|
||||||
if (status != SUCCESS) {
|
if (status != SUCCESS) {
|
||||||
#if RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION
|
err = -EIO;
|
||||||
LL_PWR_DisableBkUpAccess();
|
goto protect_unlock_return;
|
||||||
#endif /* RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION */
|
|
||||||
k_mutex_unlock(&data->lock);
|
|
||||||
return -EIO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LL_RTC_DATE_SetYear(RTC, bin2bcd(real_year - RTC_YEAR_REF));
|
LL_RTC_DATE_SetYear(RTC, bin2bcd(real_year - RTC_YEAR_REF));
|
||||||
|
@ -442,13 +437,13 @@ static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *t
|
||||||
LL_RTC_DATE_SetWeekDay(RTC, timeptr->tm_wday);
|
LL_RTC_DATE_SetWeekDay(RTC, timeptr->tm_wday);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LL_RTC_TIME_SetHour(RTC, bin2bcd(timeptr->tm_hour));
|
LL_RTC_TIME_SetHour(RTC, bin2bcd(timeptr->tm_hour));
|
||||||
LL_RTC_TIME_SetMinute(RTC, bin2bcd(timeptr->tm_min));
|
LL_RTC_TIME_SetMinute(RTC, bin2bcd(timeptr->tm_min));
|
||||||
LL_RTC_TIME_SetSecond(RTC, bin2bcd(timeptr->tm_sec));
|
LL_RTC_TIME_SetSecond(RTC, bin2bcd(timeptr->tm_sec));
|
||||||
|
|
||||||
LL_RTC_DisableInitMode(RTC);
|
LL_RTC_DisableInitMode(RTC);
|
||||||
|
|
||||||
|
protect_unlock_return:
|
||||||
LL_RTC_EnableWriteProtection(RTC);
|
LL_RTC_EnableWriteProtection(RTC);
|
||||||
|
|
||||||
#if RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION
|
#if RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue