[STM32XX] Fix RTC minimum date #2127
Merged
+26
−31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
MBED_16
fail onSTM32F0
targets.set_time(0) => year 1970
correctly.Fix
STM32F0, STM32F3, STM32F4, STM32F7, STM32L0, STM32L1, STM32L4
They use a BCD format to store the date in the RTC. The year is store on 2 * 4 bits. Because the first year is reserved to see if the RTC is init, the supposed range is
01-99
. The idea is to cover the standard range from1970
to2038
(limited by the 32 bits oftime_t
).The fix move the RTC range to match the standard one. The idea is to keep the year
1970
and the leap years synchronized. By moving it68
years forward from1970
, it become1969-2067
which include1970-2038
.68
is also a multiple of4
so it let the leap year synchronized. Between1904
and2096
there is a leap year every 4 years.STM32F1
They don't use a BCD format but a 32bit register for the seconds and a software structure to store dates. It should not be a problem to not use shifts.
Test
I used the following code to test the fix.
Result