stm32l4xx_ll_crs.h 26 KB

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