Skip to content

Commit b106532

Browse files
peterhinchdpgeorge
authored andcommitted
stmhal/rtc: Init uses YMD rather than backup register to detect powerup.
1 parent 8e6e9ea commit b106532

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

stmhal/rtc.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ STATIC void RTC_CalendarConfig(void);
161161

162162
void rtc_init(void) {
163163
RTCHandle.Instance = RTC;
164+
RTC_DateTypeDef date;
164165

165166
/* Configure RTC prescaler and RTC data registers */
166167
/* RTC configured as follow:
@@ -188,8 +189,8 @@ void rtc_init(void) {
188189
// record how long it took for the RTC to start up
189190
rtc_info = HAL_GetTick() - tick;
190191

191-
// check data stored in BackUp register0
192-
if (HAL_RTCEx_BKUPRead(&RTCHandle, RTC_BKP_DR0) != 0x32f2) {
192+
HAL_RTC_GetDate(&RTCHandle, &date, FORMAT_BIN);
193+
if (date.Year == 0 && date.Month ==0 && date.Date == 0) {
193194
// fresh reset; configure RTC Calendar
194195
RTC_CalendarConfig();
195196
} else {
@@ -233,9 +234,6 @@ STATIC void RTC_CalendarConfig(void) {
233234
// init error
234235
return;
235236
}
236-
237-
// write data to indicate the RTC has been set
238-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR0, 0x32f2);
239237
}
240238

241239
/*

0 commit comments

Comments
 (0)