Skip to content

Commit 961c8da

Browse files
committed
STM32F1 RTC : Date read after reset
F1 is the only STM32 family where RTC date is not saved into registers
1 parent 45cbdc8 commit 961c8da

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

targets/TARGET_STM/rtc_api.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ So by moving it 68 years forward from 1970, it become 1969-2067 which include 19
189189
68 is also a multiple of 4 so it let the leap year synchronized.
190190
191191
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.
193194
It is then not a problem to not use shifts.
194195
*/
195196

@@ -206,16 +207,25 @@ time_t rtc_read(void)
206207
HAL_RTC_GetTime(&RtcHandle, &timeStruct, RTC_FORMAT_BIN);
207208
HAL_RTC_GetDate(&RtcHandle, &dateStruct, RTC_FORMAT_BIN);
208209

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+
209220
// 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 */
211223
timeinfo.tm_mon = dateStruct.Month - 1;
212224
timeinfo.tm_mday = dateStruct.Date;
213225
timeinfo.tm_year = dateStruct.Year + 68;
214226
timeinfo.tm_hour = timeStruct.Hours;
215227
timeinfo.tm_min = timeStruct.Minutes;
216228
timeinfo.tm_sec = timeStruct.Seconds;
217-
// Daylight Saving Time information is not available
218-
timeinfo.tm_isdst = -1;
219229

220230
// Convert to timestamp
221231
time_t t;

0 commit comments

Comments
 (0)