cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with STMH7 RTC using 32768Hz LSE clock gains time

Rhodes.Keith
Associate II

We have our own STM32H743II board with a 32768Hz LSE crystal and proper caps as specified in app note AN2867. We have configured PC13 to output a 1Hz signal. We then used that to gate a frequency counter that is reading a precision calibrated 10MHz signal.

When we power up the board from a full RTC backup reset, the number of pulses recorded is 3528 more than 10MHz, which is reasonable. An hour later, it is up to about 4000 more pulses record from the same source. On average, it increases a pulse or two every 2-3 seconds.

If we fully reset the board and RTC backup by shorting the super cap, it goes back to 3528 pulses over.

This seems to be a problem inside the RTC, where it is continually adding an increasing offset to the input clock frequency calculation.

I have set the default prescalers, no shift register, no smooth calibration and not using the RTC_REFIN input signal.

This seems to make the RTC unusable for time keeping operations.

Thoughts? Thanks...Keith Rhodes

Here is our initialization code:

	RTC_HandleTypeDef g_RtcHandle;
	RCC_OscInitTypeDef        RCC_OscInitStruct;
	RCC_PeriphCLKInitTypeDef  PeriphClkInitStruct;
	GPIO_InitTypeDef   GPIO_InitStructure;
 
	// Initialize LSE clock in and clock out pins even though the datasheet
	//  says they are initialized this way at startup
	GPIO_InitStructure.Pin = LSE_OSCILLATOR_OUT_PIN;
	GPIO_InitStructure.Alternate = GPIO_AF15_EVENTOUT;
	GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
	GPIO_InitStructure.Pull = GPIO_NOPULL;
	GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
	HAL_GPIO_Init(LSE_OSCILLATOR_PORT, &GPIO_InitStructure);
 
	GPIO_InitStructure.Pin = LSE_OSCILLATOR_IN_PIN;
	GPIO_InitStructure.Alternate = GPIO_AF15_EVENTOUT;
	HAL_GPIO_Init(LSE_OSCILLATOR_PORT, &GPIO_InitStructure);
 
	HAL_PWR_EnableBkUpAccess();
 
	/*##-1- Configure LSE as RTC clock source ###################################*/
	RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
	RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
	RCC_OscInitStruct.LSEState = RCC_LSE_ON;
	if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
	{
		return(false);
	}
 
 
	PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
	PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
	if(HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
	{
		return(false);
	}
 
	/*##-2- Enable RTC peripheral Clocks #######################################*/
	/* Enable RTC Clock */
	__HAL_RCC_RTC_ENABLE();
 
	g_RtcHandle.Instance = RTC;
 
#define RTC_ASYNCH_PREDIV		(128 - 1)
#define RTC_SYNCH_PREDIV		(256 - 1)
 
	  __HAL_RTC_RESET_HANDLE_STATE(&g_RtcHandle);
 
	/*##-1- Configure the RTC peripheral #######################################*/
 
	/* Configure RTC prescaler and RTC data registers */
	/* RTC configured as follow:
	- 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 */
	g_RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
	g_RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
	g_RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
	g_RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
	g_RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
	g_RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
	g_RtcHandle.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
 
	if(HAL_RTC_Init(&g_RtcHandle) != HAL_OK)
	{
		return(false);
	}
 
	/* Clear Reset Flag */
	__HAL_RCC_CLEAR_RESET_FLAGS();
 
       // ensure the SHIFTR register is set to 0
	HAL_RTCEx_SetSynchroShift(&g_RtcHandle, RTC_SHIFTADD1S_RESET, 0);
 
	 // Turn on shadow registers to speed up RTC operations
	 HAL_RTCEx_EnableBypassShadow(&g_RtcHandle);
 
 	 // Turn on calibration output on PC13
	 HAL_RTCEx_SetCalibrationOutPut(&g_RtcHandle, RTC_CALIBOUTPUT_1HZ);
 
 

1 REPLY 1
Rhodes.Keith
Associate II

One more thing, if I just reset or cycle power the H743 and keep the RTC powered from the super cal, the offset value stays about where it was before the reset, which further implicates the RTC doing something unwanted.