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;
}