Incorrect RTC operation in STM32L073CZ
Good afternoon.
I have developed a device for collecting data from sensers and storing them in external memory.
During testing, I revealed a failure in the operation of the device.
Investigation of the behavior showed that there is an error in the RTC of the microcontroller.
The RTC skips July 31st and goes on August 1st.
July 30 - utc = 1627689599
July 31 - utc = 1627689600 pass
August 1 - utc = 1627776000
If you set the time to 1627689601, then the clock works normally.
How do I fix erroneous RTC behavior?
uint32_t time = 1627689599;
const tm* out = gmtime(&time);
LL_RTC_TimeTypeDef RTC_TimeStruct = {0};
RTC_TimeStruct.Hours = __LL_RTC_CONVERT_BIN2BCD(out->tm_hour);
RTC_TimeStruct.Minutes = __LL_RTC_CONVERT_BIN2BCD(out->tm_min);
RTC_TimeStruct.Seconds = __LL_RTC_CONVERT_BIN2BCD(out->tm_sec);
LL_RTC_DateTypeDef RTC_DateStruct = {0};
RTC_DateStruct.WeekDay = __LL_RTC_CONVERT_BIN2BCD(out->tm_wday);
RTC_DateStruct.Day = __LL_RTC_CONVERT_BIN2BCD(out->tm_mday);
RTC_DateStruct.Month = __LL_RTC_CONVERT_BIN2BCD(out->tm_mon);
RTC_DateStruct.Year = __LL_RTC_CONVERT_BIN2BCD(out->tm_year);
LL_RTC_TIME_Config(RTC, RTC_TimeStruct.TimeFormat, RTC_TimeStruct.Hours,
RTC_TimeStruct.Minutes, RTC_TimeStruct.Seconds);
LL_RTC_DATE_Config(RTC, RTC_DateStruct.WeekDay,
RTC_DateStruct.Day,
RTC_DateStruct.Month,
RTC_DateStruct.Year);