@@ -189,7 +189,8 @@ So by moving it 68 years forward from 1970, it become 1969-2067 which include 19
189
189
68 is also a multiple of 4 so it let the leap year synchronized.
190
190
191
191
Information about STM32F1:
192
- 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.
193
194
It is then not a problem to not use shifts.
194
195
*/
195
196
@@ -206,16 +207,25 @@ time_t rtc_read(void)
206
207
HAL_RTC_GetTime (& RtcHandle , & timeStruct , RTC_FORMAT_BIN );
207
208
HAL_RTC_GetDate (& RtcHandle , & dateStruct , RTC_FORMAT_BIN );
208
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
+
209
220
// Setup a tm structure based on the RTC
210
- /* 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 */
211
223
timeinfo .tm_mon = dateStruct .Month - 1 ;
212
224
timeinfo .tm_mday = dateStruct .Date ;
213
225
timeinfo .tm_year = dateStruct .Year + 68 ;
214
226
timeinfo .tm_hour = timeStruct .Hours ;
215
227
timeinfo .tm_min = timeStruct .Minutes ;
216
228
timeinfo .tm_sec = timeStruct .Seconds ;
217
- // Daylight Saving Time information is not available
218
- timeinfo .tm_isdst = -1 ;
219
229
220
230
// Convert to timestamp
221
231
time_t t ;
0 commit comments