@@ -440,7 +440,6 @@ static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *t
440
440
LL_RTC_TimeTypeDef rtc_time ;
441
441
LL_RTC_DateTypeDef rtc_date ;
442
442
uint32_t real_year = timeptr -> tm_year + TM_YEAR_REF ;
443
- int err = 0 ;
444
443
445
444
if (real_year < RTC_YEAR_REF ) {
446
445
/* RTC does not support years before 2000 */
@@ -452,19 +451,10 @@ static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *t
452
451
return - EINVAL ;
453
452
}
454
453
455
- k_spinlock_key_t key = k_spin_lock (& data -> lock );
456
-
457
- LOG_DBG ("Setting clock" );
458
-
459
- #if RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION
460
- LL_PWR_EnableBkUpAccess ();
461
- #endif /* RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION */
462
-
463
454
/* Enter Init mode inside the LL_RTC_Time and Date Init functions */
464
455
rtc_time .Hours = bin2bcd (timeptr -> tm_hour );
465
456
rtc_time .Minutes = bin2bcd (timeptr -> tm_min );
466
457
rtc_time .Seconds = bin2bcd (timeptr -> tm_sec );
467
- LL_RTC_TIME_Init (RTC , LL_RTC_FORMAT_BCD , & rtc_time );
468
458
469
459
/* Set Date after Time to be sure the DR is correctly updated on stm32F2 serie. */
470
460
rtc_date .Year = bin2bcd ((real_year - RTC_YEAR_REF ));
@@ -474,6 +464,16 @@ static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *t
474
464
/* WeekDay sunday (tm_wday = 0) is not represented by the same value in hardware,
475
465
* all the other values are consistent with what is expected by hardware.
476
466
*/
467
+
468
+ LOG_DBG ("Setting clock" );
469
+
470
+ k_spinlock_key_t key = k_spin_lock (& data -> lock );
471
+
472
+ #if RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION
473
+ LL_PWR_EnableBkUpAccess ();
474
+ #endif /* RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION */
475
+
476
+ LL_RTC_TIME_Init (RTC , LL_RTC_FORMAT_BCD , & rtc_time );
477
477
LL_RTC_DATE_Init (RTC , LL_RTC_FORMAT_BCD , & rtc_date );
478
478
479
479
#if RTC_STM32_BACKUP_DOMAIN_WRITE_PROTECTION
@@ -490,8 +490,6 @@ static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *t
490
490
}
491
491
#endif /* CONFIG_SOC_SERIES_STM32F2X */
492
492
493
- k_spin_unlock (& data -> lock , key );
494
-
495
493
LOG_DBG ("Calendar set : %d/%d/%d - %dh%dm%ds" ,
496
494
LL_RTC_DATE_GetDay (RTC ),
497
495
LL_RTC_DATE_GetMonth (RTC ),
@@ -501,7 +499,9 @@ static int rtc_stm32_set_time(const struct device *dev, const struct rtc_time *t
501
499
LL_RTC_TIME_GetSecond (RTC )
502
500
);
503
501
504
- return err ;
502
+ k_spin_unlock (& data -> lock , key );
503
+
504
+ return 0 ;
505
505
}
506
506
507
507
static int rtc_stm32_get_time (const struct device * dev , struct rtc_time * timeptr )
0 commit comments