cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 RTC skips a second on subsecond rollover

TEgli.1
Associate

It appears that there is some unusual behaviour taking place when I read the time shadow register from the RTC.

My application reads the RTC every 1000 systicks and prints the information.

When the subsecond component rolls over to greater than the subsecond fraction component, the second field fails to increment. I am unsure if this is expected behaviour, but it seems errant to me.

My hope is that someone might be able to suggest that I am going something wrong.

See attached image

Code snippet:

void board_debug_print_rtc(RTC_HandleTypeDef * stm32_rtc)
{
    RTC_TimeTypeDef time = {0};
    RTC_DateTypeDef date = {0};
    int response_time = 0;
    int response_date = 0;
 
    taskENTER_CRITICAL();
 
    response_time = HAL_RTC_GetTime(stm32_rtc, &time, RTC_FORMAT_BIN);
    response_date = HAL_RTC_GetDate(stm32_rtc, &date, RTC_FORMAT_BIN);
 
    taskEXIT_CRITICAL();
 
    float dec_seconds = (float)(time.SubSeconds) / (float)(time.SecondFraction);
    uint8_t dec_sec_fixed = (uint8_t) (dec_seconds * 100.);
 
    if((response_date == HAL_OK) && (response_time == HAL_OK))
    {
        printf("STMRTC:YYMMDDTHHMMSS: %02d:%02d:%02dT%02d:%02d:%02d.%02d\r\n",
        date.Year,date.Month,date.Date,time.Hours,time.Minutes,time.Seconds,dec_sec_fixed );
    }
    else
    {
        printf("STM32 RTC:Read FAILED:\r\n");
    }
}

1 REPLY 1

Normally I would say, check the BYPSHD bit setting, but given the RTC erratum it does not matter.

Do as outlined in errata, i.e. read twice until you get two identical readings.

JW