You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

799 lines
24 KiB

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