stm32l4xx_ll_crs.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_crs.h
  4. * @author MCD Application Team
  5. * @brief Header file of CRS LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32L4xx_LL_CRS_H
  20. #define STM32L4xx_LL_CRS_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l4xx.h"
  26. /** @addtogroup STM32L4xx_LL_Driver
  27. * @{
  28. */
  29. #if defined(CRS)
  30. /** @defgroup CRS_LL CRS
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. /* Private macros ------------------------------------------------------------*/
  37. /* Exported types ------------------------------------------------------------*/
  38. /* Exported constants --------------------------------------------------------*/
  39. /** @defgroup CRS_LL_Exported_Constants CRS Exported Constants
  40. * @{
  41. */
  42. /** @defgroup CRS_LL_EC_GET_FLAG Get Flags Defines
  43. * @brief Flags defines which can be used with LL_CRS_ReadReg function
  44. * @{
  45. */
  46. #define LL_CRS_ISR_SYNCOKF CRS_ISR_SYNCOKF
  47. #define LL_CRS_ISR_SYNCWARNF CRS_ISR_SYNCWARNF
  48. #define LL_CRS_ISR_ERRF CRS_ISR_ERRF
  49. #define LL_CRS_ISR_ESYNCF CRS_ISR_ESYNCF
  50. #define LL_CRS_ISR_SYNCERR CRS_ISR_SYNCERR
  51. #define LL_CRS_ISR_SYNCMISS CRS_ISR_SYNCMISS
  52. #define LL_CRS_ISR_TRIMOVF CRS_ISR_TRIMOVF
  53. /**
  54. * @}
  55. */
  56. /** @defgroup CRS_LL_EC_IT IT Defines
  57. * @brief IT defines which can be used with LL_CRS_ReadReg and LL_CRS_WriteReg functions
  58. * @{
  59. */
  60. #define LL_CRS_CR_SYNCOKIE CRS_CR_SYNCOKIE
  61. #define LL_CRS_CR_SYNCWARNIE CRS_CR_SYNCWARNIE
  62. #define LL_CRS_CR_ERRIE CRS_CR_ERRIE
  63. #define LL_CRS_CR_ESYNCIE CRS_CR_ESYNCIE
  64. /**
  65. * @}
  66. */
  67. /** @defgroup CRS_LL_EC_SYNC_DIV Synchronization Signal Divider
  68. * @{
  69. */
  70. #define LL_CRS_SYNC_DIV_1 ((uint32_t)0x00U) /*!< Synchro Signal not divided (default) */
  71. #define LL_CRS_SYNC_DIV_2 CRS_CFGR_SYNCDIV_0 /*!< Synchro Signal divided by 2 */
  72. #define LL_CRS_SYNC_DIV_4 CRS_CFGR_SYNCDIV_1 /*!< Synchro Signal divided by 4 */
  73. #define LL_CRS_SYNC_DIV_8 (CRS_CFGR_SYNCDIV_1 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 8 */
  74. #define LL_CRS_SYNC_DIV_16 CRS_CFGR_SYNCDIV_2 /*!< Synchro Signal divided by 16 */
  75. #define LL_CRS_SYNC_DIV_32 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 32 */
  76. #define LL_CRS_SYNC_DIV_64 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_1) /*!< Synchro Signal divided by 64 */
  77. #define LL_CRS_SYNC_DIV_128 CRS_CFGR_SYNCDIV /*!< Synchro Signal divided by 128 */
  78. /**
  79. * @}
  80. */
  81. /** @defgroup CRS_LL_EC_SYNC_SOURCE Synchronization Signal Source
  82. * @{
  83. */
  84. #define LL_CRS_SYNC_SOURCE_GPIO ((uint32_t)0x00U) /*!< Synchro Signal source GPIO */
  85. #define LL_CRS_SYNC_SOURCE_LSE CRS_CFGR_SYNCSRC_0 /*!< Synchro Signal source LSE */
  86. #define LL_CRS_SYNC_SOURCE_USB CRS_CFGR_SYNCSRC_1 /*!< Synchro Signal source USB SOF (default)*/
  87. /**
  88. * @}
  89. */
  90. /** @defgroup CRS_LL_EC_SYNC_POLARITY Synchronization Signal Polarity
  91. * @{
  92. */
  93. #define LL_CRS_SYNC_POLARITY_RISING ((uint32_t)0x00U) /*!< Synchro Active on rising edge (default) */
  94. #define LL_CRS_SYNC_POLARITY_FALLING CRS_CFGR_SYNCPOL /*!< Synchro Active on falling edge */
  95. /**
  96. * @}
  97. */
  98. /** @defgroup CRS_LL_EC_FREQERRORDIR Frequency Error Direction
  99. * @{
  100. */
  101. #define LL_CRS_FREQ_ERROR_DIR_UP ((uint32_t)0x00U) /*!< Upcounting direction, the actual frequency is above the target */
  102. #define LL_CRS_FREQ_ERROR_DIR_DOWN ((uint32_t)CRS_ISR_FEDIR) /*!< Downcounting direction, the actual frequency is below the target */
  103. /**
  104. * @}
  105. */
  106. /** @defgroup CRS_LL_EC_DEFAULTVALUES Default Values
  107. * @{
  108. */
  109. /**
  110. * @brief Reset value of the RELOAD field
  111. * @note The reset value of the RELOAD field corresponds to a target frequency of 48 MHz
  112. * and a synchronization signal frequency of 1 kHz (SOF signal from USB)
  113. */
  114. #define LL_CRS_RELOADVALUE_DEFAULT ((uint32_t)0xBB7FU)
  115. /**
  116. * @brief Reset value of Frequency error limit.
  117. */
  118. #define LL_CRS_ERRORLIMIT_DEFAULT ((uint32_t)0x22U)
  119. /**
  120. * @brief Reset value of the HSI48 Calibration field
  121. * @note The default value is 64 for STM32L412xx/L422xx, 32 otherwise, which corresponds
  122. * to the middle of the trimming interval.
  123. * The trimming step is around 67 kHz between two consecutive TRIM steps.
  124. * A higher TRIM value corresponds to a higher output frequency
  125. */
  126. #if defined (STM32L412xx) || defined (STM32L422xx)
  127. #define LL_CRS_HSI48CALIBRATION_DEFAULT ((uint32_t)64U)
  128. #else
  129. #define LL_CRS_HSI48CALIBRATION_DEFAULT ((uint32_t)32U)
  130. #endif
  131. /**
  132. * @}
  133. */
  134. /**
  135. * @}
  136. */
  137. /* Exported macro ------------------------------------------------------------*/
  138. /** @defgroup CRS_LL_Exported_Macros CRS Exported Macros
  139. * @{
  140. */
  141. /** @defgroup CRS_LL_EM_WRITE_READ Common Write and read registers Macros
  142. * @{
  143. */
  144. /**
  145. * @brief Write a value in CRS register
  146. * @param __INSTANCE__ CRS Instance
  147. * @param __REG__ Register to be written
  148. * @param __VALUE__ Value to be written in the register
  149. * @retval None
  150. */
  151. #define LL_CRS_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  152. /**
  153. * @brief Read a value in CRS register
  154. * @param __INSTANCE__ CRS Instance
  155. * @param __REG__ Register to be read
  156. * @retval Register value
  157. */
  158. #define LL_CRS_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  159. /**
  160. * @}
  161. */
  162. /** @defgroup CRS_LL_EM_Exported_Macros_Calculate_Reload Exported_Macros_Calculate_Reload
  163. * @{
  164. */
  165. /**
  166. * @brief Macro to calculate reload value to be set in CRS register according to target and sync frequencies
  167. * @note The RELOAD value should be selected according to the ratio between
  168. * the target frequency and the frequency of the synchronization source after
  169. * prescaling. It is then decreased by one in order to reach the expected
  170. * synchronization on the zero value. The formula is the following:
  171. * RELOAD = (fTARGET / fSYNC) -1
  172. * @param __FTARGET__ Target frequency (value in Hz)
  173. * @param __FSYNC__ Synchronization signal frequency (value in Hz)
  174. * @retval Reload value (in Hz)
  175. */
  176. #define __LL_CRS_CALC_CALCULATE_RELOADVALUE(__FTARGET__, __FSYNC__) (((__FTARGET__) / (__FSYNC__)) - 1U)
  177. /**
  178. * @}
  179. */
  180. /**
  181. * @}
  182. */
  183. /* Exported functions --------------------------------------------------------*/
  184. /** @defgroup CRS_LL_Exported_Functions CRS Exported Functions
  185. * @{
  186. */
  187. /** @defgroup CRS_LL_EF_Configuration Configuration
  188. * @{
  189. */
  190. /**
  191. * @brief Enable Frequency error counter
  192. * @note When this bit is set, the CRS_CFGR register is write-protected and cannot be modified
  193. * @rmtoll CR CEN LL_CRS_EnableFreqErrorCounter
  194. * @retval None
  195. */
  196. __STATIC_INLINE void LL_CRS_EnableFreqErrorCounter(void)
  197. {
  198. SET_BIT(CRS->CR, CRS_CR_CEN);
  199. }
  200. /**
  201. * @brief Disable Frequency error counter
  202. * @rmtoll CR CEN LL_CRS_DisableFreqErrorCounter
  203. * @retval None
  204. */
  205. __STATIC_INLINE void LL_CRS_DisableFreqErrorCounter(void)
  206. {
  207. CLEAR_BIT(CRS->CR, CRS_CR_CEN);
  208. }
  209. /**
  210. * @brief Check if Frequency error counter is enabled or not
  211. * @rmtoll CR CEN LL_CRS_IsEnabledFreqErrorCounter
  212. * @retval State of bit (1 or 0).
  213. */
  214. __STATIC_INLINE uint32_t LL_CRS_IsEnabledFreqErrorCounter(void)
  215. {
  216. return (READ_BIT(CRS->CR, CRS_CR_CEN) == (CRS_CR_CEN));
  217. }
  218. /**
  219. * @brief Enable Automatic trimming counter
  220. * @rmtoll CR AUTOTRIMEN LL_CRS_EnableAutoTrimming
  221. * @retval None
  222. */
  223. __STATIC_INLINE void LL_CRS_EnableAutoTrimming(void)
  224. {
  225. SET_BIT(CRS->CR, CRS_CR_AUTOTRIMEN);
  226. }
  227. /**
  228. * @brief Disable Automatic trimming counter
  229. * @rmtoll CR AUTOTRIMEN LL_CRS_DisableAutoTrimming
  230. * @retval None
  231. */
  232. __STATIC_INLINE void LL_CRS_DisableAutoTrimming(void)
  233. {
  234. CLEAR_BIT(CRS->CR, CRS_CR_AUTOTRIMEN);
  235. }
  236. /**
  237. * @brief Check if Automatic trimming is enabled or not
  238. * @rmtoll CR AUTOTRIMEN LL_CRS_IsEnabledAutoTrimming
  239. * @retval State of bit (1 or 0).
  240. */
  241. __STATIC_INLINE uint32_t LL_CRS_IsEnabledAutoTrimming(void)
  242. {
  243. return (READ_BIT(CRS->CR, CRS_CR_AUTOTRIMEN) == (CRS_CR_AUTOTRIMEN));
  244. }
  245. /**
  246. * @brief Set HSI48 oscillator smooth trimming
  247. * @note When the AUTOTRIMEN bit is set, this field is controlled by hardware and is read-only
  248. * @rmtoll CR TRIM LL_CRS_SetHSI48SmoothTrimming
  249. * @param Value a number between Min_Data = 0 and Max_Data = 127 for STM32L412xx/L422xx or 63 otherwise
  250. * @note Default value can be set thanks to @ref LL_CRS_HSI48CALIBRATION_DEFAULT
  251. * @retval None
  252. */
  253. __STATIC_INLINE void LL_CRS_SetHSI48SmoothTrimming(uint32_t Value)
  254. {
  255. MODIFY_REG(CRS->CR, CRS_CR_TRIM, Value << CRS_CR_TRIM_Pos);
  256. }
  257. /**
  258. * @brief Get HSI48 oscillator smooth trimming
  259. * @rmtoll CR TRIM LL_CRS_GetHSI48SmoothTrimming
  260. * @retval a number between Min_Data = 0 and Max_Data = 127 for STM32L412xx/L422xx or 63 otherwise
  261. */
  262. __STATIC_INLINE uint32_t LL_CRS_GetHSI48SmoothTrimming(void)
  263. {
  264. return (uint32_t)(READ_BIT(CRS->CR, CRS_CR_TRIM) >> CRS_CR_TRIM_Pos);
  265. }
  266. /**
  267. * @brief Set counter reload value
  268. * @rmtoll CFGR RELOAD LL_CRS_SetReloadCounter
  269. * @param Value a number between Min_Data = 0 and Max_Data = 0xFFFF
  270. * @note Default value can be set thanks to @ref LL_CRS_RELOADVALUE_DEFAULT
  271. * Otherwise it can be calculated in using macro @ref __LL_CRS_CALC_CALCULATE_RELOADVALUE (_FTARGET_, _FSYNC_)
  272. * @retval None
  273. */
  274. __STATIC_INLINE void LL_CRS_SetReloadCounter(uint32_t Value)
  275. {
  276. MODIFY_REG(CRS->CFGR, CRS_CFGR_RELOAD, Value);
  277. }
  278. /**
  279. * @brief Get counter reload value
  280. * @rmtoll CFGR RELOAD LL_CRS_GetReloadCounter
  281. * @retval a number between Min_Data = 0 and Max_Data = 0xFFFF
  282. */
  283. __STATIC_INLINE uint32_t LL_CRS_GetReloadCounter(void)
  284. {
  285. return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_RELOAD));
  286. }
  287. /**
  288. * @brief Set frequency error limit
  289. * @rmtoll CFGR FELIM LL_CRS_SetFreqErrorLimit
  290. * @param Value a number between Min_Data = 0 and Max_Data = 255
  291. * @note Default value can be set thanks to @ref LL_CRS_ERRORLIMIT_DEFAULT
  292. * @retval None
  293. */
  294. __STATIC_INLINE void LL_CRS_SetFreqErrorLimit(uint32_t Value)
  295. {
  296. MODIFY_REG(CRS->CFGR, CRS_CFGR_FELIM, Value << CRS_CFGR_FELIM_Pos);
  297. }
  298. /**
  299. * @brief Get frequency error limit
  300. * @rmtoll CFGR FELIM LL_CRS_GetFreqErrorLimit
  301. * @retval A number between Min_Data = 0 and Max_Data = 255
  302. */
  303. __STATIC_INLINE uint32_t LL_CRS_GetFreqErrorLimit(void)
  304. {
  305. return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_FELIM) >> CRS_CFGR_FELIM_Pos);
  306. }
  307. /**
  308. * @brief Set division factor for SYNC signal
  309. * @rmtoll CFGR SYNCDIV LL_CRS_SetSyncDivider
  310. * @param Divider This parameter can be one of the following values:
  311. * @arg @ref LL_CRS_SYNC_DIV_1
  312. * @arg @ref LL_CRS_SYNC_DIV_2
  313. * @arg @ref LL_CRS_SYNC_DIV_4
  314. * @arg @ref LL_CRS_SYNC_DIV_8
  315. * @arg @ref LL_CRS_SYNC_DIV_16
  316. * @arg @ref LL_CRS_SYNC_DIV_32
  317. * @arg @ref LL_CRS_SYNC_DIV_64
  318. * @arg @ref LL_CRS_SYNC_DIV_128
  319. * @retval None
  320. */
  321. __STATIC_INLINE void LL_CRS_SetSyncDivider(uint32_t Divider)
  322. {
  323. MODIFY_REG(CRS->CFGR, CRS_CFGR_SYNCDIV, Divider);
  324. }
  325. /**
  326. * @brief Get division factor for SYNC signal
  327. * @rmtoll CFGR SYNCDIV LL_CRS_GetSyncDivider
  328. * @retval Returned value can be one of the following values:
  329. * @arg @ref LL_CRS_SYNC_DIV_1
  330. * @arg @ref LL_CRS_SYNC_DIV_2
  331. * @arg @ref LL_CRS_SYNC_DIV_4
  332. * @arg @ref LL_CRS_SYNC_DIV_8
  333. * @arg @ref LL_CRS_SYNC_DIV_16
  334. * @arg @ref LL_CRS_SYNC_DIV_32
  335. * @arg @ref LL_CRS_SYNC_DIV_64
  336. * @arg @ref LL_CRS_SYNC_DIV_128
  337. */
  338. __STATIC_INLINE uint32_t LL_CRS_GetSyncDivider(void)
  339. {
  340. return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_SYNCDIV));
  341. }
  342. /**
  343. * @brief Set SYNC signal source
  344. * @rmtoll CFGR SYNCSRC LL_CRS_SetSyncSignalSource
  345. * @param Source This parameter can be one of the following values:
  346. * @arg @ref LL_CRS_SYNC_SOURCE_GPIO
  347. * @arg @ref LL_CRS_SYNC_SOURCE_LSE
  348. * @arg @ref LL_CRS_SYNC_SOURCE_USB
  349. * @retval None
  350. */
  351. __STATIC_INLINE void LL_CRS_SetSyncSignalSource(uint32_t Source)
  352. {
  353. MODIFY_REG(CRS->CFGR, CRS_CFGR_SYNCSRC, Source);
  354. }
  355. /**
  356. * @brief Get SYNC signal source
  357. * @rmtoll CFGR SYNCSRC LL_CRS_GetSyncSignalSource
  358. * @retval Returned value can be one of the following values:
  359. * @arg @ref LL_CRS_SYNC_SOURCE_GPIO
  360. * @arg @ref LL_CRS_SYNC_SOURCE_LSE
  361. * @arg @ref LL_CRS_SYNC_SOURCE_USB
  362. */
  363. __STATIC_INLINE uint32_t LL_CRS_GetSyncSignalSource(void)
  364. {
  365. return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_SYNCSRC));
  366. }
  367. /**
  368. * @brief Set input polarity for the SYNC signal source
  369. * @rmtoll CFGR SYNCPOL LL_CRS_SetSyncPolarity
  370. * @param Polarity This parameter can be one of the following values:
  371. * @arg @ref LL_CRS_SYNC_POLARITY_RISING
  372. * @arg @ref LL_CRS_SYNC_POLARITY_FALLING
  373. * @retval None
  374. */
  375. __STATIC_INLINE void LL_CRS_SetSyncPolarity(uint32_t Polarity)
  376. {
  377. MODIFY_REG(CRS->CFGR, CRS_CFGR_SYNCPOL, Polarity);
  378. }
  379. /**
  380. * @brief Get input polarity for the SYNC signal source
  381. * @rmtoll CFGR SYNCPOL LL_CRS_GetSyncPolarity
  382. * @retval Returned value can be one of the following values:
  383. * @arg @ref LL_CRS_SYNC_POLARITY_RISING
  384. * @arg @ref LL_CRS_SYNC_POLARITY_FALLING
  385. */
  386. __STATIC_INLINE uint32_t LL_CRS_GetSyncPolarity(void)
  387. {
  388. return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_SYNCPOL));
  389. }
  390. /**
  391. * @brief Configure CRS for the synchronization
  392. * @rmtoll CR TRIM LL_CRS_ConfigSynchronization\n
  393. * CFGR RELOAD LL_CRS_ConfigSynchronization\n
  394. * CFGR FELIM LL_CRS_ConfigSynchronization\n
  395. * CFGR SYNCDIV LL_CRS_ConfigSynchronization\n
  396. * CFGR SYNCSRC LL_CRS_ConfigSynchronization\n
  397. * CFGR SYNCPOL LL_CRS_ConfigSynchronization
  398. * @param HSI48CalibrationValue a number between Min_Data = 0 and Max_Data = 127 for STM32L412xx/L422xx or 63 otherwise
  399. * @param ErrorLimitValue a number between Min_Data = 0 and Max_Data = 0xFFFF
  400. * @param ReloadValue a number between Min_Data = 0 and Max_Data = 255
  401. * @param Settings This parameter can be a combination of the following values:
  402. * @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
  403. * 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
  404. * @arg @ref LL_CRS_SYNC_SOURCE_GPIO or @ref LL_CRS_SYNC_SOURCE_LSE or @ref LL_CRS_SYNC_SOURCE_USB
  405. * @arg @ref LL_CRS_SYNC_POLARITY_RISING or @ref LL_CRS_SYNC_POLARITY_FALLING
  406. * @retval None
  407. */
  408. __STATIC_INLINE void LL_CRS_ConfigSynchronization(uint32_t HSI48CalibrationValue, uint32_t ErrorLimitValue, uint32_t ReloadValue, uint32_t Settings)
  409. {
  410. MODIFY_REG(CRS->CR, CRS_CR_TRIM, HSI48CalibrationValue << CRS_CR_TRIM_Pos);
  411. MODIFY_REG(CRS->CFGR,
  412. CRS_CFGR_RELOAD | CRS_CFGR_FELIM | CRS_CFGR_SYNCDIV | CRS_CFGR_SYNCSRC | CRS_CFGR_SYNCPOL,
  413. ReloadValue | (ErrorLimitValue << CRS_CFGR_FELIM_Pos) | Settings);
  414. }
  415. /**
  416. * @}
  417. */
  418. /** @defgroup CRS_LL_EF_CRS_Management CRS_Management
  419. * @{
  420. */
  421. /**
  422. * @brief Generate software SYNC event
  423. * @rmtoll CR SWSYNC LL_CRS_GenerateEvent_SWSYNC
  424. * @retval None
  425. */
  426. __STATIC_INLINE void LL_CRS_GenerateEvent_SWSYNC(void)
  427. {
  428. SET_BIT(CRS->CR, CRS_CR_SWSYNC);
  429. }
  430. /**
  431. * @brief Get the frequency error direction latched in the time of the last
  432. * SYNC event
  433. * @rmtoll ISR FEDIR LL_CRS_GetFreqErrorDirection
  434. * @retval Returned value can be one of the following values:
  435. * @arg @ref LL_CRS_FREQ_ERROR_DIR_UP
  436. * @arg @ref LL_CRS_FREQ_ERROR_DIR_DOWN
  437. */
  438. __STATIC_INLINE uint32_t LL_CRS_GetFreqErrorDirection(void)
  439. {
  440. return (uint32_t)(READ_BIT(CRS->ISR, CRS_ISR_FEDIR));
  441. }
  442. /**
  443. * @brief Get the frequency error counter value latched in the time of the last SYNC event
  444. * @rmtoll ISR FECAP LL_CRS_GetFreqErrorCapture
  445. * @retval A number between Min_Data = 0x0000 and Max_Data = 0xFFFF
  446. */
  447. __STATIC_INLINE uint32_t LL_CRS_GetFreqErrorCapture(void)
  448. {
  449. return (uint32_t)(READ_BIT(CRS->ISR, CRS_ISR_FECAP) >> CRS_ISR_FECAP_Pos);
  450. }
  451. /**
  452. * @}
  453. */
  454. /** @defgroup CRS_LL_EF_FLAG_Management FLAG_Management
  455. * @{
  456. */
  457. /**
  458. * @brief Check if SYNC event OK signal occurred or not
  459. * @rmtoll ISR SYNCOKF LL_CRS_IsActiveFlag_SYNCOK
  460. * @retval State of bit (1 or 0).
  461. */
  462. __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_SYNCOK(void)
  463. {
  464. return (READ_BIT(CRS->ISR, CRS_ISR_SYNCOKF) == (CRS_ISR_SYNCOKF));
  465. }
  466. /**
  467. * @brief Check if SYNC warning signal occurred or not
  468. * @rmtoll ISR SYNCWARNF LL_CRS_IsActiveFlag_SYNCWARN
  469. * @retval State of bit (1 or 0).
  470. */
  471. __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_SYNCWARN(void)
  472. {
  473. return (READ_BIT(CRS->ISR, CRS_ISR_SYNCWARNF) == (CRS_ISR_SYNCWARNF));
  474. }
  475. /**
  476. * @brief Check if Synchronization or trimming error signal occurred or not
  477. * @rmtoll ISR ERRF LL_CRS_IsActiveFlag_ERR
  478. * @retval State of bit (1 or 0).
  479. */
  480. __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_ERR(void)
  481. {
  482. return (READ_BIT(CRS->ISR, CRS_ISR_ERRF) == (CRS_ISR_ERRF));
  483. }
  484. /**
  485. * @brief Check if Expected SYNC signal occurred or not
  486. * @rmtoll ISR ESYNCF LL_CRS_IsActiveFlag_ESYNC
  487. * @retval State of bit (1 or 0).
  488. */
  489. __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_ESYNC(void)
  490. {
  491. return (READ_BIT(CRS->ISR, CRS_ISR_ESYNCF) == (CRS_ISR_ESYNCF));
  492. }
  493. /**
  494. * @brief Check if SYNC error signal occurred or not
  495. * @rmtoll ISR SYNCERR LL_CRS_IsActiveFlag_SYNCERR
  496. * @retval State of bit (1 or 0).
  497. */
  498. __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_SYNCERR(void)
  499. {
  500. return (READ_BIT(CRS->ISR, CRS_ISR_SYNCERR) == (CRS_ISR_SYNCERR));
  501. }
  502. /**
  503. * @brief Check if SYNC missed error signal occurred or not
  504. * @rmtoll ISR SYNCMISS LL_CRS_IsActiveFlag_SYNCMISS
  505. * @retval State of bit (1 or 0).
  506. */
  507. __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_SYNCMISS(void)
  508. {
  509. return (READ_BIT(CRS->ISR, CRS_ISR_SYNCMISS) == (CRS_ISR_SYNCMISS));
  510. }
  511. /**
  512. * @brief Check if Trimming overflow or underflow occurred or not
  513. * @rmtoll ISR TRIMOVF LL_CRS_IsActiveFlag_TRIMOVF
  514. * @retval State of bit (1 or 0).
  515. */
  516. __STATIC_INLINE uint32_t LL_CRS_IsActiveFlag_TRIMOVF(void)
  517. {
  518. return (READ_BIT(CRS->ISR, CRS_ISR_TRIMOVF) == (CRS_ISR_TRIMOVF));
  519. }
  520. /**
  521. * @brief Clear the SYNC event OK flag
  522. * @rmtoll ICR SYNCOKC LL_CRS_ClearFlag_SYNCOK
  523. * @retval None
  524. */
  525. __STATIC_INLINE void LL_CRS_ClearFlag_SYNCOK(void)
  526. {
  527. WRITE_REG(CRS->ICR, CRS_ICR_SYNCOKC);
  528. }
  529. /**
  530. * @brief Clear the SYNC warning flag
  531. * @rmtoll ICR SYNCWARNC LL_CRS_ClearFlag_SYNCWARN
  532. * @retval None
  533. */
  534. __STATIC_INLINE void LL_CRS_ClearFlag_SYNCWARN(void)
  535. {
  536. WRITE_REG(CRS->ICR, CRS_ICR_SYNCWARNC);
  537. }
  538. /**
  539. * @brief Clear TRIMOVF, SYNCMISS and SYNCERR bits and consequently also
  540. * the ERR flag
  541. * @rmtoll ICR ERRC LL_CRS_ClearFlag_ERR
  542. * @retval None
  543. */
  544. __STATIC_INLINE void LL_CRS_ClearFlag_ERR(void)
  545. {
  546. WRITE_REG(CRS->ICR, CRS_ICR_ERRC);
  547. }
  548. /**
  549. * @brief Clear Expected SYNC flag
  550. * @rmtoll ICR ESYNCC LL_CRS_ClearFlag_ESYNC
  551. * @retval None
  552. */
  553. __STATIC_INLINE void LL_CRS_ClearFlag_ESYNC(void)
  554. {
  555. WRITE_REG(CRS->ICR, CRS_ICR_ESYNCC);
  556. }
  557. /**
  558. * @}
  559. */
  560. /** @defgroup CRS_LL_EF_IT_Management IT_Management
  561. * @{
  562. */
  563. /**
  564. * @brief Enable SYNC event OK interrupt
  565. * @rmtoll CR SYNCOKIE LL_CRS_EnableIT_SYNCOK
  566. * @retval None
  567. */
  568. __STATIC_INLINE void LL_CRS_EnableIT_SYNCOK(void)
  569. {
  570. SET_BIT(CRS->CR, CRS_CR_SYNCOKIE);
  571. }
  572. /**
  573. * @brief Disable SYNC event OK interrupt
  574. * @rmtoll CR SYNCOKIE LL_CRS_DisableIT_SYNCOK
  575. * @retval None
  576. */
  577. __STATIC_INLINE void LL_CRS_DisableIT_SYNCOK(void)
  578. {
  579. CLEAR_BIT(CRS->CR, CRS_CR_SYNCOKIE);
  580. }
  581. /**
  582. * @brief Check if SYNC event OK interrupt is enabled or not
  583. * @rmtoll CR SYNCOKIE LL_CRS_IsEnabledIT_SYNCOK
  584. * @retval State of bit (1 or 0).
  585. */
  586. __STATIC_INLINE uint32_t LL_CRS_IsEnabledIT_SYNCOK(void)
  587. {
  588. return (READ_BIT(CRS->CR, CRS_CR_SYNCOKIE) == (CRS_CR_SYNCOKIE));
  589. }
  590. /**
  591. * @brief Enable SYNC warning interrupt
  592. * @rmtoll CR SYNCWARNIE LL_CRS_EnableIT_SYNCWARN
  593. * @retval None
  594. */
  595. __STATIC_INLINE void LL_CRS_EnableIT_SYNCWARN(void)
  596. {
  597. SET_BIT(CRS->CR, CRS_CR_SYNCWARNIE);
  598. }
  599. /**
  600. * @brief Disable SYNC warning interrupt
  601. * @rmtoll CR SYNCWARNIE LL_CRS_DisableIT_SYNCWARN
  602. * @retval None
  603. */
  604. __STATIC_INLINE void LL_CRS_DisableIT_SYNCWARN(void)
  605. {
  606. CLEAR_BIT(CRS->CR, CRS_CR_SYNCWARNIE);
  607. }
  608. /**
  609. * @brief Check if SYNC warning interrupt is enabled or not
  610. * @rmtoll CR SYNCWARNIE LL_CRS_IsEnabledIT_SYNCWARN
  611. * @retval State of bit (1 or 0).
  612. */
  613. __STATIC_INLINE uint32_t LL_CRS_IsEnabledIT_SYNCWARN(void)
  614. {
  615. return (READ_BIT(CRS->CR, CRS_CR_SYNCWARNIE) == (CRS_CR_SYNCWARNIE));
  616. }
  617. /**
  618. * @brief Enable Synchronization or trimming error interrupt
  619. * @rmtoll CR ERRIE LL_CRS_EnableIT_ERR
  620. * @retval None
  621. */
  622. __STATIC_INLINE void LL_CRS_EnableIT_ERR(void)
  623. {
  624. SET_BIT(CRS->CR, CRS_CR_ERRIE);
  625. }
  626. /**
  627. * @brief Disable Synchronization or trimming error interrupt
  628. * @rmtoll CR ERRIE LL_CRS_DisableIT_ERR
  629. * @retval None
  630. */
  631. __STATIC_INLINE void LL_CRS_DisableIT_ERR(void)
  632. {
  633. CLEAR_BIT(CRS->CR, CRS_CR_ERRIE);
  634. }
  635. /**
  636. * @brief Check if Synchronization or trimming error interrupt is enabled or not
  637. * @rmtoll CR ERRIE LL_CRS_IsEnabledIT_ERR
  638. * @retval State of bit (1 or 0).
  639. */
  640. __STATIC_INLINE uint32_t LL_CRS_IsEnabledIT_ERR(void)
  641. {
  642. return (READ_BIT(CRS->CR, CRS_CR_ERRIE) == (CRS_CR_ERRIE));
  643. }
  644. /**
  645. * @brief Enable Expected SYNC interrupt
  646. * @rmtoll CR ESYNCIE LL_CRS_EnableIT_ESYNC
  647. * @retval None
  648. */
  649. __STATIC_INLINE void LL_CRS_EnableIT_ESYNC(void)
  650. {
  651. SET_BIT(CRS->CR, CRS_CR_ESYNCIE);
  652. }
  653. /**
  654. * @brief Disable Expected SYNC interrupt
  655. * @rmtoll CR ESYNCIE LL_CRS_DisableIT_ESYNC
  656. * @retval None
  657. */
  658. __STATIC_INLINE void LL_CRS_DisableIT_ESYNC(void)
  659. {
  660. CLEAR_BIT(CRS->CR, CRS_CR_ESYNCIE);
  661. }
  662. /**
  663. * @brief Check if Expected SYNC interrupt is enabled or not
  664. * @rmtoll CR ESYNCIE LL_CRS_IsEnabledIT_ESYNC
  665. * @retval State of bit (1 or 0).
  666. */
  667. __STATIC_INLINE uint32_t LL_CRS_IsEnabledIT_ESYNC(void)
  668. {
  669. return (READ_BIT(CRS->CR, CRS_CR_ESYNCIE) == (CRS_CR_ESYNCIE));
  670. }
  671. /**
  672. * @}
  673. */
  674. #if defined(USE_FULL_LL_DRIVER)
  675. /** @defgroup CRS_LL_EF_Init Initialization and de-initialization functions
  676. * @{
  677. */
  678. ErrorStatus LL_CRS_DeInit(void);
  679. /**
  680. * @}
  681. */
  682. #endif /* USE_FULL_LL_DRIVER */
  683. /**
  684. * @}
  685. */
  686. /**
  687. * @}
  688. */
  689. #endif /* defined(CRS) */
  690. /**
  691. * @}
  692. */
  693. #ifdef __cplusplus
  694. }
  695. #endif
  696. #endif /* STM32L4xx_LL_CRS_H */