RTC on STM32H745
Hi,
We are using a STM32H745 in our project. Over the past few days, I've been wasting a lot of time figuring out why RTC has a major error ... it always runs slower than it should. To be sure we tried to used the crystal and the capacities present in the ST demo board (STM32H747 disco) bu the problem still remain.
In the event of a power failure, the RTC remains powered through a supercap.
The waveform on the crystal pin seems to be there, a sine wave of 500mVpp @ 36.768KHz .... below is the code used for initialization:
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 ###############################*/
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);
}Any idea to fix this issue?
Thanks in advance,
DM
