Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition in RtcGetCalendarValue on NucleoL476 board #1588

Open
ndiddy99 opened this issue Dec 8, 2023 · 0 comments
Open

Race condition in RtcGetCalendarValue on NucleoL476 board #1588

ndiddy99 opened this issue Dec 8, 2023 · 0 comments

Comments

@ndiddy99
Copy link

ndiddy99 commented Dec 8, 2023

The RtcGetCalendarValue function checks the RTC subsecond register for consistency but does not check the date or time registers. Because the code doesn't use the RTC shadow registers (see here), the code needs to check the subsecond, time, and date registers to make sure none of them have changed. Our internal fix looks like this:


    uint64_t calendarValue = 0;
    volatile uint32_t firstSSR;
    volatile uint32_t firstTR;
    volatile uint32_t firstDR;
    uint32_t correction;
    uint32_t seconds;

    // The LoRaWAN stack bypasses the RTC's shadow registers, so we need to make
    // sure the RTC isn't in the process of updating any of its registers while
    // we get the date & time.
    do
    {
        firstSSR = RTC->SSR;
        firstTR = RTC->TR;
        firstDR = RTC->DR;
        HAL_RTC_GetTime( &RtcHandle, time, RTC_FORMAT_BIN );
        HAL_RTC_GetDate( &RtcHandle, date, RTC_FORMAT_BIN );
    } while ((firstSSR != RTC->SSR) || (firstTR != RTC->TR) || (firstDR != RTC->DR));

I haven't checked to see if the board files for the other STM32 processors have the same issue, but it's probably something to look at.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant