Skip to content

Commit 4d038fb

Browse files
ajarmouni-stMaureenHelm
authored andcommitted
drivers: rtc: stm32: fix error handling
re-enable Write Protection when Init Mode errors. Signed-off-by: Abderrahmane Jarmouni <[email protected]>
1 parent d9a49cb commit 4d038fb

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

drivers/rtc/rtc_ll_stm32.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,7 @@ static int rtc_stm32_init(const struct device *dev)
392392
static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *timeptr)
393393
{
394394
struct rtc_stm32_data *data = dev->data;
395-
396395
uint32_t real_year = timeptr->tm_year + TM_YEAR_REF;
397-
398396
int err = 0;
399397

400398
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
423421
ErrorStatus status = LL_RTC_EnterInitMode(RTC);
424422

425423
if (status != SUCCESS) {
426-
#if RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION
427-
LL_PWR_DisableBkUpAccess();
428-
#endif /* RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION */
429-
k_mutex_unlock(&data->lock);
430-
return -EIO;
424+
err = -EIO;
425+
goto protect_unlock_return;
431426
}
432427

433428
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
442437
LL_RTC_DATE_SetWeekDay(RTC, timeptr->tm_wday);
443438
}
444439

445-
446440
LL_RTC_TIME_SetHour(RTC, bin2bcd(timeptr->tm_hour));
447441
LL_RTC_TIME_SetMinute(RTC, bin2bcd(timeptr->tm_min));
448442
LL_RTC_TIME_SetSecond(RTC, bin2bcd(timeptr->tm_sec));
449443

450444
LL_RTC_DisableInitMode(RTC);
451445

446+
protect_unlock_return:
452447
LL_RTC_EnableWriteProtection(RTC);
453448

454449
#if RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION

0 commit comments

Comments
 (0)