RTCv2 sets invalid WDU value Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

RTCv2 sets invalid WDU value  Topic is solved

Postby FXCoder » Sat Oct 05, 2019 2:00 pm

Hi,
RTCDateTime.dayofweek ranges from 1 - 7.
In RTCv2 LLD rtc_encode_date(...) deducts 1 from the value of dayofweek when setting RTC.DR WDU[2:0].

Best case an incorrect or invalid (0) WDU is set in the RTC (which goes unnoticed most likely if dayofweek is ignored/unused in RTC reads).
Worst case the year value set into RTC.DR will be corrupted by underflow when RTCDateTime.dayofweek = 0 is passed in.
--
Bob

Code: Select all


Index: hal_rtc_lld.c
===================================================================
--- hal_rtc_lld.c   (revision 13074)
+++ hal_rtc_lld.c   (working copy)
@@ -194,7 +194,7 @@
   dr = dr | ((n % 10) << RTC_DR_DT_OFFSET);
 
   /* Days of week conversion.*/
-  dr = dr | ((timespec->dayofweek - 1) << RTC_DR_WDU_OFFSET);
+  dr = dr | ((timespec->dayofweek) << RTC_DR_WDU_OFFSET);
 
   return dr;
 }

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

Re: RTCv2 sets invalid WDU value

Postby Giovanni » Sat Oct 05, 2019 2:19 pm

Hi,

Fixed in trunk, it was caused by a wrong fix, 19.1 and 18.2 are unchanged.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 63 guests