stm32l4xx_ll_crs.h 25 KB

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