Calibration can be done by just a call to HAL_RTCEx_SetSmoothCalib, which is part of stm32f4xx_hal_rtc_ex.c or by setting the required parameter manually. You have certainly read the above-mentioned section 26.3.11 carefully so that you will immediately understand how the following, very simple function works, which incidentally is independent of the target and does not yet contain a check for the range of parameters. Simply call it anywhere in your user program to set the correction value to -511 ... +512 steps:
/**
* @brief Sets the new correction values for smooth calibration into RTC_CALR, fixed for calibration period of 32s
* @param calibration value -511...+512 for calculating CALP, CALM[8..0]
* @retval none
*/
void wr_LSEcalibration(int16_t LSEcalibrationvalue)
{
if (LSEcalibrationvalue > 0)
{
if (HAL_RTCEx_SetSmoothCalib(&hrtc, RTC_SMOOTHCALIB_PERIOD_32SEC, RTC_SMOOTHCALIB_PLUSPULSES_SET, (uint32_t)(512-LSEcalibrationvalue)) != HAL_OK)
{
Error_Handler();
}
}
else
{
if (HAL_RTCEx_SetSmoothCalib(&hrtc, RTC_SMOOTHCALIB_PERIOD_32SEC, RTC_SMOOTHCALIB_PLUSPULSES_RESET, (uint32_t)abs(LSEcalibrationvalue)) != HAL_OK)
{
Error_Handler();
}
}
}
Regards
/Peter
In order 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.