2424RTC_HandleTypeDef RtcHandle ;
2525static int rtc_initialized = 0 ;
2626
27-
28- void HAL_RTC_MspInit (RTC_HandleTypeDef * hrtc )
29- {
30- RCC_OscInitTypeDef RCC_OscInitStruct ;
31- RCC_PeriphCLKInitTypeDef PeriphClkInitStruct ;
32-
33- /*##-1- Configure LSE as RTC clock source ##################################*/
34- RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE ;
35- RCC_OscInitStruct .PLL .PLLState = RCC_PLL_NONE ;
36- RCC_OscInitStruct .LSEState = RCC_LSE_OFF ;
37- RCC_OscInitStruct .LSIState = RCC_LSI_ON ;
38- if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK )
39- {
40- return ;
41- }
42-
43- PeriphClkInitStruct .PeriphClockSelection = RCC_PERIPHCLK_RTC ;
44- PeriphClkInitStruct .RTCClockSelection = RCC_RTCCLKSOURCE_LSI ;
45- if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInitStruct ) != HAL_OK )
46- {
47- return ;
48- }
49-
50- /*##-2- Enable RTC peripheral Clocks #######################################*/
51- /* Enable RTC Clock */
52- __HAL_RCC_RTC_ENABLE ();
53- }
54-
55- #define RTC_ASYNCH_PREDIV 0x7F /* LSE as RTC clock */
56- #define RTC_SYNCH_PREDIV 0x00FF /* LSE as RTC clock */
57-
58- void RTC_CalendarBkupInit (void )
27+ void RTC_Bkp_Init (void )
5928{
60-
6129 /*##-1- Configure the RTC peripheral #######################################*/
6230 /* Configure RTC prescaler and RTC data registers */
6331 /* RTC configured as follow:
@@ -68,26 +36,14 @@ void RTC_CalendarBkupInit(void)
6836 - OutPutPolarity = High Polarity
6937 - OutPutType = Open Drain */
7038 RtcHandle .Instance = RTC ;
71- RtcHandle .Init .HourFormat = RTC_HOURFORMAT_24 ;
72- RtcHandle .Init .AsynchPrediv = RTC_ASYNCH_PREDIV ;
73- RtcHandle .Init .SynchPrediv = RTC_SYNCH_PREDIV ;
74- RtcHandle .Init .OutPut = RTC_OUTPUT_DISABLE ;
75- RtcHandle .Init .OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH ;
76- RtcHandle .Init .OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN ;
77-
78- if (HAL_RTC_Init (& RtcHandle ) != HAL_OK )
79- {
80- BOOT_LOG_ERR ("HAL_RTC_Init" );
81- return ;
82- }
83-
39+ __HAL_RCC_PWR_CLK_ENABLE ();
40+ HAL_PWR_EnableBkUpAccess ();
8441 rtc_initialized = 1 ;
8542}
8643
8744void RTCInit () {
8845 if (!rtc_initialized ) {
89- HAL_RTC_MspInit (& RtcHandle );
90- RTC_CalendarBkupInit ();
46+ RTC_Bkp_Init ();
9147 }
9248}
9349
0 commit comments