@@ -42,6 +42,7 @@ static RTC_HandleTypeDef RtcHandle;
42
42
void rtc_init (void )
43
43
{
44
44
RCC_OscInitTypeDef RCC_OscInitStruct ;
45
+ RCC_PeriphCLKInitTypeDef PeriphClkInitStruct ;
45
46
uint32_t rtc_freq = 0 ;
46
47
47
48
#if DEVICE_RTC_LSI
@@ -51,26 +52,30 @@ void rtc_init(void)
51
52
52
53
RtcHandle .Instance = RTC ;
53
54
55
+ // Note : Due to a change inside stm32l0xx_hal_rcc.c (v1.2 to v1.5) the bit DBP of the register
56
+ // PWR_CR is now reset by the fonction HAL_RCC_OscConfig().
57
+ // Enable Power clock
58
+ __PWR_CLK_ENABLE ();
59
+
60
+ // Enable access to Backup domain
61
+ HAL_PWR_EnableBkUpAccess ();
62
+
54
63
#if !DEVICE_RTC_LSI
55
64
// Enable LSE Oscillator
56
65
RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_LSE ;
57
66
RCC_OscInitStruct .PLL .PLLState = RCC_PLL_NONE ; // Mandatory, otherwise the PLL is reconfigured!
58
67
RCC_OscInitStruct .LSEState = RCC_LSE_ON ; // External 32.768 kHz clock on OSC_IN/OSC_OUT
59
- if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) == HAL_OK ) {
60
- // Connect LSE to RTC
61
- __HAL_RCC_RTC_CLKPRESCALER (RCC_RTCCLKSOURCE_LSE );
62
- __HAL_RCC_RTC_CONFIG (RCC_RTCCLKSOURCE_LSE );
63
- rtc_freq = LSE_VALUE ;
64
- } else {
68
+ if (HAL_RCC_OscConfig (& RCC_OscInitStruct ) != HAL_OK ) {
65
69
error ("Cannot initialize RTC with LSE\n" );
66
70
}
71
+ // Connect LSE to RTC
72
+ PeriphClkInitStruct .PeriphClockSelection = RCC_PERIPHCLK_RTC ;
73
+ PeriphClkInitStruct .RTCClockSelection = RCC_RTCCLKSOURCE_LSE ;
74
+ if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInitStruct ) != HAL_OK ) {
75
+ error ("Cannot initialize RTC with LSI\n" );
76
+ }
77
+ rtc_freq = LSE_VALUE ;
67
78
#else
68
- // Enable Power clock
69
- __PWR_CLK_ENABLE ();
70
-
71
- // Enable access to Backup domain
72
- HAL_PWR_EnableBkUpAccess ();
73
-
74
79
// Reset Backup domain
75
80
__HAL_RCC_BACKUPRESET_FORCE ();
76
81
__HAL_RCC_BACKUPRESET_RELEASE ();
@@ -84,8 +89,11 @@ void rtc_init(void)
84
89
error ("RTC error: LSI clock initialization failed." );
85
90
}
86
91
// Connect LSI to RTC
87
- __HAL_RCC_RTC_CLKPRESCALER (RCC_RTCCLKSOURCE_LSI );
88
- __HAL_RCC_RTC_CONFIG (RCC_RTCCLKSOURCE_LSI );
92
+ PeriphClkInitStruct .PeriphClockSelection = RCC_PERIPHCLK_RTC ;
93
+ PeriphClkInitStruct .RTCClockSelection = RCC_RTCCLKSOURCE_LSI ;
94
+ if (HAL_RCCEx_PeriphCLKConfig (& PeriphClkInitStruct ) != HAL_OK ) {
95
+ error ("Cannot initialize RTC with LSI\n" );
96
+ }
89
97
// This value is LSI typical value. To be measured precisely using a timer input capture for example.
90
98
rtc_freq = 38000 ;
91
99
#endif
@@ -186,6 +194,8 @@ time_t rtc_read(void)
186
194
timeinfo .tm_hour = timeStruct .Hours ;
187
195
timeinfo .tm_min = timeStruct .Minutes ;
188
196
timeinfo .tm_sec = timeStruct .Seconds ;
197
+ // Daylight Saving Time information is not available
198
+ timeinfo .tm_isdst = -1 ;
189
199
190
200
// Convert to timestamp
191
201
time_t t = mktime (& timeinfo );
0 commit comments