cancel
Showing results for 
Search instead for 
Did you mean: 

STMH745 and RTC issue

DMast.1
Associate II

Hello, I'm using a stm32h745 on my new board with an external 32768Hz quart and setup RTC at startup as follow (using LSE):

HalErr_tError HalRtc_Init(void)
{
   HalErr_tError zError = HalErr_eNoError;
 
   /* Configure RTC prescaler and RTC data registers */
   /* RTC configured as follows:
       - Hour Format    = Format 24
       - Asynch Prediv  = Value according to source clock
       - Synch Prediv   = Value according to source clock
       - OutPut         = Output Disable
       - OutPutPolarity = High Polarity
       - OutPutType     = Open Drain */
   gRtcHandle.Instance = RTC;
 
   gRtcHandle.Init.HourFormat     = RTC_HOURFORMAT_24;
   gRtcHandle.Init.AsynchPrediv   = RTC_ASYNCH_PREDIV;
   gRtcHandle.Init.SynchPrediv    = RTC_SYNCH_PREDIV;
   gRtcHandle.Init.OutPut         = RTC_OUTPUT_DISABLE;
   gRtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
   gRtcHandle.Init.OutPutType     = RTC_OUTPUT_TYPE_OPENDRAIN;
   if (HAL_RTC_Init(&gRtcHandle) != HAL_OK)
   {
      /* Initialization Error */
      zError = HalErr_eInternal;
   }
 
   /** Enable the reference Clock input */
   if (HAL_RTCEx_SetRefClock(&gRtcHandle) != HAL_OK)
   {
      zError = HalErr_eInternal;
   }
 
   return zError;
}
void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc)
{
   RCC_OscInitTypeDef        RCC_OscInitStruct;
   RCC_PeriphCLKInitTypeDef  PeriphClkInitStruct;
 
   /*##-1- Enables access to the backup domain ######*/
   /* To enable access on RTC registers */
   HAL_PWR_EnableBkUpAccess();
 
   /*##-2- Configure LSE/LSI as RTC clock source ###############################*/
#ifdef RTC_CLOCK_SOURCE_LSE
   RCC_OscInitStruct.OscillatorType =  RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
   RCC_OscInitStruct.LSEState = RCC_LSE_ON;
   RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
   if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
   {
      while(1){};
   }
 
   PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
   PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
   if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
   {
      while(1){};
   }
   /* Configures the External Low Speed oscillator (LSE) drive capability */
   __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH);
#elif defined (RTC_CLOCK_SOURCE_LSI)
   RCC_OscInitStruct.OscillatorType =  RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
   RCC_OscInitStruct.LSIState = RCC_LSI_ON;
   RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
   if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
   {
      while(1){};
   }
 
   PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
   PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
   if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
   {
      while(1){};
   }
#else
#error Please select the RTC Clock source inside the main.h file
#endif /*RTC_CLOCK_SOURCE_LSE*/
 
   /*##-3- Enable RTC peripheral Clocks #######################################*/
   /* Enable RTC Clock */
   __HAL_RCC_RTC_ENABLE();
 
   /*##-4- Configure the NVIC for RTC Alarm ###################################*/
//   HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 0x0F, 0);
//   HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
 
   UNUSED(hrtc);
}

I’m experiencing some problems:

1) the clock is always slower (about 10%), no matter of the capacitor installed (even without the capacitors)

2) there is a jitter on the oscillator signal even if the RTC is powered by the Vbat and the uC is not powered

Thanks in advance for any suggestion.

Regards

1 REPLY 1

> the clock is always slower

How do you know?

> there is a jitter on the oscillator signal

How do you know?

Read out and check the respective RCC registers whether RTC is properly set to LSE.

JW