Extended Clock Recovery System Control functions.
More...
Extended Clock Recovery System Control functions.
===============================================================================
##### Extended Clock Recovery System Control functions #####
===============================================================================
[..]
For devices with Clock Recovery System feature (CRS), RCC Extention HAL driver can be used as follows:
(#) In System clock config, HSI48 needs to be enabled
(#) Enable CRS clock in IP MSP init which will use CRS functions
(#) Call CRS functions as follows:
(##) Prepare synchronization configuration necessary for HSI48 calibration
(+++) Default values can be set for frequency Error Measurement (reload and error limit)
and also HSI48 oscillator smooth trimming.
(+++) Macro __HAL_RCC_CRS_RELOADVALUE_CALCULATE can be also used to calculate
directly reload value with target and sychronization frequencies values
(##) Call function HAL_RCCEx_CRSConfig which
(+++) Resets CRS registers to their default values.
(+++) Configures CRS registers with synchronization configuration
(+++) Enables automatic calibration and frequency error counter feature
Note: When using USB LPM (Link Power Management) and the device is in Sleep mode, the
periodic USB SOF will not be generated by the host. No SYNC signal will therefore be
provided to the CRS to calibrate the HSI48 on the run. To guarantee the required clock
precision after waking up from Sleep mode, the LSE or reference clock on the GPIOs
should be used as SYNC signal.
(##) A polling function is provided to wait for complete synchronization
(+++) Call function HAL_RCCEx_CRSWaitSynchronization()
(+++) According to CRS status, user can decide to adjust again the calibration or continue
application if synchronization is OK
(#) User can retrieve information related to synchronization in calling function
HAL_RCCEx_CRSGetSynchronizationInfo()
(#) Regarding synchronization status and synchronization information, user can try a new calibration
in changing synchronization configuration and call again HAL_RCCEx_CRSConfig.
Note: When the SYNC event is detected during the downcounting phase (before reaching the zero value),
it means that the actual frequency is lower than the target (and so, that the TRIM value should be
incremented), while when it is detected during the upcounting phase it means that the actual frequency
is higher (and that the TRIM value should be decremented).
(#) In interrupt mode, user can resort to the available macros (__HAL_RCC_CRS_XXX_IT). Interrupts will go
through CRS Handler (CRS_IRQn/CRS_IRQHandler)
(++) Call function HAL_RCCEx_CRSConfig()
(++) Enable CRS_IRQn (thanks to NVIC functions)
(++) Enable CRS interrupt (__HAL_RCC_CRS_ENABLE_IT)
(++) Implement CRS status management in the following user callbacks called from
HAL_RCCEx_CRS_IRQHandler():
(+++) HAL_RCCEx_CRS_SyncOkCallback()
(+++) HAL_RCCEx_CRS_SyncWarnCallback()
(+++) HAL_RCCEx_CRS_ExpectedSyncCallback()
(+++) HAL_RCCEx_CRS_ErrorCallback()
(#) To force a SYNC EVENT, user can use the function HAL_RCCEx_CRSSoftwareSynchronizationGenerate().
This function can be called before calling HAL_RCCEx_CRSConfig (for instance in Systick handler)
◆ HAL_RCCEx_CRS_ErrorCallback()
| __weak void HAL_RCCEx_CRS_ErrorCallback |
( |
uint32_t |
Error | ) |
|
RCCEx Clock Recovery System Error interrupt callback.
- Parameters
-
| Error | Combination of Error status. This parameter can be a combination of the following values:
- RCC_CRS_SYNCERR
- RCC_CRS_SYNCMISS
- RCC_CRS_TRIMOVF
|
- Return values
-
Definition at line 2852 of file stm32l4xx_hal_rcc_ex.c.
◆ HAL_RCCEx_CRS_ExpectedSyncCallback()
| __weak void HAL_RCCEx_CRS_ExpectedSyncCallback |
( |
void |
| ) |
|
RCCEx Clock Recovery System Expected SYNC interrupt callback.
- Return values
-
Definition at line 2836 of file stm32l4xx_hal_rcc_ex.c.
◆ HAL_RCCEx_CRS_IRQHandler()
| void HAL_RCCEx_CRS_IRQHandler |
( |
void |
| ) |
|
Handle the Clock Recovery System interrupt request.
- Return values
-
Definition at line 2749 of file stm32l4xx_hal_rcc_ex.c.
2751 uint32_t crserror = RCC_CRS_NONE;
2753 uint32_t itflags = READ_REG(CRS->ISR);
2754 uint32_t itsources = READ_REG(CRS->CR);
2757 if(((itflags & RCC_CRS_FLAG_SYNCOK) != 0U) && ((itsources & RCC_CRS_IT_SYNCOK) != 0U))
2760 WRITE_REG(CRS->ICR, CRS_ICR_SYNCOKC);
2766 else if(((itflags & RCC_CRS_FLAG_SYNCWARN) != 0U) && ((itsources & RCC_CRS_IT_SYNCWARN) != 0U))
2769 WRITE_REG(CRS->ICR, CRS_ICR_SYNCWARNC);
2775 else if(((itflags & RCC_CRS_FLAG_ESYNC) != 0U) && ((itsources & RCC_CRS_IT_ESYNC) != 0U))
2778 WRITE_REG(CRS->ICR, CRS_ICR_ESYNCC);
2786 if(((itflags & RCC_CRS_FLAG_ERR) != 0U) && ((itsources & RCC_CRS_IT_ERR) != 0U))
2788 if((itflags & RCC_CRS_FLAG_SYNCERR) != 0U)
2790 crserror |= RCC_CRS_SYNCERR;
2792 if((itflags & RCC_CRS_FLAG_SYNCMISS) != 0U)
2794 crserror |= RCC_CRS_SYNCMISS;
2796 if((itflags & RCC_CRS_FLAG_TRIMOVF) != 0U)
2798 crserror |= RCC_CRS_TRIMOVF;
2802 WRITE_REG(CRS->ICR, CRS_ICR_ERRC);
void HAL_RCCEx_CRS_ExpectedSyncCallback(void)
RCCEx Clock Recovery System Expected SYNC interrupt callback.
void HAL_RCCEx_CRS_SyncOkCallback(void)
RCCEx Clock Recovery System SYNCOK interrupt callback.
void HAL_RCCEx_CRS_ErrorCallback(uint32_t Error)
RCCEx Clock Recovery System Error interrupt callback.
void HAL_RCCEx_CRS_SyncWarnCallback(void)
RCCEx Clock Recovery System SYNCWARN interrupt callback.
◆ HAL_RCCEx_CRS_SyncOkCallback()
| __weak void HAL_RCCEx_CRS_SyncOkCallback |
( |
void |
| ) |
|
◆ HAL_RCCEx_CRS_SyncWarnCallback()
| __weak void HAL_RCCEx_CRS_SyncWarnCallback |
( |
void |
| ) |
|
◆ HAL_RCCEx_CRSConfig()
Start automatic synchronization for polling mode.
- Parameters
-
- Return values
-
Definition at line 2580 of file stm32l4xx_hal_rcc_ex.c.
2595 __HAL_RCC_CRS_FORCE_RESET();
2596 __HAL_RCC_CRS_RELEASE_RESET();
2606 WRITE_REG(CRS->CFGR, value);
2616 SET_BIT(CRS->CR, CRS_CR_AUTOTRIMEN | CRS_CR_CEN);
uint32_t HSI48CalibrationValue
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
◆ HAL_RCCEx_CRSGetSynchronizationInfo()
Return synchronization info.
- Parameters
-
- Return values
-
Definition at line 2633 of file stm32l4xx_hal_rcc_ex.c.
2639 pSynchroInfo->
ReloadValue = (READ_BIT(CRS->CFGR, CRS_CFGR_RELOAD));
2645 pSynchroInfo->
FreqErrorCapture = (READ_BIT(CRS->ISR, CRS_ISR_FECAP) >> CRS_ISR_FECAP_Pos);
uint32_t FreqErrorCapture
uint32_t HSI48CalibrationValue
uint32_t FreqErrorDirection
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
◆ HAL_RCCEx_CRSSoftwareSynchronizationGenerate()
| void HAL_RCCEx_CRSSoftwareSynchronizationGenerate |
( |
void |
| ) |
|
Generate the software synchronization event.
- Return values
-
Definition at line 2623 of file stm32l4xx_hal_rcc_ex.c.
2625 SET_BIT(CRS->CR, CRS_CR_SWSYNC);
◆ HAL_RCCEx_CRSWaitSynchronization()
| uint32_t HAL_RCCEx_CRSWaitSynchronization |
( |
uint32_t |
Timeout | ) |
|
Wait for CRS Synchronization status.
- Parameters
-
| Timeout | Duration of the timeout |
- Note
- Timeout is based on the maximum time to receive a SYNC event based on synchronization frequency.
-
If Timeout set to HAL_MAX_DELAY, HAL_TIMEOUT will be never returned.
- Return values
-
| Combination | of Synchronization status This parameter can be a combination of the following values:
- RCC_CRS_TIMEOUT
- RCC_CRS_SYNCOK
- RCC_CRS_SYNCWARN
- RCC_CRS_SYNCERR
- RCC_CRS_SYNCMISS
- RCC_CRS_TRIMOVF
|
Definition at line 2666 of file stm32l4xx_hal_rcc_ex.c.
2668 uint32_t crsstatus = RCC_CRS_NONE;
2677 if(Timeout != HAL_MAX_DELAY)
2679 if(((
HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
2681 crsstatus = RCC_CRS_TIMEOUT;
2685 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCOK))
2688 crsstatus |= RCC_CRS_SYNCOK;
2691 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCOK);
2695 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCWARN))
2698 crsstatus |= RCC_CRS_SYNCWARN;
2701 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCWARN);
2705 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_TRIMOVF))
2708 crsstatus |= RCC_CRS_TRIMOVF;
2711 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_TRIMOVF);
2715 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCERR))
2718 crsstatus |= RCC_CRS_SYNCERR;
2721 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCERR);
2725 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_SYNCMISS))
2728 crsstatus |= RCC_CRS_SYNCMISS;
2731 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_SYNCMISS);
2735 if(__HAL_RCC_CRS_GET_FLAG(RCC_CRS_FLAG_ESYNC))
2738 __HAL_RCC_CRS_CLEAR_FLAG(RCC_CRS_FLAG_ESYNC);
2740 }
while(RCC_CRS_NONE == crsstatus);
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.