|
发表于 2021-5-1 08:24:55
|
显示全部楼层
看了下这个函数,只有简单的寄存器设置,这个有必要研究下手册了
- /**
- * @brief Set the Smooth calibration parameters.
- * @param hrtc RTC handle
- * @param SmoothCalibPeriod Select the Smooth Calibration Period.
- * This parameter can be can be one of the following values :
- * @arg RTC_SMOOTHCALIB_PERIOD_32SEC: The smooth calibration period is 32s.
- * @arg RTC_SMOOTHCALIB_PERIOD_16SEC: The smooth calibration period is 16s.
- * @arg RTC_SMOOTHCALIB_PERIOD_8SEC: The smooth calibration period is 8s.
- * @param SmoothCalibPlusPulses Select to Set or reset the CALP bit.
- * This parameter can be one of the following values:
- * @arg RTC_SMOOTHCALIB_PLUSPULSES_SET: Add one RTCCLK pulse every 2*11 pulses.
- * @arg RTC_SMOOTHCALIB_PLUSPULSES_RESET: No RTCCLK pulses are added.
- * @param SmoothCalibMinusPulsesValue Select the value of CALM[8:0] bits.
- * This parameter can be one any value from 0 to 0x000001FF.
- * @note To deactivate the smooth calibration, the field SmoothCalibPlusPulses
- * must be equal to SMOOTHCALIB_PLUSPULSES_RESET and the field
- * SmoothCalibMinusPulsesValue must be equal to 0.
- * @retval HAL status
- */
- HAL_StatusTypeDef HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef * hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmoothCalibMinusPulsesValue)
- {
- uint32_t tickstart;
- /* Check the parameters */
- assert_param(IS_RTC_SMOOTH_CALIB_PERIOD(SmoothCalibPeriod));
- assert_param(IS_RTC_SMOOTH_CALIB_PLUS(SmoothCalibPlusPulses));
- assert_param(IS_RTC_SMOOTH_CALIB_MINUS(SmoothCalibMinusPulsesValue));
- /* Process Locked */
- __HAL_LOCK(hrtc);
- hrtc->State = HAL_RTC_STATE_BUSY;
- /* Disable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
- /* check if a calibration operation is pending */
- #if defined(RTC_ICSR_RECALPF)
- if ((hrtc->Instance->ICSR & RTC_ICSR_RECALPF) != 0U)
- #endif /* RTC_ICSR_RECALPF */
- #if defined(RTC_ISR_RECALPF)
- if ((hrtc->Instance->ISR & RTC_ISR_RECALPF) != 0U)
- #endif /* RTC_ISR_RECALPF */
- {
- tickstart = HAL_GetTick();
- /* Wait for pending calibration operation to finish */
- #if defined(RTC_ICSR_RECALPF)
- while ((hrtc->Instance->ICSR & RTC_ICSR_RECALPF) != 0U)
- #endif /* RTC_ICSR_RECALPF */
- #if defined(RTC_ISR_RECALPF)
- while ((hrtc->Instance->ISR & RTC_ISR_RECALPF) != 0U)
- #endif /* RTC_ISR_RECALPF */
- {
- if ((HAL_GetTick() - tickstart) > RTC_TIMEOUT_VALUE)
- {
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_TIMEOUT;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_TIMEOUT;
- }
- }
- }
- /* Configure the Smooth calibration settings */
- MODIFY_REG(hrtc->Instance->CALR, (RTC_CALR_CALP | RTC_CALR_CALW8 | RTC_CALR_CALW16 | RTC_CALR_CALM), (uint32_t)(SmoothCalibPeriod | SmoothCalibPlusPulses | SmoothCalibMinusPulsesValue));
- /* Enable the write protection for RTC registers */
- __HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
- /* Change RTC state */
- hrtc->State = HAL_RTC_STATE_READY;
- /* Process Unlocked */
- __HAL_UNLOCK(hrtc);
- return HAL_OK;
- }
复制代码
|
|