cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H5 RTC register bug?

Imre
Associate III

Hello

I have found a bug that stops updating the RTC_TR register. There is no problem with the RTC clock itself, it is ticking but the content of RTC_TR might in some specific use cases stop updating.

I use the latest STM32CubeH5 Firmware Package v1.5.0 for STM32H5.

 

The problem:

When only using the function HAL_RTC_GetTime(const RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format), the time stored in sTime is not updated. I even printed the content of RTC->TR and it is stuck, not updating.

However, when I use it together with HAL_RTC_GetDate(), the RTC->TR is changing. When stop calling the HAL_RTC_GetDate(), the RTC->TR is stuck.

With following example code, in C, I narrowed it down that it relates to access of RTC_SSR register.

void call_this_every_second(void) {
  static int8_t time = 20;
  if (time > 0) {
    volatile uint32_t ssr = RTC->SSR;
    if (time > 10) {
      volatile uint32_t dr = RTC->DR;
    }
    --time;
  } else if (time == 0) {
    --time;
    volatile uint32_t dr = RTC->DR;
  }
  printf("0x%lx\n", RTC->TR);
}

The output will be:

0x0
0x1
0x2
0x3
0x4
0x5
0x6
0x7
0x8
0x9
0x10
0x11
0x11
0x11
0x11
0x11
0x11
0x11
0x11
0x11
0x11
0x11
0x22
0x23
0x24
0x25
0x26

Can someone confirm my findings?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Call HAL_RTC_GetDate every time after you call HAL_RTC_GetTime. The time register is frozen until you read the date. This is intentional to keep time/date readings consistent.

stm32h5xx-hal-driver/Src/stm32h5xx_hal_rtc.c at 8c41bbe0b445f5036163d2ac637b50962d8b2f21 · STMicroelectronics/stm32h5xx-hal-driver

 

TDK_0-1743170541802.png

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
Imre
Associate III

These are my settings for the RTC:

        /*
         * RTC is clocked from HSE/50. HSE = 16 MHz -> 320 kHz on RTC
         * RTC internal clock will run at 320k/((127+1)+(2499+1)) = 1 Hz
         */
        hrtc.Instance = RTC;
        hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
        hrtc.Init.AsynchPrediv = 127;
        hrtc.Init.SynchPrediv = 2499;
        hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
        hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
        hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
        hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
        hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
        hrtc.Init.BinMode = RTC_BINARY_NONE;
        status = HAL_RTC_Init(&hrtc);

With BYPSHAD=0 (which is default), you always have to read RTC->DR as the last register, after RTC->SSR and RTC->TR.

JW

TDK
Guru

Call HAL_RTC_GetDate every time after you call HAL_RTC_GetTime. The time register is frozen until you read the date. This is intentional to keep time/date readings consistent.

stm32h5xx-hal-driver/Src/stm32h5xx_hal_rtc.c at 8c41bbe0b445f5036163d2ac637b50962d8b2f21 · STMicroelectronics/stm32h5xx-hal-driver

 

TDK_0-1743170541802.png

 

If you feel a post has answered your question, please click "Accept as Solution".