Skip to main content
Amilton Rogério da Silva
Associate III
July 24, 2019
Question

STM32H743 / STM32H750 RTC BUG - hour keep counting above 23

  • July 24, 2019
  • 5 replies
  • 2142 views

Hi,

  What could be possibly wrong to make the RTC hour keep count up above 23 hour. With some boards it works correctly, going to 00 from 23. but some other keep count up 24, 25...

  How is that possible? There is any configuration to do that?

This topic has been closed for replies.

5 replies

Uwe Bonnes
Chief
July 24, 2019

Did you have a look at RTC->TR. Are there really values above 23 HT and HU?

Amilton Rogério da Silva
Associate III
July 24, 2019

Hi Uwe and thank you for answer,

   I need to say yes once I am using the HAL library to read the RTC, and it get the TR value from the RTC instance.

HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)

{

 uint32_t tmpreg;

 /* Check the parameters */

 assert_param(IS_RTC_FORMAT(Format));

 /* Get subseconds structure field from the corresponding register*/

 sTime->SubSeconds = (uint32_t)(hrtc->Instance->SSR);

 /* Get SecondFraction structure field from the corresponding register field*/

 sTime->SecondFraction = (uint32_t)(hrtc->Instance->PRER & RTC_PRER_PREDIV_S);

 /* Get the TR register */

 tmpreg = (uint32_t)(hrtc->Instance->TR & RTC_TR_RESERVED_MASK);

 /* Fill the structure fields with the read parameters */

 sTime->Hours  = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> RTC_TR_HU_Pos);

 sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >> RTC_TR_MNU_Pos);

 sTime->Seconds = (uint8_t)( tmpreg & (RTC_TR_ST | RTC_TR_SU));

 sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM))    >> RTC_TR_PM_Pos);

 /* Check the input parameters format */

 if(Format == RTC_FORMAT_BIN)

 {

 /* Convert the time structure parameters to Binary format */

 sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours);

 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes);

 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds);

 }

 return HAL_OK;

}

  Obs.: Removing the battery and soldering it again, made the bug desapear for now. But honestly, this is not a solution if it happen again with a costumer.

Tesla DeLorean
Guru
July 24, 2019

"But honestly, this is not a solution if it happen again with a customer."

Perhap you could recognize it is occurring and reset the RTC. Surely a way to do that without removing the battery. Consider a link or switch so you don't need to physically desolder stuff.

Sense the failure state, so next time you can root-cause the issue with an FAE. Perhaps file a support ticket now so you can get feedback or answers from their FAQ.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
waclawek.jan
Super User
July 24, 2019

This happens e.g. if you set the 12-hour format and set the hour beyond 12 hours.

On this forum this was reported to happen when using "libraries" and the init struct does not have all fields filled in properly.

When it happens, read out and check the RTC registers' content.

JW

aling.11
Visitor II
July 15, 2022

I have the same problem.

flow work for me.

   RTC_TimeTypeDef sTime;

sTime.TimeFormat =RTC_FORMAT_BIN;

sTime.Hours = Hours;        

sTime.Minutes = Min;        

sTime.Seconds = Sec;      

sTime.DayLightSaving = 0; <----

sTime.StoreOperation = 0; <-----

  HAL_RTC_SetTime(hrtc, &sTime, RTC_FORMAT_BIN); //儲存設定值

waclawek.jan
Super User
July 15, 2022

Make sure you set *all* fields of sTime.

JW

Tesla DeLorean
Guru
July 15, 2022

+1 **THIS**

Failure to properly initialize auto/local variables, which live on the stack with random content, is the cause of a million latent failures. ST code is rife with them, as is the use of globals.

RTC_TimeTypeDef sTime = {0}; // Ensures at least you're starting with a clean and consistent sheet

It also helps the compiler/optimizer as it hints at intent.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..