stm32g4xx_ll_crs.h 24 KB

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