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.
 
 
 

784 lines
24 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_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 STM32H7xx_LL_CRS_H
  21. #define STM32H7xx_LL_CRS_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32h7xx.h"
  27. /** @addtogroup STM32H7xx_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. /* Private macros ------------------------------------------------------------*/
  38. /* Exported types ------------------------------------------------------------*/
  39. /* Exported constants --------------------------------------------------------*/
  40. /** @defgroup CRS_LL_Exported_Constants CRS Exported Constants
  41. * @{
  42. */
  43. /** @defgroup CRS_LL_EC_GET_FLAG Get Flags Defines
  44. * @brief Flags defines which can be used with LL_CRS_ReadReg function
  45. * @{
  46. */
  47. #define LL_CRS_ISR_SYNCOKF CRS_ISR_SYNCOKF
  48. #define LL_CRS_ISR_SYNCWARNF CRS_ISR_SYNCWARNF
  49. #define LL_CRS_ISR_ERRF CRS_ISR_ERRF
  50. #define LL_CRS_ISR_ESYNCF CRS_ISR_ESYNCF
  51. #define LL_CRS_ISR_SYNCERR CRS_ISR_SYNCERR
  52. #define LL_CRS_ISR_SYNCMISS CRS_ISR_SYNCMISS
  53. #define LL_CRS_ISR_TRIMOVF CRS_ISR_TRIMOVF
  54. /**
  55. * @}
  56. */
  57. /** @defgroup CRS_LL_EC_IT IT Defines
  58. * @brief IT defines which can be used with LL_CRS_ReadReg and LL_CRS_WriteReg functions
  59. * @{
  60. */
  61. #define LL_CRS_CR_SYNCOKIE CRS_CR_SYNCOKIE
  62. #define LL_CRS_CR_SYNCWARNIE CRS_CR_SYNCWARNIE
  63. #define LL_CRS_CR_ERRIE CRS_CR_ERRIE
  64. #define LL_CRS_CR_ESYNCIE CRS_CR_ESYNCIE
  65. /**
  66. * @}
  67. */
  68. /** @defgroup CRS_LL_EC_SYNC_DIV Synchronization Signal Divider
  69. * @{
  70. */
  71. #define LL_CRS_SYNC_DIV_1 0x00000000U /*!< Synchro Signal not divided (default) */
  72. #define LL_CRS_SYNC_DIV_2 CRS_CFGR_SYNCDIV_0 /*!< Synchro Signal divided by 2 */
  73. #define LL_CRS_SYNC_DIV_4 CRS_CFGR_SYNCDIV_1 /*!< Synchro Signal divided by 4 */
  74. #define LL_CRS_SYNC_DIV_8 (CRS_CFGR_SYNCDIV_1 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 8 */
  75. #define LL_CRS_SYNC_DIV_16 CRS_CFGR_SYNCDIV_2 /*!< Synchro Signal divided by 16 */
  76. #define LL_CRS_SYNC_DIV_32 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_0) /*!< Synchro Signal divided by 32 */
  77. #define LL_CRS_SYNC_DIV_64 (CRS_CFGR_SYNCDIV_2 | CRS_CFGR_SYNCDIV_1) /*!< Synchro Signal divided by 64 */
  78. #define LL_CRS_SYNC_DIV_128 CRS_CFGR_SYNCDIV /*!< Synchro Signal divided by 128 */
  79. /**
  80. * @}
  81. */
  82. /** @defgroup CRS_LL_EC_SYNC_SOURCE Synchronization Signal Source
  83. * @{
  84. */
  85. #define LL_CRS_SYNC_SOURCE_GPIO 0x00000000U /*!< Synchro Signal soucre GPIO */
  86. #define LL_CRS_SYNC_SOURCE_LSE CRS_CFGR_SYNCSRC_0 /*!< Synchro Signal source LSE */
  87. #define LL_CRS_SYNC_SOURCE_USB CRS_CFGR_SYNCSRC_1 /*!< Synchro Signal source USB SOF (default)*/
  88. /**
  89. * @}
  90. */
  91. /** @defgroup CRS_LL_EC_SYNC_POLARITY Synchronization Signal Polarity
  92. * @{
  93. */
  94. #define LL_CRS_SYNC_POLARITY_RISING 0x00000000U /*!< Synchro Active on rising edge (default) */
  95. #define LL_CRS_SYNC_POLARITY_FALLING CRS_CFGR_SYNCPOL /*!< Synchro Active on falling edge */
  96. /**
  97. * @}
  98. */
  99. /** @defgroup CRS_LL_EC_FREQERRORDIR Frequency Error Direction
  100. * @{
  101. */
  102. #define LL_CRS_FREQ_ERROR_DIR_UP 0x00000000U /*!< Upcounting direction, the actual frequency is above the target */
  103. #define LL_CRS_FREQ_ERROR_DIR_DOWN CRS_ISR_FEDIR /*!< Downcounting direction, the actual frequency is below the target */
  104. /**
  105. * @}
  106. */
  107. /** @defgroup CRS_LL_EC_DEFAULTVALUES Default Values
  108. * @{
  109. */
  110. /**
  111. * @brief Reset value of the RELOAD field
  112. * @note The reset value of the RELOAD field corresponds to a target frequency of 48 MHz
  113. * and a synchronization signal frequency of 1 kHz (SOF signal from USB)
  114. */
  115. #define LL_CRS_RELOADVALUE_DEFAULT 0x0000BB7FU
  116. /**
  117. * @brief Reset value of Frequency error limit.
  118. */
  119. #define LL_CRS_ERRORLIMIT_DEFAULT 0x00000022U
  120. /**
  121. * @brief Reset value of the HSI48 Calibration field
  122. * @note The default value is 64, which corresponds to the middle of the trimming interval.
  123. * The trimming step is specified in the product datasheet.
  124. * A higher TRIM value corresponds to a higher output frequency.
  125. */
  126. #define LL_CRS_HSI48CALIBRATION_DEFAULT 0x00000020U
  127. /**
  128. * @}
  129. */
  130. /**
  131. * @}
  132. */
  133. /* Exported macro ------------------------------------------------------------*/
  134. /** @defgroup CRS_LL_Exported_Macros CRS Exported Macros
  135. * @{
  136. */
  137. /** @defgroup CRS_LL_EM_WRITE_READ Common Write and read registers Macros
  138. * @{
  139. */
  140. /**
  141. * @brief Write a value in CRS register
  142. * @param __INSTANCE__ CRS Instance
  143. * @param __REG__ Register to be written
  144. * @param __VALUE__ Value to be written in the register
  145. * @retval None
  146. */
  147. #define LL_CRS_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  148. /**
  149. * @brief Read a value in CRS register
  150. * @param __INSTANCE__ CRS Instance
  151. * @param __REG__ Register to be read
  152. * @retval Register value
  153. */
  154. #define LL_CRS_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  155. /**
  156. * @}
  157. */
  158. /** @defgroup CRS_LL_EM_Exported_Macros_Calculate_Reload Exported_Macros_Calculate_Reload
  159. * @{
  160. */
  161. /**
  162. * @brief Macro to calculate reload value to be set in CRS register according to target and sync frequencies
  163. * @note The RELOAD value should be selected according to the ratio between
  164. * the target frequency and the frequency of the synchronization source after
  165. * prescaling. It is then decreased by one in order to reach the expected
  166. * synchronization on the zero value. The formula is the following:
  167. * RELOAD = (fTARGET / fSYNC) -1
  168. * @param __FTARGET__ Target frequency (value in Hz)
  169. * @param __FSYNC__ Synchronization signal frequency (value in Hz)
  170. * @retval Reload value (in Hz)
  171. */
  172. #define __LL_CRS_CALC_CALCULATE_RELOADVALUE(__FTARGET__, __FSYNC__) (((__FTARGET__) / (__FSYNC__)) - 1U)
  173. /**
  174. * @}
  175. */
  176. /**
  177. * @}
  178. */
  179. /* Exported functions --------------------------------------------------------*/
  180. /** @defgroup CRS_LL_Exported_Functions CRS Exported Functions
  181. * @{
  182. */
  183. /** @defgroup CRS_LL_EF_Configuration Configuration
  184. * @{
  185. */
  186. /**
  187. * @brief Enable Frequency error counter
  188. * @note When this bit is set, the CRS_CFGR register is write-protected and cannot be modified
  189. * @rmtoll CR CEN LL_CRS_EnableFreqErrorCounter
  190. * @retval None
  191. */
  192. __STATIC_INLINE void LL_CRS_EnableFreqErrorCounter(void)
  193. {
  194. SET_BIT(CRS->CR, CRS_CR_CEN);
  195. }
  196. /**
  197. * @brief Disable Frequency error counter
  198. * @rmtoll CR CEN LL_CRS_DisableFreqErrorCounter
  199. * @retval None
  200. */
  201. __STATIC_INLINE void LL_CRS_DisableFreqErrorCounter(void)
  202. {
  203. CLEAR_BIT(CRS->CR, CRS_CR_CEN);
  204. }
  205. /**
  206. * @brief Check if Frequency error counter is enabled or not
  207. * @rmtoll CR CEN LL_CRS_IsEnabledFreqErrorCounter
  208. * @retval State of bit (1 or 0).
  209. */
  210. __STATIC_INLINE uint32_t LL_CRS_IsEnabledFreqErrorCounter(void)
  211. {
  212. return ((READ_BIT(CRS->CR, CRS_CR_CEN) == (CRS_CR_CEN)) ? 1UL : 0UL);
  213. }
  214. /**
  215. * @brief Enable Automatic trimming counter
  216. * @rmtoll CR AUTOTRIMEN LL_CRS_EnableAutoTrimming
  217. * @retval None
  218. */
  219. __STATIC_INLINE void LL_CRS_EnableAutoTrimming(void)
  220. {
  221. SET_BIT(CRS->CR, CRS_CR_AUTOTRIMEN);
  222. }
  223. /**
  224. * @brief Disable Automatic trimming counter
  225. * @rmtoll CR AUTOTRIMEN LL_CRS_DisableAutoTrimming
  226. * @retval None
  227. */
  228. __STATIC_INLINE void LL_CRS_DisableAutoTrimming(void)
  229. {
  230. CLEAR_BIT(CRS->CR, CRS_CR_AUTOTRIMEN);
  231. }
  232. /**
  233. * @brief Check if Automatic trimming is enabled or not
  234. * @rmtoll CR AUTOTRIMEN LL_CRS_IsEnabledAutoTrimming
  235. * @retval State of bit (1 or 0).
  236. */
  237. __STATIC_INLINE uint32_t LL_CRS_IsEnabledAutoTrimming(void)
  238. {
  239. return ((READ_BIT(CRS->CR, CRS_CR_AUTOTRIMEN) == (CRS_CR_AUTOTRIMEN)) ? 1UL : 0UL);
  240. }
  241. /**
  242. * @brief Set HSI48 oscillator smooth trimming
  243. * @note When the AUTOTRIMEN bit is set, this field is controlled by hardware and is read-only
  244. * @rmtoll CR TRIM LL_CRS_SetHSI48SmoothTrimming
  245. * @param Value a number between Min_Data = 0 and Max_Data = 127
  246. * @note Default value can be set thanks to @ref LL_CRS_HSI48CALIBRATION_DEFAULT
  247. * @retval None
  248. */
  249. __STATIC_INLINE void LL_CRS_SetHSI48SmoothTrimming(uint32_t Value)
  250. {
  251. MODIFY_REG(CRS->CR, CRS_CR_TRIM, Value << CRS_CR_TRIM_Pos);
  252. }
  253. /**
  254. * @brief Get HSI48 oscillator smooth trimming
  255. * @rmtoll CR TRIM LL_CRS_GetHSI48SmoothTrimming
  256. * @retval a number between Min_Data = 0 and Max_Data = 127
  257. */
  258. __STATIC_INLINE uint32_t LL_CRS_GetHSI48SmoothTrimming(void)
  259. {
  260. return (uint32_t)(READ_BIT(CRS->CR, CRS_CR_TRIM) >> CRS_CR_TRIM_Pos);
  261. }
  262. /**
  263. * @brief Set counter reload value
  264. * @rmtoll CFGR RELOAD LL_CRS_SetReloadCounter
  265. * @param Value a number between Min_Data = 0 and Max_Data = 0xFFFF
  266. * @note Default value can be set thanks to @ref LL_CRS_RELOADVALUE_DEFAULT
  267. * Otherwise it can be calculated in using macro @ref __LL_CRS_CALC_CALCULATE_RELOADVALUE (_FTARGET_, _FSYNC_)
  268. * @retval None
  269. */
  270. __STATIC_INLINE void LL_CRS_SetReloadCounter(uint32_t Value)
  271. {
  272. MODIFY_REG(CRS->CFGR, CRS_CFGR_RELOAD, Value);
  273. }
  274. /**
  275. * @brief Get counter reload value
  276. * @rmtoll CFGR RELOAD LL_CRS_GetReloadCounter
  277. * @retval a number between Min_Data = 0 and Max_Data = 0xFFFF
  278. */
  279. __STATIC_INLINE uint32_t LL_CRS_GetReloadCounter(void)
  280. {
  281. return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_RELOAD));
  282. }
  283. /**
  284. * @brief Set frequency error limit
  285. * @rmtoll CFGR FELIM LL_CRS_SetFreqErrorLimit
  286. * @param Value a number between Min_Data = 0 and Max_Data = 255
  287. * @note Default value can be set thanks to @ref LL_CRS_ERRORLIMIT_DEFAULT
  288. * @retval None
  289. */
  290. __STATIC_INLINE void LL_CRS_SetFreqErrorLimit(uint32_t Value)
  291. {
  292. MODIFY_REG(CRS->CFGR, CRS_CFGR_FELIM, Value << CRS_CFGR_FELIM_Pos);
  293. }
  294. /**
  295. * @brief Get frequency error limit
  296. * @rmtoll CFGR FELIM LL_CRS_GetFreqErrorLimit
  297. * @retval A number between Min_Data = 0 and Max_Data = 255
  298. */
  299. __STATIC_INLINE uint32_t LL_CRS_GetFreqErrorLimit(void)
  300. {
  301. return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_FELIM) >> CRS_CFGR_FELIM_Pos);
  302. }
  303. /**
  304. * @brief Set division factor for SYNC signal
  305. * @rmtoll CFGR SYNCDIV LL_CRS_SetSyncDivider
  306. * @param Divider This parameter can be one of the following values:
  307. * @arg @ref LL_CRS_SYNC_DIV_1
  308. * @arg @ref LL_CRS_SYNC_DIV_2
  309. * @arg @ref LL_CRS_SYNC_DIV_4
  310. * @arg @ref LL_CRS_SYNC_DIV_8
  311. * @arg @ref LL_CRS_SYNC_DIV_16
  312. * @arg @ref LL_CRS_SYNC_DIV_32
  313. * @arg @ref LL_CRS_SYNC_DIV_64
  314. * @arg @ref LL_CRS_SYNC_DIV_128
  315. * @retval None
  316. */
  317. __STATIC_INLINE void LL_CRS_SetSyncDivider(uint32_t Divider)
  318. {
  319. MODIFY_REG(CRS->CFGR, CRS_CFGR_SYNCDIV, Divider);
  320. }
  321. /**
  322. * @brief Get division factor for SYNC signal
  323. * @rmtoll CFGR SYNCDIV LL_CRS_GetSyncDivider
  324. * @retval Returned value can be one of the following values:
  325. * @arg @ref LL_CRS_SYNC_DIV_1
  326. * @arg @ref LL_CRS_SYNC_DIV_2
  327. * @arg @ref LL_CRS_SYNC_DIV_4
  328. * @arg @ref LL_CRS_SYNC_DIV_8
  329. * @arg @ref LL_CRS_SYNC_DIV_16
  330. * @arg @ref LL_CRS_SYNC_DIV_32
  331. * @arg @ref LL_CRS_SYNC_DIV_64
  332. * @arg @ref LL_CRS_SYNC_DIV_128
  333. */
  334. __STATIC_INLINE uint32_t LL_CRS_GetSyncDivider(void)
  335. {
  336. return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_SYNCDIV));
  337. }
  338. /**
  339. * @brief Set SYNC signal source
  340. * @rmtoll CFGR SYNCSRC LL_CRS_SetSyncSignalSource
  341. * @param Source This parameter can be one of the following values:
  342. * @arg @ref LL_CRS_SYNC_SOURCE_GPIO
  343. * @arg @ref LL_CRS_SYNC_SOURCE_LSE
  344. * @arg @ref LL_CRS_SYNC_SOURCE_USB
  345. * @retval None
  346. */
  347. __STATIC_INLINE void LL_CRS_SetSyncSignalSource(uint32_t Source)
  348. {
  349. MODIFY_REG(CRS->CFGR, CRS_CFGR_SYNCSRC, Source);
  350. }
  351. /**
  352. * @brief Get SYNC signal source
  353. * @rmtoll CFGR SYNCSRC LL_CRS_GetSyncSignalSource
  354. * @retval Returned value can be one of the following values:
  355. * @arg @ref LL_CRS_SYNC_SOURCE_GPIO
  356. * @arg @ref LL_CRS_SYNC_SOURCE_LSE
  357. * @arg @ref LL_CRS_SYNC_SOURCE_USB
  358. */
  359. __STATIC_INLINE uint32_t LL_CRS_GetSyncSignalSource(void)
  360. {
  361. return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_SYNCSRC));
  362. }
  363. /**
  364. * @brief Set input polarity for the SYNC signal source
  365. * @rmtoll CFGR SYNCPOL LL_CRS_SetSyncPolarity
  366. * @param Polarity This parameter can be one of the following values:
  367. * @arg @ref LL_CRS_SYNC_POLARITY_RISING
  368. * @arg @ref LL_CRS_SYNC_POLARITY_FALLING
  369. * @retval None
  370. */
  371. __STATIC_INLINE void LL_CRS_SetSyncPolarity(uint32_t Polarity)
  372. {
  373. MODIFY_REG(CRS->CFGR, CRS_CFGR_SYNCPOL, Polarity);
  374. }
  375. /**
  376. * @brief Get input polarity for the SYNC signal source
  377. * @rmtoll CFGR SYNCPOL LL_CRS_GetSyncPolarity
  378. * @retval Returned value can be one of the following values:
  379. * @arg @ref LL_CRS_SYNC_POLARITY_RISING
  380. * @arg @ref LL_CRS_SYNC_POLARITY_FALLING
  381. */
  382. __STATIC_INLINE uint32_t LL_CRS_GetSyncPolarity(void)
  383. {
  384. return (uint32_t)(READ_BIT(CRS->CFGR, CRS_CFGR_SYNCPOL));
  385. }
  386. /**
  387. * @brief Configure CRS for the synchronization
  388. * @rmtoll CR TRIM LL_CRS_ConfigSynchronization\n
  389. * CFGR RELOAD LL_CRS_ConfigSynchronization\n
  390. * CFGR FELIM LL_CRS_ConfigSynchronization\n
  391. * CFGR SYNCDIV LL_CRS_ConfigSynchronization\n
  392. * CFGR SYNCSRC LL_CRS_ConfigSynchronization\n
  393. * CFGR SYNCPOL LL_CRS_ConfigSynchronization
  394. * @param HSI48CalibrationValue a number between Min_Data = 0 and Max_Data = 63
  395. * @param ErrorLimitValue a number between Min_Data = 0 and Max_Data = 0xFFFF
  396. * @param ReloadValue a number between Min_Data = 0 and Max_Data = 255
  397. * @param Settings This parameter can be a combination of the following values:
  398. * @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
  399. * 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
  400. * @arg @ref LL_CRS_SYNC_SOURCE_GPIO or @ref LL_CRS_SYNC_SOURCE_LSE or @ref LL_CRS_SYNC_SOURCE_USB
  401. * @arg @ref LL_CRS_SYNC_POLARITY_RISING or @ref LL_CRS_SYNC_POLARITY_FALLING
  402. * @retval None
  403. */
  404. __STATIC_INLINE void LL_CRS_ConfigSynchronization(uint32_t HSI48CalibrationValue, uint32_t ErrorLimitValue, 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 /* STM32H7xx_LL_CRS_H */
  693. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/