@@ -187,16 +187,20 @@ static void RTC_initClock(sourceClock_t source)
187
187
if (source == LSE_CLOCK ) {
188
188
/* Enable the clock if not already set by user */
189
189
enableClock (LSE_CLOCK );
190
-
190
+ #if defined(RCC_PERIPHCLK_RTC_WDG_BLEWKUP )
191
+ PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_BLEWKUP ;
192
+ PeriphClkInit .RTCWDGBLEWKUPClockSelection = RCC_RTC_WDG_BLEWKUP_CLKSOURCE_LSE ;
193
+ } else if (source == HSI_CLOCK ) {
194
+ /* Enable the clock if not already set by user */
195
+ enableClock (HSI_CLOCK );
196
+ PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_BLEWKUP ;
197
+ PeriphClkInit .RTCWDGBLEWKUPClockSelection = RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 ;
198
+ #else
191
199
PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC ;
192
200
PeriphClkInit .RTCClockSelection = RCC_RTCCLKSOURCE_LSE ;
193
- if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInit ) != HAL_OK ) {
194
- Error_Handler ();
195
- }
196
201
} else if (source == HSE_CLOCK ) {
197
202
/* Enable the clock if not already set by user */
198
203
enableClock (HSE_CLOCK );
199
-
200
204
/* HSE division factor for RTC clock must be set to ensure that
201
205
* the clock supplied to the RTC is less than or equal to 1 MHz
202
206
*/
@@ -230,21 +234,27 @@ static void RTC_initClock(sourceClock_t source)
230
234
#else
231
235
#error "Could not define RTCClockSelection"
232
236
#endif /* STM32F1xx */
233
- if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInit ) != HAL_OK ) {
234
- Error_Handler ();
235
- }
237
+ #endif /* RCC_PERIPHCLK_RTC_WDG_BLEWKUP */
236
238
} else if (source == LSI_CLOCK ) {
237
239
/* Enable the clock if not already set by user */
238
240
enableClock (LSI_CLOCK );
239
-
241
+ #if defined(RCC_PERIPHCLK_RTC_WDG_BLEWKUP )
242
+ PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_BLEWKUP ;
243
+ PeriphClkInit .RTCWDGBLEWKUPClockSelection = RCC_RTC_WDG_BLEWKUP_CLKSOURCE_LSI ;
244
+ #else
240
245
PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC ;
241
246
PeriphClkInit .RTCClockSelection = RCC_RTCCLKSOURCE_LSI ;
242
- if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInit ) != HAL_OK ) {
243
- Error_Handler ();
244
- }
247
+ #endif /* RCC_PERIPHCLK_RTC_WDG_BLEWKUP */
245
248
} else {
249
+ /* Invalid clock source */
250
+ Error_Handler ();
251
+ }
252
+ if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInit ) != HAL_OK ) {
246
253
Error_Handler ();
247
254
}
255
+ #if defined(__HAL_RCC_RTC_CLK_ENABLE )
256
+ __HAL_RCC_RTC_CLK_ENABLE ();
257
+ #endif
248
258
}
249
259
250
260
/**
@@ -451,7 +461,9 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
451
461
RtcHandle .Init .HourFormat = (format == HOUR_FORMAT_12 ) ? RTC_HOURFORMAT_12 : RTC_HOURFORMAT_24 ;
452
462
RtcHandle .Init .OutPut = RTC_OUTPUT_DISABLE ;
453
463
RtcHandle .Init .OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH ;
464
+ #if defined(RTC_OUTPUT_TYPE_OPENDRAIN )
454
465
RtcHandle .Init .OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN ;
466
+ #endif
455
467
#if defined(RTC_OUTPUT_PULLUP_NONE )
456
468
RtcHandle .Init .OutPutPullUp = RTC_OUTPUT_PULLUP_NONE ;
457
469
#endif
@@ -507,6 +519,14 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
507
519
reinit = true;
508
520
} else {
509
521
// RTC is already initialized
522
+ #if defined(__HAL_RCC_GET_RTC_WDG_BLEWKUP_CLK_CONFIG )
523
+ uint32_t oldRtcClockSource = __HAL_RCC_GET_RTC_WDG_BLEWKUP_CLK_CONFIG ();
524
+ oldRtcClockSource = ((oldRtcClockSource == RCC_RTC_WDG_BLEWKUP_CLKSOURCE_LSE ) ? LSE_CLOCK :
525
+ (oldRtcClockSource == RCC_RTC_WDG_BLEWKUP_CLKSOURCE_LSI ) ? LSI_CLOCK :
526
+ (oldRtcClockSource == RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 ) ? HSI_CLOCK :
527
+ // default case corresponding to no clock source
528
+ 0xFFFFFFFF );
529
+ #else
510
530
uint32_t oldRtcClockSource = __HAL_RCC_GET_RTC_SOURCE ();
511
531
oldRtcClockSource = ((oldRtcClockSource == RCC_RTCCLKSOURCE_LSE ) ? LSE_CLOCK :
512
532
(oldRtcClockSource == RCC_RTCCLKSOURCE_LSI ) ? LSI_CLOCK :
@@ -521,7 +541,7 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
521
541
#endif
522
542
// default case corresponding to no clock source
523
543
0xFFFFFFFF );
524
-
544
+ #endif
525
545
#if defined(STM32F1xx )
526
546
if ((RtcHandle .DateToUpdate .WeekDay == 0 )
527
547
&& (RtcHandle .DateToUpdate .Month == 0 )
@@ -711,8 +731,8 @@ void RTC_SetTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSe
711
731
/*RTC_TimeStruct.SubSeconds = subSeconds;*/
712
732
/*RTC_TimeStruct.SecondFraction = 0;*/
713
733
#endif /* RTC_SSR_SS */
714
- RTC_TimeStruct .DayLightSaving = RTC_STOREOPERATION_RESET ;
715
- RTC_TimeStruct .StoreOperation = RTC_DAYLIGHTSAVING_NONE ;
734
+ RTC_TimeStruct .DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
735
+ RTC_TimeStruct .StoreOperation = RTC_STOREOPERATION_RESET ;
716
736
#else
717
737
UNUSED (period );
718
738
#endif /* !STM32F1xx */
@@ -1192,7 +1212,8 @@ void RTC_Alarm_IRQHandler(void)
1192
1212
defined(STM32F091xC ) || defined(STM32F098xx ) || defined(STM32F070xB ) || \
1193
1213
defined(STM32F030xC ) || defined(STM32G0xx ) || defined(STM32H5xx ) || \
1194
1214
defined(STM32L0xx ) || defined(STM32L5xx ) || defined(STM32U0xx ) || \
1195
- defined(STM32U3xx ) || defined(STM32U5xx ) || defined(STM32WBAxx )
1215
+ defined(STM32U3xx ) || defined(STM32U5xx ) || defined(STM32WB0x ) || \
1216
+ defined(STM32WBAxx )
1196
1217
// In some cases, the same vector is used to manage WakeupTimer,
1197
1218
// but with a dedicated HAL IRQHandler
1198
1219
HAL_RTCEx_WakeUpTimerIRQHandler (& RtcHandle );
0 commit comments