@@ -144,28 +144,8 @@ void rtc_init(void)
144
144
145
145
void rtc_free (void )
146
146
{
147
- #if !MBED_CONF_TARGET_LSE_AVAILABLE
148
- // Enable Power clock
149
- __HAL_RCC_PWR_CLK_ENABLE ();
150
-
151
- // Enable access to Backup domain
152
- HAL_PWR_EnableBkUpAccess ();
153
-
154
- // Reset Backup domain
155
- __HAL_RCC_BACKUPRESET_FORCE ();
156
- __HAL_RCC_BACKUPRESET_RELEASE ();
157
-
158
147
// Disable access to Backup domain
159
148
HAL_PWR_DisableBkUpAccess ();
160
- #endif
161
-
162
- // Disable LSI and LSE clocks
163
- RCC_OscInitTypeDef RCC_OscInitStruct = {0 };
164
- RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE ;
165
- RCC_OscInitStruct .PLL .PLLState = RCC_PLL_NONE ;
166
- RCC_OscInitStruct .LSIState = RCC_LSI_OFF ;
167
- RCC_OscInitStruct .LSEState = RCC_LSE_OFF ;
168
- HAL_RCC_OscConfig (& RCC_OscInitStruct );
169
149
}
170
150
171
151
/*
@@ -209,7 +189,8 @@ So by moving it 68 years forward from 1970, it become 1969-2067 which include 19
209
189
68 is also a multiple of 4 so it let the leap year synchronized.
210
190
211
191
Information about STM32F1:
212
- 32bit register is used (no BCD format) for the seconds and a software structure to store dates.
192
+ 32bit register is used (no BCD format) for the seconds.
193
+ For date, there is no specific register, only a software structure.
213
194
It is then not a problem to not use shifts.
214
195
*/
215
196
@@ -226,16 +207,25 @@ time_t rtc_read(void)
226
207
HAL_RTC_GetTime (& RtcHandle , & timeStruct , RTC_FORMAT_BIN );
227
208
HAL_RTC_GetDate (& RtcHandle , & dateStruct , RTC_FORMAT_BIN );
228
209
210
+ #if TARGET_STM32F1
211
+ /* date information is null before first write procedure */
212
+ /* set 01/01/1970 as default values */
213
+ if (dateStruct .Year == 0 ) {
214
+ dateStruct .Year = 2 ;
215
+ dateStruct .Month = 1 ;
216
+ dateStruct .Date = 1 ;
217
+ }
218
+ #endif
219
+
229
220
// Setup a tm structure based on the RTC
230
- /* tm_wday information is ignored by mktime */
221
+ /* tm_wday information is ignored by _rtc_maketime */
222
+ /* tm_isdst information is ignored by _rtc_maketime */
231
223
timeinfo .tm_mon = dateStruct .Month - 1 ;
232
224
timeinfo .tm_mday = dateStruct .Date ;
233
225
timeinfo .tm_year = dateStruct .Year + 68 ;
234
226
timeinfo .tm_hour = timeStruct .Hours ;
235
227
timeinfo .tm_min = timeStruct .Minutes ;
236
228
timeinfo .tm_sec = timeStruct .Seconds ;
237
- // Daylight Saving Time information is not available
238
- timeinfo .tm_isdst = -1 ;
239
229
240
230
// Convert to timestamp
241
231
time_t t ;
0 commit comments