cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible RTC on STM32H7 loses 1 second on each power cycle?

HTD
Senior III

My setup is STM32H745I-DISCO board with VBAT connected to a 3V2 battery (solder bridge removed).

Here's my clock configuration:

0693W00000Uo7dZQAR.png0693W00000Uo7doQAB.pngWhen I set up the date and time with my UI and then watch how it ticks in real time - nothing happens. I mean - it holds time without problems.

Then I power the device off, wait a minute or two, power it back again - the time lags exactly 1 second. I repeated the test a couple of times, each time losing a second. Then I tried just resetting the device - it seems to work exactly the same - a second "eaten", so the lag increases each restart.

What's interesting, when the timer IRQs were set to 5 priority (like I wanted to call RTOS functions from ISRs) - the clock seemed to not work properly at all, it was hardly ticking. So I removed RTOS priority and set RTC IRQ to zero priority and it doesn't lag during normal device operation.

My question: how to remove the restart lag beside just pushing the clock forward one second on each start? Is there something in HAL I should check?

2 REPLIES 2

Thanks, so it's a known issue, I should add a conditional initialization - when the date is set I skip rest of the register setting and it should work.

HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc)
{
  HAL_StatusTypeDef status = HAL_ERROR;
 
  /* Check RTC handler */
  if(hrtc != NULL)
  {
    if (hrtc->Instance->DR > 0) // FIX: Seconds lost on reset.
    {
      hrtc->State = HAL_RTC_STATE_READY;
      return HAL_OK;
    }
    // ... the rest of the original code...
  }
}

I added this fix and it seems to do the job. The clock keeps the time on restarts. Should I check something else? BTW, my app sets date, it is very important, because the date is used for filesystem operations and time-stamping data.