@@ -69,8 +69,16 @@ static inline void resetBackupDomain(void)
6969 */
7070 HAL_PWR_EnableBkUpAccess ();
7171#endif
72+ #if defined(__HAL_RCC_BACKUPRESET_FORCE )
7273 __HAL_RCC_BACKUPRESET_FORCE ();
7374 __HAL_RCC_BACKUPRESET_RELEASE ();
75+ #endif
76+ #if defined(LL_APB0_GRP1_PERIPH_RTC )
77+ LL_RCC_DisableRTC ();
78+ /* Wait until RTC is disabled */
79+ while (LL_RCC_IsEnabledRTC ());
80+ LL_RCC_EnableRTC ();
81+ #endif
7482}
7583
7684static inline void enableBackupDomain (void )
@@ -91,6 +99,23 @@ static inline void enableBackupDomain(void)
9199 /* Enable RTC CLK for TAMP backup registers */
92100 __HAL_RCC_RTCAPB_CLK_ENABLE ();
93101#endif
102+ #if defined(LL_APB0_GRP1_PERIPH_RTC )
103+ if (!LL_RCC_IsEnabledRTC ()) {
104+ if (LL_RCC_LSE_IsEnabled ()) {
105+ LL_RCC_LSCO_SetSource (LL_RCC_LSCO_CLKSOURCE_LSE );
106+ } else {
107+ /* Configure the Low Speed Clock to LSI */
108+ LL_RCC_LSCO_SetSource (LL_RCC_LSCO_CLKSOURCE_LSI );
109+ if (!LL_RCC_LSI_IsEnabled ()) {
110+ /* Enable LSI */
111+ LL_RCC_LSI_Enable ();
112+ /* Wait until LSI is ready */
113+ while (!LL_RCC_LSI_IsReady ());
114+ }
115+ }
116+ LL_RCC_EnableRTC ();
117+ }
118+ #endif
94119}
95120
96121static inline void disableBackupDomain (void )
@@ -111,13 +136,16 @@ static inline void disableBackupDomain(void)
111136 /* Disable RTC CLK for TAMP backup registers */
112137 __HAL_RCC_RTCAPB_CLK_DISABLE ();
113138#endif
139+ #if defined(LL_APB0_GRP1_PERIPH_RTC )
140+ LL_RCC_DisableRTC ();
141+ #endif
114142}
115143
116144static inline void setBackupRegister (uint32_t index , uint32_t value )
117145{
118146#if defined(BKP_BASE )
119147 LL_RTC_BKP_SetRegister (BKP , index , value );
120- #elif defined(RTC_BKP0R )
148+ #elif defined(RTC_BKP0R ) || defined( RTC_BKP0R_BKP )
121149 LL_RTC_BAK_SetRegister (RTC , index , value );
122150#elif defined(TAMP_BKP0R )
123151#if defined(STM32G4xx ) || defined(STM32H5xx ) || defined(STM32L5xx ) || \
@@ -141,7 +169,7 @@ static inline uint32_t getBackupRegister(uint32_t index)
141169{
142170#if defined(BKP_BASE )
143171 return LL_RTC_BKP_GetRegister (BKP , index );
144- #elif defined(RTC_BKP0R )
172+ #elif defined(RTC_BKP0R ) || defined( RTC_BKP0R_BKP )
145173 return LL_RTC_BAK_GetRegister (RTC , index );
146174#elif defined(TAMP_BKP0R )
147175#if defined(STM32G4xx ) || defined(STM32H5xx ) || defined(STM32L5xx ) || \
0 commit comments