@@ -138,12 +138,10 @@ static void RTC_initClock(sourceClock_t source)
138138 /* HSE max is 16 MHZ divided by 128 --> 125 KHz */
139139 PeriphClkInit .RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV128 ;
140140 HSEDiv = 128 ;
141- #elif defined(STM32F0xx ) || defined(STM32F3xx ) || defined(STM32G0xx ) || \
142- defined(STM32G4xx ) || defined(STM32L4xx ) || defined(STM32L5xx ) || \
143- defined(STM32WBxx )
141+ #elif defined(RCC_RTCCLKSOURCE_HSE_DIV32 ) && !defined(RCC_RTCCLKSOURCE_HSE_DIV31 )
144142 PeriphClkInit .RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV32 ;
145143 HSEDiv = 32 ;
146- #elif defined(STM32L0xx ) || defined( STM32L1xx )
144+ #elif ! defined(RCC_RTCCLKSOURCE_HSE_DIV31 )
147145 if ((HSE_VALUE / 2 ) <= HSE_RTC_MAX ) {
148146 PeriphClkInit .RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV2 ;
149147 HSEDiv = 2 ;
@@ -157,12 +155,12 @@ static void RTC_initClock(sourceClock_t source)
157155 PeriphClkInit .RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV16 ;
158156 HSEDiv = 16 ;
159157 }
160- #elif defined(STM32F2xx ) || defined( STM32F4xx ) || defined( STM32F7xx ) || defined( STM32H7xx )
158+ #elif defined(RCC_RTCCLKSOURCE_HSE_DIV31 )
161159 /* Not defined for STM32F2xx */
162160#ifndef RCC_RTCCLKSOURCE_HSE_DIVX
163161#define RCC_RTCCLKSOURCE_HSE_DIVX 0x00000300U
164162#endif /* RCC_RTCCLKSOURCE_HSE_DIVX */
165- #if defined(STM32H7xx )
163+ #if defined(RCC_RTCCLKSOURCE_HSE_DIV63 )
166164#define HSEDIV_MAX 64
167165#define HSESHIFT 12
168166#else
@@ -176,7 +174,7 @@ static void RTC_initClock(sourceClock_t source)
176174 }
177175 }
178176#else
179- #error "Unknown Family - could not define RTCClockSelection"
177+ #error "Could not define RTCClockSelection"
180178#endif /* STM32F1xx */
181179 if ((HSE_VALUE / HSEDiv ) > HSE_RTC_MAX ) {
182180 Error_Handler ();
@@ -340,19 +338,19 @@ void RTC_init(hourFormat_t format, sourceClock_t source, bool reset)
340338 }
341339 RtcHandle .Init .OutPut = RTC_OUTPUT_DISABLE ;
342340 RTC_getPrediv ((int8_t * ) & (RtcHandle .Init .AsynchPrediv ), (int16_t * ) & (RtcHandle .Init .SynchPrediv ));
343- #if defined(STM32G0xx ) || defined( STM32H7xx ) || defined( STM32L0xx ) || defined( STM32L4xx ) || defined( STM32L5xx )
341+ #if defined(RTC_OUTPUT_REMAP_NONE )
344342 RtcHandle .Init .OutPutRemap = RTC_OUTPUT_REMAP_NONE ;
345- #endif /* STM32H7xx || STM32L0xx || STM32L4xx || STM32L5xx */
343+ #endif /* RTC_OUTPUT_REMAP_NONE */
346344 RtcHandle .Init .OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH ;
347345 RtcHandle .Init .OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN ;
348346#endif /* STM32F1xx */
349347
350348 HAL_RTC_Init (& RtcHandle );
351349
352- #if ! defined(STM32F1xx ) && !defined( STM32F2xx ) && !defined( STM32L1xx ) || defined( STM32L1_ULPH )
350+ #if defined(RTC_CR_BYPSHAD )
353351 /* Enable Direct Read of the calendar registers (not through Shadow) */
354352 HAL_RTCEx_EnableBypassShadow (& RtcHandle );
355- #endif /* !STM32F1xx && !STM32F2xx */
353+ #endif
356354
357355 HAL_NVIC_SetPriority (RTC_Alarm_IRQn , RTC_IRQ_PRIO , RTC_IRQ_SUBPRIO );
358356 HAL_NVIC_EnableIRQ (RTC_Alarm_IRQn );
@@ -409,11 +407,11 @@ void RTC_SetTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSe
409407 } else {
410408 RTC_TimeStruct .TimeFormat = RTC_HOURFORMAT12_AM ;
411409 }
412- #if ! defined(STM32F2xx ) && !defined( STM32L1xx ) || defined( STM32L1_ULPH )
410+ #if defined(RTC_SSR_SS )
413411 /* subSeconds is read only, so no need to set it */
414412 /*RTC_TimeStruct.SubSeconds = subSeconds;*/
415413 /*RTC_TimeStruct.SecondFraction = 0;*/
416- #endif /* !STM32F2xx && !STM32L1xx || STM32L1_ULPH */
414+ #endif /* RTC_SSR_SS */
417415 RTC_TimeStruct .DayLightSaving = RTC_STOREOPERATION_RESET ;
418416 RTC_TimeStruct .StoreOperation = RTC_DAYLIGHTSAVING_NONE ;
419417#else
@@ -451,13 +449,13 @@ void RTC_GetTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *s
451449 * period = HOUR_AM ;
452450 }
453451 }
454- #if (! defined(STM32F2xx ) && !defined( STM32L1xx )) || defined( STM32L1_ULPH )
452+ #if defined(RTC_SSR_SS )
455453 if (subSeconds != NULL ) {
456454 * subSeconds = ((predivSync - RTC_TimeStruct .SubSeconds ) * 1000 ) / (predivSync + 1 );
457455 }
458456#else
459457 UNUSED (subSeconds );
460- #endif
458+ #endif /* RTC_SSR_SS */
461459#else
462460 UNUSED (period );
463461 UNUSED (subSeconds );
@@ -538,7 +536,7 @@ void RTC_StartAlarm(uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds
538536 RTC_AlarmStructure .AlarmTime .Minutes = minutes ;
539537 RTC_AlarmStructure .AlarmTime .Hours = hours ;
540538#if !defined(STM32F1xx )
541- #if ! defined(STM32F2xx ) && !defined( STM32L1xx ) || defined( STM32L1_ULPH )
539+ #if defined(RTC_SSR_SS )
542540 if (subSeconds < 1000 ) {
543541 RTC_AlarmStructure .AlarmSubSecondMask = predivSync_bits << RTC_ALRMASSR_MASKSS_Pos ;
544542 RTC_AlarmStructure .AlarmTime .SubSeconds = predivSync - (subSeconds * (predivSync + 1 )) / 1000 ;
@@ -547,7 +545,7 @@ void RTC_StartAlarm(uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds
547545 }
548546#else
549547 UNUSED (subSeconds );
550- #endif /* !STM32F2xx && !STM32L1xx || STM32L1_ULPH */
548+ #endif /* RTC_SSR_SS */
551549 if (period == HOUR_PM ) {
552550 RTC_AlarmStructure .AlarmTime .TimeFormat = RTC_HOURFORMAT12_PM ;
553551 } else {
@@ -635,13 +633,13 @@ void RTC_GetAlarm(uint8_t *day, uint8_t *hours, uint8_t *minutes, uint8_t *secon
635633 * period = HOUR_AM ;
636634 }
637635 }
638- #if ! defined(STM32F2xx ) && !defined( STM32L1xx ) || defined( STM32L1_ULPH )
636+ #if defined(RTC_SSR_SS )
639637 if (subSeconds != NULL ) {
640638 * subSeconds = ((predivSync - RTC_AlarmStructure .AlarmTime .SubSeconds ) * 1000 ) / (predivSync + 1 );
641639 }
642640#else
643641 UNUSED (subSeconds );
644- #endif /* !STM32F2xx && !STM32L1xx || STM32L1_ULPH */
642+ #endif /* RTC_SSR_SS */
645643 if (mask != NULL ) {
646644 * mask = OFF_MSK ;
647645 if (!(RTC_AlarmStructure .AlarmMask & RTC_ALARMMASK_SECONDS )) {
0 commit comments