@@ -71,7 +71,9 @@ static voidCallbackPtr RTCSubSecondsUnderflowIrqCallback = NULL;
71
71
#endif
72
72
static sourceClock_t clkSrc = LSI_CLOCK ;
73
73
static uint32_t clkVal = LSI_VALUE ;
74
+ #if !defined(LL_RCC_LSCO_CLKSOURCE_HSI64M_DIV2048 )
74
75
static uint8_t HSEDiv = 0 ;
76
+ #endif
75
77
#if !defined(STM32F1xx )
76
78
/* predividers values */
77
79
static uint8_t predivSync_bits = 0xFF ;
@@ -122,6 +124,13 @@ void RTC_SetClockSource(sourceClock_t source)
122
124
clkSrc = source ;
123
125
if (source == LSE_CLOCK ) {
124
126
clkVal = LSE_VALUE ;
127
+ #if defined(LL_RCC_LSCO_CLKSOURCE_HSI64M_DIV2048 )
128
+ } else if (source == HSI_CLOCK ) {
129
+ /* HSI division factor for RTC clock must be define to ensure that
130
+ * the clock supplied to the RTC is less than or equal to 1 MHz
131
+ */
132
+ clkVal = 32000 ; /* HSI64M divided by 64 --> 1 MHz */
133
+ #else
125
134
} else if (source == HSE_CLOCK ) {
126
135
/* HSE division factor for RTC clock must be define to ensure that
127
136
* the clock supplied to the RTC is less than or equal to 1 MHz
@@ -163,6 +172,7 @@ void RTC_SetClockSource(sourceClock_t source)
163
172
Error_Handler ();
164
173
}
165
174
clkVal = HSE_VALUE / HSEDiv ;
175
+ #endif
166
176
} else if (source == LSI_CLOCK ) {
167
177
clkVal = LSI_VALUE ;
168
178
} else {
@@ -187,16 +197,20 @@ static void RTC_initClock(sourceClock_t source)
187
197
if (source == LSE_CLOCK ) {
188
198
/* Enable the clock if not already set by user */
189
199
enableClock (LSE_CLOCK );
190
-
200
+ #if defined(RCC_PERIPHCLK_RTC_WDG_BLEWKUP )
201
+ PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_BLEWKUP ;
202
+ PeriphClkInit .RTCWDGBLEWKUPClockSelection = RCC_RTC_WDG_BLEWKUP_CLKSOURCE_LSE ;
203
+ } else if (source == HSI_CLOCK ) {
204
+ /* Enable the clock if not already set by user */
205
+ enableClock (HSI_CLOCK );
206
+ PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_BLEWKUP ;
207
+ PeriphClkInit .RTCWDGBLEWKUPClockSelection = RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 ;
208
+ #else
191
209
PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC ;
192
210
PeriphClkInit .RTCClockSelection = RCC_RTCCLKSOURCE_LSE ;
193
- if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInit ) != HAL_OK ) {
194
- Error_Handler ();
195
- }
196
211
} else if (source == HSE_CLOCK ) {
197
212
/* Enable the clock if not already set by user */
198
213
enableClock (HSE_CLOCK );
199
-
200
214
/* HSE division factor for RTC clock must be set to ensure that
201
215
* the clock supplied to the RTC is less than or equal to 1 MHz
202
216
*/
@@ -230,21 +244,27 @@ static void RTC_initClock(sourceClock_t source)
230
244
#else
231
245
#error "Could not define RTCClockSelection"
232
246
#endif /* STM32F1xx */
233
- if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInit ) != HAL_OK ) {
234
- Error_Handler ();
235
- }
247
+ #endif /* RCC_PERIPHCLK_RTC_WDG_BLEWKUP */
236
248
} else if (source == LSI_CLOCK ) {
237
249
/* Enable the clock if not already set by user */
238
250
enableClock (LSI_CLOCK );
239
-
251
+ #if defined(RCC_PERIPHCLK_RTC_WDG_BLEWKUP )
252
+ PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC_WDG_BLEWKUP ;
253
+ PeriphClkInit .RTCWDGBLEWKUPClockSelection = RCC_RTC_WDG_BLEWKUP_CLKSOURCE_LSI ;
254
+ #else
240
255
PeriphClkInit .PeriphClockSelection = RCC_PERIPHCLK_RTC ;
241
256
PeriphClkInit .RTCClockSelection = RCC_RTCCLKSOURCE_LSI ;
242
- if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInit ) != HAL_OK ) {
243
- Error_Handler ();
244
- }
257
+ #endif /* RCC_PERIPHCLK_RTC_WDG_BLEWKUP */
245
258
} else {
259
+ /* Invalid clock source */
246
260
Error_Handler ();
247
261
}
262
+ if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInit ) != HAL_OK ) {
263
+ Error_Handler ();
264
+ }
265
+ #if defined(__HAL_RCC_RTC_CLK_ENABLE )
266
+ __HAL_RCC_RTC_CLK_ENABLE ();
267
+ #endif
248
268
}
249
269
250
270
/**
@@ -451,7 +471,9 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
451
471
RtcHandle .Init .HourFormat = (format == HOUR_FORMAT_12 ) ? RTC_HOURFORMAT_12 : RTC_HOURFORMAT_24 ;
452
472
RtcHandle .Init .OutPut = RTC_OUTPUT_DISABLE ;
453
473
RtcHandle .Init .OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH ;
474
+ #if defined(RTC_OUTPUT_TYPE_OPENDRAIN )
454
475
RtcHandle .Init .OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN ;
476
+ #endif
455
477
#if defined(RTC_OUTPUT_PULLUP_NONE )
456
478
RtcHandle .Init .OutPutPullUp = RTC_OUTPUT_PULLUP_NONE ;
457
479
#endif
@@ -507,6 +529,14 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
507
529
reinit = true;
508
530
} else {
509
531
// RTC is already initialized
532
+ #if defined(__HAL_RCC_GET_RTC_WDG_BLEWKUP_CLK_CONFIG )
533
+ uint32_t oldRtcClockSource = __HAL_RCC_GET_RTC_WDG_BLEWKUP_CLK_CONFIG ();
534
+ oldRtcClockSource = ((oldRtcClockSource == RCC_RTC_WDG_BLEWKUP_CLKSOURCE_LSE ) ? LSE_CLOCK :
535
+ (oldRtcClockSource == RCC_RTC_WDG_BLEWKUP_CLKSOURCE_LSI ) ? LSI_CLOCK :
536
+ (oldRtcClockSource == RCC_RTC_WDG_BLEWKUP_CLKSOURCE_HSI64M_DIV2048 ) ? HSI_CLOCK :
537
+ // default case corresponding to no clock source
538
+ 0xFFFFFFFF );
539
+ #else
510
540
uint32_t oldRtcClockSource = __HAL_RCC_GET_RTC_SOURCE ();
511
541
oldRtcClockSource = ((oldRtcClockSource == RCC_RTCCLKSOURCE_LSE ) ? LSE_CLOCK :
512
542
(oldRtcClockSource == RCC_RTCCLKSOURCE_LSI ) ? LSI_CLOCK :
@@ -521,7 +551,7 @@ bool RTC_init(hourFormat_t format, binaryMode_t mode, sourceClock_t source, bool
521
551
#endif
522
552
// default case corresponding to no clock source
523
553
0xFFFFFFFF );
524
-
554
+ #endif
525
555
#if defined(STM32F1xx )
526
556
if ((RtcHandle .DateToUpdate .WeekDay == 0 )
527
557
&& (RtcHandle .DateToUpdate .Month == 0 )
@@ -711,8 +741,8 @@ void RTC_SetTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSe
711
741
/*RTC_TimeStruct.SubSeconds = subSeconds;*/
712
742
/*RTC_TimeStruct.SecondFraction = 0;*/
713
743
#endif /* RTC_SSR_SS */
714
- RTC_TimeStruct .DayLightSaving = RTC_STOREOPERATION_RESET ;
715
- RTC_TimeStruct .StoreOperation = RTC_DAYLIGHTSAVING_NONE ;
744
+ RTC_TimeStruct .DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
745
+ RTC_TimeStruct .StoreOperation = RTC_STOREOPERATION_RESET ;
716
746
#else
717
747
UNUSED (period );
718
748
#endif /* !STM32F1xx */
@@ -1192,7 +1222,8 @@ void RTC_Alarm_IRQHandler(void)
1192
1222
defined(STM32F091xC ) || defined(STM32F098xx ) || defined(STM32F070xB ) || \
1193
1223
defined(STM32F030xC ) || defined(STM32G0xx ) || defined(STM32H5xx ) || \
1194
1224
defined(STM32L0xx ) || defined(STM32L5xx ) || defined(STM32U0xx ) || \
1195
- defined(STM32U3xx ) || defined(STM32U5xx ) || defined(STM32WBAxx )
1225
+ defined(STM32U3xx ) || defined(STM32U5xx ) || defined(STM32WB0x ) || \
1226
+ defined(STM32WBAxx )
1196
1227
// In some cases, the same vector is used to manage WakeupTimer,
1197
1228
// but with a dedicated HAL IRQHandler
1198
1229
HAL_RTCEx_WakeUpTimerIRQHandler (& RtcHandle );
0 commit comments