stm32h5xx_ll_crs.h 24 KB

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