Skip to main content
Associate III
February 6, 2026
Question

STM32F411 RTC 32768 cal Freq only 490Hz

  • February 6, 2026
  • 4 replies
  • 432 views

Post Edited by ST moderator to apply source code formatting to comply with the community rule:


I wonder if any one can help me.

The rtc Cal freq produced by the init code below produces on 490Hz.  The RTC clock is loosing about 55 sec in 20 minutes.

Is there a way to increase this freq without replacing the crystal?

 

 
static void MX_RTC_Init(void)

{

/* USER CODE BEGIN RTC_Init 0 */

/* USER CODE END RTC_Init 0 */



RTC_TimeTypeDef sTime = {0};

RTC_DateTypeDef sDate = {0};

/* USER CODE BEGIN RTC_Init 1 */

/* USER CODE END RTC_Init 1 */

/** Initialize RTC Only */

hrtc.Instance = RTC;

hrtc.Init.HourFormat = RTC_HOURFORMAT_24;

hrtc.Init.AsynchPrediv = 127;

hrtc.Init.SynchPrediv = 255;

hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;

hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

if (HAL_RTC_Init(&hrtc) != HAL_OK)

{

Error_Handler();

}



/* USER CODE BEGIN Check_RTC_BKUP */



/* USER CODE END Check_RTC_BKUP */



/** Initialize RTC and set the Time and Date

*/

sTime.Hours = 18;

sTime.Minutes = 4;

sTime.Seconds = 11;

sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

sTime.StoreOperation = RTC_STOREOPERATION_RESET;

if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)

{

Error_Handler();

}

sDate.WeekDay = RTC_WEEKDAY_SATURDAY;

sDate.Month = RTC_MONTH_JANUARY;

sDate.Date = 24;

sDate.Year = 26;



if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)

{

Error_Handler();

}



/** Enable Calibrartion

*/

if (HAL_RTCEx_SetCalibrationOutPut(&hrtc, RTC_CALIBOUTPUT_512HZ) != HAL_OK)

{

Error_Handler();

}

/* USER CODE BEGIN RTC_Init 2 */



/* USER CODE END RTC_Init 2 */



}

 

 

Thank you

4 replies

mƎALLEm
Technical Moderator
February 6, 2026

Hello,

1- Please use </> button to share your code. Read How to write your question to maximize your chances to find a solution. I invite you to edit your post to be inline to this community rule.

2- This knowledge base article may help you: How to calibrate the STM32's real-time clock (RTC)

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
TDK
Super User
February 6, 2026

> Is there a way to increase this freq without replacing the crystal?

No, 55s in 20min is 5% off. That's 50000 ppm. That is way more than you can correct for in software. You'll have to fix whatever is wrong with the circuit.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Peter BENSCH
Technical Moderator
February 6, 2026

@erastusC 

You didn't specify which clock you are using to test the RTC. As @TDK said, your deviation is so large that it can't possibly have anything to do with a (real) 32768Hz crystal.

Let's do the math: if you multiply your 490Hz by the corresponding divisor of 64, you get 31360Hz. Then you look at the documentation of the STM32F411 (data sheet) and see that the free-running LSI has a frequency of min 17kHz, typ 32kHz and max 47kHz – do you notice anything?

Exactly – you clocked the RTC from the LSI and not from the LSE.

Regards
/Peter

erastusCAuthor
Associate III
February 7, 2026

Hi Peter,

Thanks for the info. What I understand is this configuration selects the Crystal for the RTC.

Am I doing something wrong?

The line of code according to the documentation should either increase or decease the clock.  The Freq on the Oscilloscope remains 490Hz no matter what I do to the 0x1F0 value.

/ HAL_RTCEx_SetSmoothCalib(&hrtc, RTC_SMOOTHCALIB_PERIOD_8SEC,

/  RTC_SMOOTHCALIB_PLUSPULSES_RESET, 0x1F0);

 

erastusC_1-1770460832630.png

 

 

 

 

 

 

 

+

waclawek.jan
Super User
February 7, 2026

... or the LSE circuit is badly disturbed by the calib-out signal.

waclawekjan_0-1770456900579.png

JW

PS. [rant mode on] Couldn't errata be proof-read? Those references to packages are a mess.

erastusCAuthor
Associate III
February 7, 2026

Thank you for your response.   DO you suggest Once I do the calibration I disable PC13 pin as it might affect the crystal osc?

EThom.3
Senior II
February 12, 2026

The way I read the errata sheet, you can't even use PC13 for calibration, as (ironically) the signal you use in the calibration process may disturb the very clock you want to calibrate.