counter: stm32 rtc: improve reading registers
Synchronize reading two separate registers. In some edge cases the read registers could point different dates. Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
This commit is contained in:
parent
ad53863d1a
commit
16370a259a
1 changed files with 10 additions and 3 deletions
|
@ -192,10 +192,17 @@ static uint32_t rtc_stm32_read(const struct device *dev)
|
||||||
#endif
|
#endif
|
||||||
ARG_UNUSED(dev);
|
ARG_UNUSED(dev);
|
||||||
|
|
||||||
/* Read time and date registers */
|
/* Read time and date registers. Make sure value of the previous register
|
||||||
rtc_time = LL_RTC_TIME_Get(RTC);
|
* hasn't been changed while reading the next one.
|
||||||
|
*/
|
||||||
#if !defined(COUNTER_NO_DATE)
|
#if !defined(COUNTER_NO_DATE)
|
||||||
|
do {
|
||||||
rtc_date = LL_RTC_DATE_Get(RTC);
|
rtc_date = LL_RTC_DATE_Get(RTC);
|
||||||
|
rtc_time = LL_RTC_TIME_Get(RTC);
|
||||||
|
|
||||||
|
} while (rtc_date != LL_RTC_DATE_Get(RTC));
|
||||||
|
#else
|
||||||
|
rtc_time = LL_RTC_TIME_Get(RTC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(COUNTER_NO_DATE)
|
#if !defined(COUNTER_NO_DATE)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue