STM32L443xx HAL User Manual
stm32l4xx_ll_crs.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_ll_crs.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of CRS LL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * Copyright (c) 2017 STMicroelectronics.
00010   * All rights reserved.
00011   *
00012   * This software is licensed under terms that can be found in the LICENSE file
00013   * in the root directory of this software component.
00014   * If no LICENSE file comes with this software, it is provided AS-IS.
00015   *
00016   ******************************************************************************
00017   */
00018 
00019 /* Define to prevent recursive inclusion -------------------------------------*/
00020 #ifndef STM32L4xx_LL_CRS_H
00021 #define STM32L4xx_LL_CRS_H
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00027 /* Includes ------------------------------------------------------------------*/
00028 #include "stm32l4xx.h"
00029 
00030 /** @addtogroup STM32L4xx_LL_Driver
00031   * @{
00032   */
00033 
00034 #if defined(CRS)
00035 
00036 /** @defgroup CRS_LL CRS
00037   * @{
00038   */
00039 
00040 /* Private types -------------------------------------------------------------*/
00041 /* Private variables ---------------------------------------------------------*/
00042 /* Private constants ---------------------------------------------------------*/
00043 /* Private macros ------------------------------------------------------------*/
00044 
00045 /* Exported types ------------------------------------------------------------*/
00046 /* Exported constants --------------------------------------------------------*/
00047 /** @defgroup CRS_LL_Exported_Constants CRS Exported Constants
00048   * @{
00049   */
00050 
00051 /** @defgroup CRS_LL_EC_GET_FLAG Get Flags Defines
00052   * @brief    Flags defines which can be used with LL_CRS_ReadReg function
00053   * @{
00054   */
00055 #define LL_CRS_ISR_SYNCOKF                 CRS_ISR_SYNCOKF
00056 #define LL_CRS_ISR_SYNCWARNF               CRS_ISR_SYNCWARNF
00057 #define LL_CRS_ISR_ERRF                    CRS_ISR_ERRF
00058 #define LL_CRS_ISR_ESYNCF                  CRS_ISR_ESYNCF
00059 #define LL_CRS_ISR_SYNCERR                 CRS_ISR_SYNCERR
00060 #define LL_CRS_ISR_SYNCMISS                CRS_ISR_SYNCMISS
00061 #define LL_CRS_ISR_TRIMOVF                 CRS_ISR_TRIMOVF
00062 /**
00063   * @}
00064   */
00065 
00066 /** @defgroup CRS_LL_EC_IT IT Defines
00067   * @brief    IT defines which can be used with LL_CRS_ReadReg and  LL_CRS_WriteReg functions
00068   * @{
00069   */
00070 #define LL_CRS_CR_SYNCOKIE                 CRS_CR_SYNCOKIE
00071 #define LL_CRS_CR_SYNCWARNIE               CRS_CR_SYNCWARNIE
00072 #define LL_CRS_CR_ERRIE                    CRS_CR_ERRIE
00073 #define LL_CRS_CR_ESYNCIE                  CRS_CR_ESYNCIE
00074 /**
00075   * @}
00076   */
00077 
00078 /** @defgroup CRS_LL_EC_SYNC_DIV Synchronization Signal Divider
00079   * @{
00080   */
00081 #define LL_CRS_SYNC_DIV_1                  ((uint32_t)0x00U)                         /*!< Synchro Signal not divided (default) */
00082 #define LL_CRS_SYNC_DIV_2                  CRS_CFGR_SYNCDIV_0                        /*!< Synchro Signal divided by 2 */
00083 #define LL_CRS_SYNC_DIV_4                  CRS_CFGR_SYNCDIV_1                        /*!< Synchro Signal divided by 4 */
00084 #define LL_CRS_SYNC_DIV_8                  (CRS_CFGR_SYNCDIV_1 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 8 */
00085 #define LL_CRS_SYNC_DIV_16                 CRS_CFGR_SYNCDIV_2                        /*!< Synchro Signal divided by 16 */
00086 #define LL_CRS_SYNC_DIV_32                 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 32 */
00087 #define LL_CRS_SYNC_DIV_64                 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_1) /*!< Synchro Signal divided by 64 */
00088 #define LL_CRS_SYNC_DIV_128                CRS_CFGR_SYNCDIV                          /*!< Synchro Signal divided by 128 */
00089 /**
00090   * @}
00091   */
00092 
00093 /** @defgroup CRS_LL_EC_SYNC_SOURCE Synchronization Signal Source
00094   * @{
00095   */
00096 #define LL_CRS_SYNC_SOURCE_GPIO            ((uint32_t)0x00U)       /*!< Synchro Signal soucre GPIO */
00097 #define LL_CRS_SYNC_SOURCE_LSE             CRS_CFGR_SYNCSRC_0      /*!< Synchro Signal source LSE */
00098 #define LL_CRS_SYNC_SOURCE_USB             CRS_CFGR_SYNCSRC_1      /*!< Synchro Signal source USB SOF (default)*/
00099 /**
00100   * @}
00101   */
00102 
00103 /** @defgroup CRS_LL_EC_SYNC_POLARITY Synchronization Signal Polarity
00104   * @{
00105   */
00106 #define LL_CRS_SYNC_POLARITY_RISING        ((uint32_t)0x00U)     /*!< Synchro Active on rising edge (default) */
00107 #define LL_CRS_SYNC_POLARITY_FALLING       CRS_CFGR_SYNCPOL      /*!< Synchro Active on falling edge */
00108 /**
00109   * @}
00110   */
00111 
00112 /** @defgroup CRS_LL_EC_FREQERRORDIR Frequency Error Direction
00113   * @{
00114   */
00115 #define LL_CRS_FREQ_ERROR_DIR_UP             ((uint32_t)0x00U)         /*!< Upcounting direction, the actual frequency is above the target */
00116 #define LL_CRS_FREQ_ERROR_DIR_DOWN           ((uint32_t)CRS_ISR_FEDIR) /*!< Downcounting direction, the actual frequency is below the target */
00117 /**
00118   * @}
00119   */
00120 
00121 /** @defgroup CRS_LL_EC_DEFAULTVALUES Default Values
00122   * @{
00123   */
00124 /**
00125   * @brief Reset value of the RELOAD field
00126   * @note The reset value of the RELOAD field corresponds to a target frequency of 48 MHz
00127   *       and a synchronization signal frequency of 1 kHz (SOF signal from USB)
00128   */
00129 #define LL_CRS_RELOADVALUE_DEFAULT         ((uint32_t)0xBB7FU)
00130 
00131 /**
00132   * @brief Reset value of Frequency error limit.
00133   */
00134 #define LL_CRS_ERRORLIMIT_DEFAULT          ((uint32_t)0x22U)
00135 
00136 /**
00137   * @brief Reset value of the HSI48 Calibration field
00138   * @note The default value is 64 for STM32L412xx/L422xx, 32 otherwise, which corresponds
00139   *       to the middle of the trimming interval.
00140   *       The trimming step is around 67 kHz between two consecutive TRIM steps.
00141   *       A higher TRIM value corresponds to a higher output frequency
00142   */
00143 #if defined (STM32L412xx) || defined (STM32L422xx)
00144 #define LL_CRS_HSI48CALIBRATION_DEFAULT    ((uint32_t)64U)
00145 #else
00146 #define LL_CRS_HSI48CALIBRATION_DEFAULT    ((uint32_t)32U)
00147 #endif
00148 /**
00149   * @}
00150   */
00151 
00152 /**
00153   * @}
00154   */
00155 
00156 /* Exported macro ------------------------------------------------------------*/
00157 /** @defgroup CRS_LL_Exported_Macros CRS Exported Macros
00158   * @{
00159   */
00160 
00161 /** @defgroup CRS_LL_EM_WRITE_READ Common Write and read registers Macros
00162   * @{
00163   */
00164 
00165 /**
00166   * @brief  Write a value in CRS register
00167   * @param  __INSTANCE__ CRS Instance
00168   * @param  __REG__ Register to be written
00169   * @param  __VALUE__ Value to be written in the register
00170   * @retval None
00171   */
00172 #define LL_CRS_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
00173 
00174 /**
00175   * @brief  Read a value in CRS register
00176   * @param  __INSTANCE__ CRS Instance
00177   * @param  __REG__ Register to be read
00178   * @retval Register value
00179   */
00180 #define LL_CRS_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
00181 /**
00182   * @}
00183   */
00184 
00185 /** @defgroup CRS_LL_EM_Exported_Macros_Calculate_Reload Exported_Macros_Calculate_Reload
00186   * @{
00187   */
00188 
00189 /**
00190   * @brief  Macro to calculate reload value to be set in CRS register according to target and sync frequencies
00191   * @note   The RELOAD value should be selected according to the ratio between
00192   *         the target frequency and the frequency of the synchronization source after
00193   *         prescaling. It is then decreased by one in order to reach the expected
00194   *         synchronization on the zero value. The formula is the following:
00195   *              RELOAD = (fTARGET / fSYNC) -1
00196   * @param  __FTARGET__ Target frequency (value in Hz)
00197   * @param  __FSYNC__ Synchronization signal frequency (value in Hz)
00198   * @retval Reload value (in Hz)
00199   */
00200 #define __LL_CRS_CALC_CALCULATE_RELOADVALUE(__FTARGET__, __FSYNC__) (((__FTARGET__) / (__FSYNC__)) - 1U)
00201 
00202 /**
00203   * @}
00204   */
00205 
00206 /**
00207   * @}
00208   */
00209 
00210 /* Exported functions --------------------------------------------------------*/
00211 /** @defgroup CRS_LL_Exported_Functions CRS Exported Functions
00212   * @{
00213   */
00214 
00215 /** @defgroup CRS_LL_EF_Configuration Configuration
00216   * @{
00217   */
00218 
00219 /**
00220   * @brief  Enable Frequency error counter
00221   * @note When this bit is set, the CRS_CFGR register is write-protected and cannot be modified
00222   * @rmtoll CR           CEN           LL_CRS_EnableFreqErrorCounter
00223   * @retval None
00224   */
00225 __STATIC_INLINE void LL_CRS_EnableFreqErrorCounter(void)
00226 {
00227   SET_BIT(CRS->CR, CRS_CR_CEN);
00228 }
00229 
00230 /**
00231   * @brief  Disable Frequency error counter
00232   * @rmtoll CR           CEN           LL_CRS_DisableFreqErrorCounter
00233   * @retval None
00234   */
00235 __STATIC_INLINE void LL_CRS_DisableFreqErrorCounter(void)
00236 {
00237   CLEAR_BIT(CRS->CR, CRS_CR_CEN);
00238 }
00239 
00240 /**
00241   * @brief  Check if Frequency error counter is enabled or not
00242   * @rmtoll CR           CEN           LL_CRS_IsEnabledFreqErrorCounter
00243   * @retval State of bit (1 or 0).
00244   */
00245 __STATIC_INLINE uint32_t LL_CRS_IsEnabledFreqErrorCounter(void)
00246 {
00247   return (READ_BIT(CRS->CR, CRS_CR_CEN) == (CRS_CR_CEN));
00248 }
00249 
00250 /**
00251   * @brief  Enable Automatic trimming counter
00252   * @rmtoll CR           AUTOTRIMEN    LL_CRS_EnableAutoTrimming
00253   * @retval None
00254   */
00255 __STATIC_INLINE void LL_CRS_EnableAutoTrimming(void)
00256 {
00257   SET_BIT(CRS->CR, CRS_CR_AUTOTRIMEN);
00258 }
00259 
00260 /**
00261   * @brief  Disable Automatic trimming counter
00262   * @rmtoll CR           AUTOTRIMEN    LL_CRS_DisableAutoTrimming
00263   * @retval None
00264   */
00265 __STATIC_INLINE void LL_CRS_DisableAutoTrimming(void)
00266 {
00267   CLEAR_BIT(CRS->CR, CRS_CR_AUTOTRIMEN);
00268 }
00269 
00270 /**
00271   * @brief  Check if Automatic trimming is enabled or not
00272   * @rmtoll CR           AUTOTRIMEN    LL_CRS_IsEnabledAutoTrimming
00273   * @retval State of bit (1 or 0).
00274   */
00275 __STATIC_INLINE uint32_t LL_CRS_IsEnabledAutoTrimming(void)
00276 {
00277   return (READ_BIT(CRS->CR, CRS_CR_AUTOTRIMEN) == (CRS_CR_AUTOTRIMEN));
00278 }
00279 
00280 /**
00281   * @brief  Set HSI48 oscillator smooth trimming
00282   * @note   When the AUTOTRIMEN bit is set, this field is controlled by hardware and is read-only
00283   * @rmtoll CR           TRIM          LL_CRS_SetHSI48SmoothTrimming
00284   * @param  Value a number between Min_Data = 0 and Max_Data = 127 for STM32L412xx/L422xx or 63 otherwise
00285   * @note   Default value can be set thanks to @ref LL_CRS_HSI48CALIBRATION_DEFAULT
00286   * @retval None
00287   */
00288 __STATIC_INLINE void LL_CRS_SetHSI48SmoothTrimming(uint32_t Value)
00289 {
00290   MODIFY_REG(CRS->CR, CRS_CR_TRIM, Value << CRS_CR_TRIM_Pos);
00291 }
00292 
00293 /**
00294   * @brief  Get HSI48 oscillator smooth trimming
00295   * @rmtoll CR           TRIM          LL_CRS_GetHSI48SmoothTrimming
00296   * @retval a number between Min_Data = 0 and Max_Data = 127 for STM32L412xx/L422xx or 63 otherwise
00297   */
00298 __STATIC_INLINE uint32_t LL_CRS_GetHSI48SmoothTrimming(void)
00299 {
00300   return (uint32_t)(READ_BIT(CRS->CR, CRS_CR_TRIM) >> CRS_CR_TRIM_Pos);
00301 }
00302 
00303 /**
00304   * @brief  Set counter reload value
00305   * @rmtoll CFGR         RELOAD        LL_CRS_SetReloadCounter
00306   * @param  Value a number between Min_Data = 0 and Max_Data = 0xFFFF
00307   * @note   Default value can be set thanks to @ref LL_CRS_RELOADVALUE_DEFAULT
00308   *         Otherwise it can be calculated in using macro @ref __LL_CRS_CALC_CALCULATE_RELOADVALUE (_FTARGET_, _FSYNC_)
00309   * @retval None
00310   */
00311 __STATIC_INLINE void LL_CRS_SetReloadCounter(uint32_t Value)
00312 {
00313   MODIFY_REG(CRS->CFGR, CRS_CFGR_RELOAD, Value);
00314 }
00315 
00316 /**
00317   * @brief  Get counter reload value
00318   * @rmtoll CFGR         RELOAD        LL_CRS_GetReloadCounter
00319   * @retval a number between Min_Data = 0 and Max_Data = 0xFFFF
00320   */
00321 __STATIC_INLINE uint32_t LL_CRS_GetReloadCounter(void)
00322 {
00323   return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_RELOAD));
00324 }
00325 
00326 /**
00327   * @brief  Set frequency error limit
00328   * @rmtoll CFGR         FELIM         LL_CRS_SetFreqErrorLimit
00329   * @param  Value a number between Min_Data = 0 and Max_Data = 255
00330   * @note   Default value can be set thanks to @ref LL_CRS_ERRORLIMIT_DEFAULT
00331   * @retval None
00332   */
00333 __STATIC_INLINE void LL_CRS_SetFreqErrorLimit(uint32_t Value)
00334 {
00335   MODIFY_REG(CRS->CFGR, CRS_CFGR_FELIM, Value << CRS_CFGR_FELIM_Pos);
00336 }
00337 
00338 /**
00339   * @brief  Get frequency error limit
00340   * @rmtoll CFGR         FELIM         LL_CRS_GetFreqErrorLimit
00341   * @retval A number between Min_Data = 0 and Max_Data = 255
00342   */
00343 __STATIC_INLINE uint32_t LL_CRS_GetFreqErrorLimit(void)
00344 {
00345   return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_FELIM) >> CRS_CFGR_FELIM_Pos);
00346 }
00347 
00348 /**
00349   * @brief  Set division factor for SYNC signal
00350   * @rmtoll CFGR         SYNCDIV       LL_CRS_SetSyncDivider
00351   * @param  Divider This parameter can be one of the following values:
00352   *         @arg @ref LL_CRS_SYNC_DIV_1
00353   *         @arg @ref LL_CRS_SYNC_DIV_2
00354   *         @arg @ref LL_CRS_SYNC_DIV_4
00355   *         @arg @ref LL_CRS_SYNC_DIV_8
00356   *         @arg @ref LL_CRS_SYNC_DIV_16
00357   *         @arg @ref LL_CRS_SYNC_DIV_32
00358   *         @arg @ref LL_CRS_SYNC_DIV_64
00359   *         @arg @ref LL_CRS_SYNC_DIV_128
00360   * @retval None
00361   */
00362 __STATIC_INLINE void LL_CRS_SetSyncDivider(uint32_t Divider)
00363 {
00364   MODIFY_REG(CRS->CFGR, CRS_CFGR_SYNCDIV, Divider);
00365 }
00366 
00367 /**
00368   * @brief  Get division factor for SYNC signal
00369   * @rmtoll CFGR         SYNCDIV       LL_CRS_GetSyncDivider
00370   * @retval Returned value can be one of the following values:
00371   *         @arg @ref LL_CRS_SYNC_DIV_1
00372   *         @arg @ref LL_CRS_SYNC_DIV_2
00373   *         @arg @ref LL_CRS_SYNC_DIV_4
00374   *         @arg @ref LL_CRS_SYNC_DIV_8
00375   *         @arg @ref LL_CRS_SYNC_DIV_16
00376   *         @arg @ref LL_CRS_SYNC_DIV_32
00377   *         @arg @ref LL_CRS_SYNC_DIV_64
00378   *         @arg @ref LL_CRS_SYNC_DIV_128
00379   */
00380 __STATIC_INLINE uint32_t LL_CRS_GetSyncDivider(void)
00381 {
00382   return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_SYNCDIV));
00383 }
00384 
00385 /**
00386   * @brief  Set SYNC signal source
00387   * @rmtoll CFGR         SYNCSRC       LL_CRS_SetSyncSignalSource
00388   * @param  Source This parameter can be one of the following values:
00389   *         @arg @ref LL_CRS_SYNC_SOURCE_GPIO
00390   *         @arg @ref LL_CRS_SYNC_SOURCE_LSE
00391   *         @arg @ref LL_CRS_SYNC_SOURCE_USB
00392   * @retval None
00393   */
00394 __STATIC_INLINE void LL_CRS_SetSyncSignalSource(uint32_t Source)
00395 {
00396   MODIFY_REG(CRS->CFGR, CRS_CFGR_SYNCSRC, Source);
00397 }
00398 
00399 /**
00400   * @brief  Get SYNC signal source
00401   * @rmtoll CFGR         SYNCSRC       LL_CRS_GetSyncSignalSource
00402   * @retval Returned value can be one of the following values:
00403   *         @arg @ref LL_CRS_SYNC_SOURCE_GPIO
00404   *         @arg @ref LL_CRS_SYNC_SOURCE_LSE
00405   *         @arg @ref LL_CRS_SYNC_SOURCE_USB
00406   */
00407 __STATIC_INLINE uint32_t LL_CRS_GetSyncSignalSource(void)
00408 {
00409   return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_SYNCSRC));
00410 }
00411 
00412 /**
00413   * @brief  Set input polarity for the SYNC signal source
00414   * @rmtoll CFGR         SYNCPOL       LL_CRS_SetSyncPolarity
00415   * @param  Polarity This parameter can be one of the following values:
00416   *         @arg @ref LL_CRS_SYNC_POLARITY_RISING
00417   *         @arg @ref LL_CRS_SYNC_POLARITY_FALLING
00418   * @retval None
00419   */
00420 __STATIC_INLINE void LL_CRS_SetSyncPolarity(uint32_t Polarity)
00421 {
00422   MODIFY_REG(CRS->CFGR, CRS_CFGR_SYNCPOL, Polarity);
00423 }
00424 
00425 /**
00426   * @brief  Get input polarity for the SYNC signal source
00427   * @rmtoll CFGR         SYNCPOL       LL_CRS_GetSyncPolarity
00428   * @retval Returned value can be one of the following values:
00429   *         @arg @ref LL_CRS_SYNC_POLARITY_RISING
00430   *         @arg @ref LL_CRS_SYNC_POLARITY_FALLING
00431   */
00432 __STATIC_INLINE uint32_t LL_CRS_GetSyncPolarity(void)
00433 {
00434   return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_SYNCPOL));
00435 }
00436 
00437 /**
00438   * @brief  Configure CRS for the synchronization
00439   * @rmtoll CR           TRIM          LL_CRS_ConfigSynchronization\n
00440   *         CFGR         RELOAD        LL_CRS_ConfigSynchronization\n
00441   *         CFGR         FELIM         LL_CRS_ConfigSynchronization\n
00442   *         CFGR         SYNCDIV       LL_CRS_ConfigSynchronization\n
00443   *         CFGR         SYNCSRC       LL_CRS_ConfigSynchronization\n
00444   *         CFGR         SYNCPOL       LL_CRS_ConfigSynchronization
00445   * @param  HSI48CalibrationValue a number between Min_Data = 0 and Max_Data = 127 for STM32L412xx/L422xx or 63 otherwise
00446   * @param  ErrorLimitValue a number between Min_Data = 0 and Max_Data = 0xFFFF
00447   * @param  ReloadValue a number between Min_Data = 0 and Max_Data = 255
00448   * @param  Settings This parameter can be a combination of the following values:
00449   *         @arg @ref LL_CRS_SYNC_DIV_1 or @ref LL_CRS_SYNC_DIV_2 or @ref LL_CRS_SYNC_DIV_4 or @ref LL_CRS_SYNC_DIV_8
00450   *              or @ref LL_CRS_SYNC_DIV_16 or @ref LL_CRS_SYNC_DIV_32 or @ref LL_CRS_SYNC_DIV_64 or @ref LL_CRS_SYNC_DIV_128
00451   *         @arg @ref LL_CRS_SYNC_SOURCE_GPIO or @ref LL_CRS_SYNC_SOURCE_LSE or @ref LL_CRS_SYNC_SOURCE_USB
00452   *         @arg @ref LL_CRS_SYNC_POLARITY_RISING or @ref LL_CRS_SYNC_POLARITY_FALLING
00453   * @retval None
00454   */
00455 __STATIC_INLINE void LL_CRS_ConfigSynchronization(uint32_t HSI48CalibrationValue, uint32_t ErrorLimitValue, uint32_t ReloadValue, uint32_t Settings)
00456 {
00457   MODIFY_REG(CRS->CR, CRS_CR_TRIM, HSI48CalibrationValue);
00458   MODIFY_REG(CRS->CFGR,
00459              CRS_CFGR_RELOAD | CRS_CFGR_FELIM | CRS_CFGR_SYNCDIV | CRS_CFGR_SYNCSRC | CRS_CFGR_SYNCPOL,
00460              ReloadValue | (ErrorLimitValue << CRS_CFGR_FELIM_Pos) | Settings);
00461 }
00462 
00463 /**
00464   * @}
00465   */
00466 
00467 /** @defgroup CRS_LL_EF_CRS_Management CRS_Management
00468   * @{
00469   */
00470 
00471 /**
00472   * @brief  Generate software SYNC event
00473   * @rmtoll CR           SWSYNC        LL_CRS_GenerateEvent_SWSYNC
00474   * @retval None
00475   */
00476 __STATIC_INLINE void LL_CRS_GenerateEvent_SWSYNC(void)
00477 {
00478   SET_BIT(CRS->CR, CRS_CR_SWSYNC);
00479 }
00480 
00481 /**
00482   * @brief  Get the frequency error direction latched in the time of the last
00483   * SYNC event
00484   * @rmtoll ISR          FEDIR         LL_CRS_GetFreqErrorDirection
00485   * @retval Returned value can be one of the following values:
00486   *         @arg @ref LL_CRS_FREQ_ERROR_DIR_UP
00487   *         @arg @ref LL_CRS_FREQ_ERROR_DIR_DOWN
00488   */
00489 __STATIC_INLINE uint32_t LL_CRS_GetFreqErrorDirection(void)
00490 {
00491   return (uint32_t)(READ_BIT(CRS->ISR, CRS_ISR_FEDIR));
00492 }
00493 
00494 /**
00495   * @brief  Get the frequency error counter value latched in the time of the last SYNC event
00496   * @rmtoll ISR          FECAP         LL_CRS_GetFreqErrorCapture
00497   * @retval A number between Min_Data = 0x0000 and Max_Data = 0xFFFF
00498   */
00499 __STATIC_INLINE uint32_t LL_CRS_GetFreqErrorCapture(void)
00500 {
00501   return (uint32_t)(READ_BIT(CRS->ISR, CRS_ISR_FECAP) >> CRS_ISR_FECAP_Pos);
00502 }
00503 
00504 /**
00505   * @}
00506   */
00507 
00508 /** @defgroup CRS_LL_EF_FLAG_Management FLAG_Management
00509   * @{
00510   */
00511 
00512 /**
00513   * @brief  Check if SYNC event OK signal occurred or not
00514   * @rmtoll ISR          SYNCOKF       LL_CRS_IsActiveFlag_SYNCOK
00515   * @retval State of bit (1 or 0).
00516   */
00517 __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_SYNCOK(void)
00518 {
00519   return (READ_BIT(CRS->ISR, CRS_ISR_SYNCOKF) == (CRS_ISR_SYNCOKF));
00520 }
00521 
00522 /**
00523   * @brief  Check if SYNC warning signal occurred or not
00524   * @rmtoll ISR          SYNCWARNF     LL_CRS_IsActiveFlag_SYNCWARN
00525   * @retval State of bit (1 or 0).
00526   */
00527 __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_SYNCWARN(void)
00528 {
00529   return (READ_BIT(CRS->ISR, CRS_ISR_SYNCWARNF) == (CRS_ISR_SYNCWARNF));
00530 }
00531 
00532 /**
00533   * @brief  Check if Synchronization or trimming error signal occurred or not
00534   * @rmtoll ISR          ERRF          LL_CRS_IsActiveFlag_ERR
00535   * @retval State of bit (1 or 0).
00536   */
00537 __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_ERR(void)
00538 {
00539   return (READ_BIT(CRS->ISR, CRS_ISR_ERRF) == (CRS_ISR_ERRF));
00540 }
00541 
00542 /**
00543   * @brief  Check if Expected SYNC signal occurred or not
00544   * @rmtoll ISR          ESYNCF        LL_CRS_IsActiveFlag_ESYNC
00545   * @retval State of bit (1 or 0).
00546   */
00547 __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_ESYNC(void)
00548 {
00549   return (READ_BIT(CRS->ISR, CRS_ISR_ESYNCF) == (CRS_ISR_ESYNCF));
00550 }
00551 
00552 /**
00553   * @brief  Check if SYNC error signal occurred or not
00554   * @rmtoll ISR          SYNCERR       LL_CRS_IsActiveFlag_SYNCERR
00555   * @retval State of bit (1 or 0).
00556   */
00557 __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_SYNCERR(void)
00558 {
00559   return (READ_BIT(CRS->ISR, CRS_ISR_SYNCERR) == (CRS_ISR_SYNCERR));
00560 }
00561 
00562 /**
00563   * @brief  Check if SYNC missed error signal occurred or not
00564   * @rmtoll ISR          SYNCMISS      LL_CRS_IsActiveFlag_SYNCMISS
00565   * @retval State of bit (1 or 0).
00566   */
00567 __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_SYNCMISS(void)
00568 {
00569   return (READ_BIT(CRS->ISR, CRS_ISR_SYNCMISS) == (CRS_ISR_SYNCMISS));
00570 }
00571 
00572 /**
00573   * @brief  Check if Trimming overflow or underflow occurred or not
00574   * @rmtoll ISR          TRIMOVF       LL_CRS_IsActiveFlag_TRIMOVF
00575   * @retval State of bit (1 or 0).
00576   */
00577 __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_TRIMOVF(void)
00578 {
00579   return (READ_BIT(CRS->ISR, CRS_ISR_TRIMOVF) == (CRS_ISR_TRIMOVF));
00580 }
00581 
00582 /**
00583   * @brief  Clear the SYNC event OK flag
00584   * @rmtoll ICR          SYNCOKC       LL_CRS_ClearFlag_SYNCOK
00585   * @retval None
00586   */
00587 __STATIC_INLINE void LL_CRS_ClearFlag_SYNCOK(void)
00588 {
00589   WRITE_REG(CRS->ICR, CRS_ICR_SYNCOKC);
00590 }
00591 
00592 /**
00593   * @brief  Clear the  SYNC warning flag
00594   * @rmtoll ICR          SYNCWARNC     LL_CRS_ClearFlag_SYNCWARN
00595   * @retval None
00596   */
00597 __STATIC_INLINE void LL_CRS_ClearFlag_SYNCWARN(void)
00598 {
00599   WRITE_REG(CRS->ICR, CRS_ICR_SYNCWARNC);
00600 }
00601 
00602 /**
00603   * @brief  Clear TRIMOVF, SYNCMISS and SYNCERR bits and consequently also
00604   * the ERR flag
00605   * @rmtoll ICR          ERRC          LL_CRS_ClearFlag_ERR
00606   * @retval None
00607   */
00608 __STATIC_INLINE void LL_CRS_ClearFlag_ERR(void)
00609 {
00610   WRITE_REG(CRS->ICR, CRS_ICR_ERRC);
00611 }
00612 
00613 /**
00614   * @brief  Clear Expected SYNC flag
00615   * @rmtoll ICR          ESYNCC        LL_CRS_ClearFlag_ESYNC
00616   * @retval None
00617   */
00618 __STATIC_INLINE void LL_CRS_ClearFlag_ESYNC(void)
00619 {
00620   WRITE_REG(CRS->ICR, CRS_ICR_ESYNCC);
00621 }
00622 
00623 /**
00624   * @}
00625   */
00626 
00627 /** @defgroup CRS_LL_EF_IT_Management IT_Management
00628   * @{
00629   */
00630 
00631 /**
00632   * @brief  Enable SYNC event OK interrupt
00633   * @rmtoll CR           SYNCOKIE      LL_CRS_EnableIT_SYNCOK
00634   * @retval None
00635   */
00636 __STATIC_INLINE void LL_CRS_EnableIT_SYNCOK(void)
00637 {
00638   SET_BIT(CRS->CR, CRS_CR_SYNCOKIE);
00639 }
00640 
00641 /**
00642   * @brief  Disable SYNC event OK interrupt
00643   * @rmtoll CR           SYNCOKIE      LL_CRS_DisableIT_SYNCOK
00644   * @retval None
00645   */
00646 __STATIC_INLINE void LL_CRS_DisableIT_SYNCOK(void)
00647 {
00648   CLEAR_BIT(CRS->CR, CRS_CR_SYNCOKIE);
00649 }
00650 
00651 /**
00652   * @brief  Check if SYNC event OK interrupt is enabled or not
00653   * @rmtoll CR           SYNCOKIE      LL_CRS_IsEnabledIT_SYNCOK
00654   * @retval State of bit (1 or 0).
00655   */
00656 __STATIC_INLINE uint32_t LL_CRS_IsEnabledIT_SYNCOK(void)
00657 {
00658   return (READ_BIT(CRS->CR, CRS_CR_SYNCOKIE) == (CRS_CR_SYNCOKIE));
00659 }
00660 
00661 /**
00662   * @brief  Enable SYNC warning interrupt
00663   * @rmtoll CR           SYNCWARNIE    LL_CRS_EnableIT_SYNCWARN
00664   * @retval None
00665   */
00666 __STATIC_INLINE void LL_CRS_EnableIT_SYNCWARN(void)
00667 {
00668   SET_BIT(CRS->CR, CRS_CR_SYNCWARNIE);
00669 }
00670 
00671 /**
00672   * @brief  Disable SYNC warning interrupt
00673   * @rmtoll CR           SYNCWARNIE    LL_CRS_DisableIT_SYNCWARN
00674   * @retval None
00675   */
00676 __STATIC_INLINE void LL_CRS_DisableIT_SYNCWARN(void)
00677 {
00678   CLEAR_BIT(CRS->CR, CRS_CR_SYNCWARNIE);
00679 }
00680 
00681 /**
00682   * @brief  Check if SYNC warning interrupt is enabled or not
00683   * @rmtoll CR           SYNCWARNIE    LL_CRS_IsEnabledIT_SYNCWARN
00684   * @retval State of bit (1 or 0).
00685   */
00686 __STATIC_INLINE uint32_t LL_CRS_IsEnabledIT_SYNCWARN(void)
00687 {
00688   return (READ_BIT(CRS->CR, CRS_CR_SYNCWARNIE) == (CRS_CR_SYNCWARNIE));
00689 }
00690 
00691 /**
00692   * @brief  Enable Synchronization or trimming error interrupt
00693   * @rmtoll CR           ERRIE         LL_CRS_EnableIT_ERR
00694   * @retval None
00695   */
00696 __STATIC_INLINE void LL_CRS_EnableIT_ERR(void)
00697 {
00698   SET_BIT(CRS->CR, CRS_CR_ERRIE);
00699 }
00700 
00701 /**
00702   * @brief  Disable Synchronization or trimming error interrupt
00703   * @rmtoll CR           ERRIE         LL_CRS_DisableIT_ERR
00704   * @retval None
00705   */
00706 __STATIC_INLINE void LL_CRS_DisableIT_ERR(void)
00707 {
00708   CLEAR_BIT(CRS->CR, CRS_CR_ERRIE);
00709 }
00710 
00711 /**
00712   * @brief  Check if Synchronization or trimming error interrupt is enabled or not
00713   * @rmtoll CR           ERRIE         LL_CRS_IsEnabledIT_ERR
00714   * @retval State of bit (1 or 0).
00715   */
00716 __STATIC_INLINE uint32_t LL_CRS_IsEnabledIT_ERR(void)
00717 {
00718   return (READ_BIT(CRS->CR, CRS_CR_ERRIE) == (CRS_CR_ERRIE));
00719 }
00720 
00721 /**
00722   * @brief  Enable Expected SYNC interrupt
00723   * @rmtoll CR           ESYNCIE       LL_CRS_EnableIT_ESYNC
00724   * @retval None
00725   */
00726 __STATIC_INLINE void LL_CRS_EnableIT_ESYNC(void)
00727 {
00728   SET_BIT(CRS->CR, CRS_CR_ESYNCIE);
00729 }
00730 
00731 /**
00732   * @brief  Disable Expected SYNC interrupt
00733   * @rmtoll CR           ESYNCIE       LL_CRS_DisableIT_ESYNC
00734   * @retval None
00735   */
00736 __STATIC_INLINE void LL_CRS_DisableIT_ESYNC(void)
00737 {
00738   CLEAR_BIT(CRS->CR, CRS_CR_ESYNCIE);
00739 }
00740 
00741 /**
00742   * @brief  Check if Expected SYNC interrupt is enabled or not
00743   * @rmtoll CR           ESYNCIE       LL_CRS_IsEnabledIT_ESYNC
00744   * @retval State of bit (1 or 0).
00745   */
00746 __STATIC_INLINE uint32_t LL_CRS_IsEnabledIT_ESYNC(void)
00747 {
00748   return (READ_BIT(CRS->CR, CRS_CR_ESYNCIE) == (CRS_CR_ESYNCIE));
00749 }
00750 
00751 /**
00752   * @}
00753   */
00754 
00755 #if defined(USE_FULL_LL_DRIVER)
00756 /** @defgroup CRS_LL_EF_Init Initialization and de-initialization functions
00757   * @{
00758   */
00759 
00760 ErrorStatus LL_CRS_DeInit(void);
00761 
00762 /**
00763   * @}
00764   */
00765 #endif /* USE_FULL_LL_DRIVER */
00766 
00767 /**
00768   * @}
00769   */
00770 
00771 /**
00772   * @}
00773   */
00774 
00775 #endif /* defined(CRS) */
00776 
00777 /**
00778   * @}
00779   */
00780 
00781 #ifdef __cplusplus
00782 }
00783 #endif
00784 
00785 #endif /* STM32L4xx_LL_CRS_H */