2021-08-22 06:51 AM
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);
2021-08-22 08:28 AM
Don't enable RTC clock, then read out the RTC registers content after you've executed the above code, and check/post.
JW
2021-08-22 11:33 AM
Perhaps set the TimeFormat properly, isn't zero binary?
To debug perhaps output data generate by the time library, and what ends up in your structures, and finally in the RTC peripheral.
2021-08-22 10:53 PM
The device worked for several months. After reading, they revealed a shift of one day. The shift took place after a month of work. In the description of the problem, I gave how to reproduce it.
2021-08-22 11:00 PM
I read the documentation but couldn't find the ranges of values in TimeFormat. Standard library for working with time (iar). Possibly the ranges of valid values do not match.
Probably the problem is tm_mon (http://www.cplusplus.com/reference/ctime/tm/)
2021-08-23 12:22 AM
I don't use Cube/LL. I suspect the problem is in the value which is result of all the conversions, that's why I recommend to find out what exactly gets written into the RTC registers.
JW
2021-08-23 12:43 AM
There are no problems with the correct writing of the RTC registers.