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