Closed PierreYvesLacroix closed 2 years ago
Hello @PierreYvesLacroix,
First, thank you for this report.
The year field must be on 2 digits in BCD format as indicated in the RM0456
The value 00 in BCD does not necessarily mean 1900. It can also mean 2000. So, the idea is not to subtract the year 1900 from the current year.
For example, 22 in BCD for the year 2022, 60 in BCD for the year 2060, and 00 in BCD for the year 2100.
With Regards,
It seems that the code is designed so that the year field is less than 99 (2 digits). But the year field for 2022 is 2022-1900 = 122 which is a value > 99 and 3 digits.
This causes 2 problems.
File stm32u5xx_hal_rtc.c (also applicable on other STM32)
1/ assert_param(IS_RTC_YEAR(sDate->Year));
We still have this assert since sDate->Year > 99 in 2022.
(Note that the control is not good on the month either since the valid values go from 0 to 11 and the control checks that the values go from 1 to 12)
2/ (uint32_t)RTC_ByteToBcd2(sDate->Year)) << RTC_DR_YU_Pos)
We have 3 digits in 2022, the conversion to BCD is done for 2 digits (no of the function and comment of the function) but it happens that it works and it will continue to work, the bug will appear only in 2060.