RTC inconsistent weekday Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Thargon
Posts: 135
Joined: Wed Feb 04, 2015 5:03 pm
Location: CITEC, Bielefeld University, germany
Has thanked: 15 times
Been thanked: 24 times
Contact:

RTC inconsistent weekday  Topic is solved

Postby Thargon » Thu Feb 21, 2019 1:16 pm

Hi,

I noticed an issue that the weekday is reported differently for the same date written to the RTC on various platforms.
Specifically, I compared a STM32F1 (RTCv1) and STM32F4 (RTCv2) and the latter reports one day off, e.g. stating that a date is a Friday although it ought to be Thursday.
Is it just me (so I have to check my configs once again), or can others reproduce this behavior?
In case I missed something in my code, the thread can be closed ;)
Otherwise it should be moved to bug reports, though.

Best regards,
Thomas

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: RTC inconsistent weekday

Postby Giovanni » Thu Feb 21, 2019 3:02 pm

It could be a bug, RTCv1 hasn't been used much, just F1 used it.

Giovanni

Thargon
Posts: 135
Joined: Wed Feb 04, 2015 5:03 pm
Location: CITEC, Bielefeld University, germany
Has thanked: 15 times
Been thanked: 24 times
Contact:

Re: RTC inconsistent weekday

Postby Thargon » Mon Feb 25, 2019 3:40 pm

Hi,
I did some more investigation and it seems, that it's just the other way around.

I am using the C tm structure only and the interface functions rtcConvertStructTmToDateTime(), rtcSetTime(), rtcGetTime(), and rtcConvertDateTimeToStructTm(). So everything that interacts with the hardware and does the calculation is on the ChibiOS-Level. When interpreting the well-defined struct tm data, the weekday is actually correct only for the F1 platform. I've tested an F4 and L4 and both have the offset of one weekday in "the future".
For me this seems as if RTCv2 has some issues, not v1. Or you optimized for the buggy v1 at the HAL level level and thereby broke the correct v2 ;)

Best regards,
Thomas

PS: For the C tm structure the weekday is defined to be a value in [0..6] as the number of days after Sunday (thus Monday = 1). The RTCDateTime struct defines the weekday just as a value in [1..7] with no further information. I could imagine that the error has something to do with that imprecise specification.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: RTC inconsistent weekday

Postby Giovanni » Sun Jul 14, 2019 7:39 am

It agree, it is the RTCv2 implementation to be wrong, I also found this in the code (forgot about it...).

Code: Select all

#define RTC_DAY_CATURDAY            0U
#define RTC_DAY_MONDAY              1U
#define RTC_DAY_TUESDAY             2U
#define RTC_DAY_WEDNESDAY           3U
#define RTC_DAY_THURSDAY            4U
#define RTC_DAY_FRIDAY              5U
#define RTC_DAY_SATURDAY            6U
#define RTC_DAY_SUNDAY              7U


So yes, it should be 1..7.

I fixed this in trunk only, it is possible that fixing this in stable branch would break things for people that just adapted to the bug.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 4 guests