Merge pull request #11198 from SteveCEvans/sce_rc2
[betaflight.git] / lib / main / STM32F4 / Drivers / STM32F4xx_HAL_Driver / Src / stm32f4xx_ll_rcc.c
blob80c1368a54274edd6e16a40fc86cadbe8b88e2ad
1 /**
2 ******************************************************************************
3 * @file stm32f4xx_ll_rcc.c
4 * @author MCD Application Team
5 * @version V1.7.1
6 * @date 14-April-2017
7 * @brief RCC LL module driver.
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
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.
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.
35 ******************************************************************************
37 #if defined(USE_FULL_LL_DRIVER)
39 /* Includes ------------------------------------------------------------------*/
40 #include "stm32f4xx_ll_rcc.h"
41 #ifdef USE_FULL_ASSERT
42 #include "stm32_assert.h"
43 #else
44 #define assert_param(expr) ((void)0U)
45 #endif
46 /** @addtogroup STM32F4xx_LL_Driver
47 * @{
50 #if defined(RCC)
52 /** @addtogroup RCC_LL
53 * @{
56 /* Private types -------------------------------------------------------------*/
57 /* Private variables ---------------------------------------------------------*/
58 /* Private constants ---------------------------------------------------------*/
59 /* Private macros ------------------------------------------------------------*/
60 /** @addtogroup RCC_LL_Private_Macros
61 * @{
63 #if defined(FMPI2C1)
64 #define IS_LL_RCC_FMPI2C_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_FMPI2C1_CLKSOURCE)
65 #endif /* FMPI2C1 */
67 #if defined(LPTIM1)
68 #define IS_LL_RCC_LPTIM_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LPTIM1_CLKSOURCE))
69 #endif /* LPTIM1 */
71 #if defined(SAI1)
72 #if defined(RCC_DCKCFGR_SAI1SRC)
73 #define IS_LL_RCC_SAI_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_SAI1_CLKSOURCE) \
74 || ((__VALUE__) == LL_RCC_SAI2_CLKSOURCE))
75 #elif defined(RCC_DCKCFGR_SAI1ASRC)
76 #define IS_LL_RCC_SAI_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_SAI1_A_CLKSOURCE) \
77 || ((__VALUE__) == LL_RCC_SAI1_B_CLKSOURCE))
78 #endif /* RCC_DCKCFGR_SAI1SRC */
79 #endif /* SAI1 */
81 #if defined(SDIO)
82 #define IS_LL_RCC_SDIO_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_SDIO_CLKSOURCE))
83 #endif /* SDIO */
85 #if defined(RNG)
86 #define IS_LL_RCC_RNG_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_RNG_CLKSOURCE))
87 #endif /* RNG */
89 #if defined(USB_OTG_FS) || defined(USB_OTG_HS)
90 #define IS_LL_RCC_USB_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USB_CLKSOURCE))
91 #endif /* USB_OTG_FS || USB_OTG_HS */
93 #if defined(DFSDM2_Channel0)
94 #define IS_LL_RCC_DFSDM_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_DFSDM1_CLKSOURCE))
96 #define IS_LL_RCC_DFSDM_AUDIO_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_DFSDM1_AUDIO_CLKSOURCE) \
97 || ((__VALUE__) == LL_RCC_DFSDM2_AUDIO_CLKSOURCE))
98 #elif defined(DFSDM1_Channel0)
99 #define IS_LL_RCC_DFSDM_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_DFSDM1_CLKSOURCE))
101 #define IS_LL_RCC_DFSDM_AUDIO_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_DFSDM1_AUDIO_CLKSOURCE))
102 #endif /* DFSDM2_Channel0 */
104 #if defined(RCC_DCKCFGR_I2S2SRC)
105 #define IS_LL_RCC_I2S_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2S1_CLKSOURCE) \
106 || ((__VALUE__) == LL_RCC_I2S2_CLKSOURCE))
107 #else
108 #define IS_LL_RCC_I2S_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2S1_CLKSOURCE))
109 #endif /* RCC_DCKCFGR_I2S2SRC */
111 #if defined(CEC)
112 #define IS_LL_RCC_CEC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_CEC_CLKSOURCE))
113 #endif /* CEC */
115 #if defined(DSI)
116 #define IS_LL_RCC_DSI_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_DSI_CLKSOURCE))
117 #endif /* DSI */
119 #if defined(LTDC)
120 #define IS_LL_RCC_LTDC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LTDC_CLKSOURCE))
121 #endif /* LTDC */
123 #if defined(SPDIFRX)
124 #define IS_LL_RCC_SPDIFRX_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_SPDIFRX1_CLKSOURCE))
125 #endif /* SPDIFRX */
127 * @}
130 /* Private function prototypes -----------------------------------------------*/
131 /** @defgroup RCC_LL_Private_Functions RCC Private functions
132 * @{
134 uint32_t RCC_GetSystemClockFreq(void);
135 uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency);
136 uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency);
137 uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency);
138 uint32_t RCC_PLL_GetFreqDomain_SYS(uint32_t SYSCLK_Source);
139 uint32_t RCC_PLL_GetFreqDomain_48M(void);
140 #if defined(RCC_DCKCFGR_I2SSRC) || defined(RCC_DCKCFGR_I2S1SRC)
141 uint32_t RCC_PLL_GetFreqDomain_I2S(void);
142 #endif /* RCC_DCKCFGR_I2SSRC || RCC_DCKCFGR_I2S1SRC */
143 #if defined(SPDIFRX)
144 uint32_t RCC_PLL_GetFreqDomain_SPDIFRX(void);
145 #endif /* SPDIFRX */
146 #if defined(RCC_PLLCFGR_PLLR)
147 #if defined(SAI1)
148 uint32_t RCC_PLL_GetFreqDomain_SAI(void);
149 #endif /* SAI1 */
150 #endif /* RCC_PLLCFGR_PLLR */
151 #if defined(DSI)
152 uint32_t RCC_PLL_GetFreqDomain_DSI(void);
153 #endif /* DSI */
154 #if defined(RCC_PLLSAI_SUPPORT)
155 uint32_t RCC_PLLSAI_GetFreqDomain_SAI(void);
156 #if defined(RCC_PLLSAICFGR_PLLSAIP)
157 uint32_t RCC_PLLSAI_GetFreqDomain_48M(void);
158 #endif /* RCC_PLLSAICFGR_PLLSAIP */
159 #if defined(LTDC)
160 uint32_t RCC_PLLSAI_GetFreqDomain_LTDC(void);
161 #endif /* LTDC */
162 #endif /* RCC_PLLSAI_SUPPORT */
163 #if defined(RCC_PLLI2S_SUPPORT)
164 uint32_t RCC_PLLI2S_GetFreqDomain_I2S(void);
165 #if defined(RCC_PLLI2SCFGR_PLLI2SQ) && !defined(RCC_DCKCFGR_PLLI2SDIVQ)
166 uint32_t RCC_PLLI2S_GetFreqDomain_48M(void);
167 #endif /* RCC_PLLI2SCFGR_PLLI2SQ && !RCC_DCKCFGR_PLLI2SDIVQ */
168 #if defined(SAI1)
169 uint32_t RCC_PLLI2S_GetFreqDomain_SAI(void);
170 #endif /* SAI1 */
171 #if defined(SPDIFRX)
172 uint32_t RCC_PLLI2S_GetFreqDomain_SPDIFRX(void);
173 #endif /* SPDIFRX */
174 #endif /* RCC_PLLI2S_SUPPORT */
176 * @}
180 /* Exported functions --------------------------------------------------------*/
181 /** @addtogroup RCC_LL_Exported_Functions
182 * @{
185 /** @addtogroup RCC_LL_EF_Init
186 * @{
190 * @brief Reset the RCC clock configuration to the default reset state.
191 * @note The default reset state of the clock configuration is given below:
192 * - HSI ON and used as system clock source
193 * - HSE and PLL OFF
194 * - AHB, APB1 and APB2 prescaler set to 1.
195 * - CSS, MCO OFF
196 * - All interrupts disabled
197 * @note This function doesn't modify the configuration of the
198 * - Peripheral clocks
199 * - LSI, LSE and RTC clocks
200 * @retval An ErrorStatus enumeration value:
201 * - SUCCESS: RCC registers are de-initialized
202 * - ERROR: not applicable
204 ErrorStatus LL_RCC_DeInit(void)
206 uint32_t vl_mask = 0U;
208 /* Set HSION bit */
209 LL_RCC_HSI_Enable();
211 /* Reset CFGR register */
212 LL_RCC_WriteReg(CFGR, 0x00000000U);
214 vl_mask = 0xFFFFFFFFU;
216 /* Reset HSEON, PLLSYSON bits */
217 CLEAR_BIT(vl_mask, (RCC_CR_HSEON | RCC_CR_HSEBYP | RCC_CR_PLLON | RCC_CR_CSSON));
219 #if defined(RCC_PLLSAI_SUPPORT)
220 /* Reset PLLSAION bit */
221 CLEAR_BIT(vl_mask, RCC_CR_PLLSAION);
222 #endif /* RCC_PLLSAI_SUPPORT */
224 #if defined(RCC_PLLI2S_SUPPORT)
225 /* Reset PLLI2SON bit */
226 CLEAR_BIT(vl_mask, RCC_CR_PLLI2SON);
227 #endif /* RCC_PLLI2S_SUPPORT */
229 /* Write new mask in CR register */
230 LL_RCC_WriteReg(CR, vl_mask);
232 /* Set HSITRIM bits to the reset value*/
233 LL_RCC_HSI_SetCalibTrimming(0x10U);
235 /* Reset PLLCFGR register */
236 LL_RCC_WriteReg(PLLCFGR, RCC_PLLCFGR_RST_VALUE);
238 #if defined(RCC_PLLI2S_SUPPORT)
239 /* Reset PLLI2SCFGR register */
240 LL_RCC_WriteReg(PLLI2SCFGR, RCC_PLLI2SCFGR_RST_VALUE);
241 #endif /* RCC_PLLI2S_SUPPORT */
243 #if defined(RCC_PLLSAI_SUPPORT)
244 /* Reset PLLSAICFGR register */
245 LL_RCC_WriteReg(PLLSAICFGR, RCC_PLLSAICFGR_RST_VALUE);
246 #endif /* RCC_PLLSAI_SUPPORT */
248 /* Reset HSEBYP bit */
249 LL_RCC_HSE_DisableBypass();
251 /* Disable all interrupts */
252 LL_RCC_WriteReg(CIR, 0x00000000U);
254 return SUCCESS;
258 * @}
261 /** @addtogroup RCC_LL_EF_Get_Freq
262 * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks
263 * and different peripheral clocks available on the device.
264 * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(**)
265 * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(***)
266 * @note If SYSCLK source is PLL, function returns values based on HSE_VALUE(***)
267 * or HSI_VALUE(**) multiplied/divided by the PLL factors.
268 * @note (**) HSI_VALUE is a constant defined in this file (default value
269 * 16 MHz) but the real value may vary depending on the variations
270 * in voltage and temperature.
271 * @note (***) HSE_VALUE is a constant defined in this file (default value
272 * 25 MHz), user has to ensure that HSE_VALUE is same as the real
273 * frequency of the crystal used. Otherwise, this function may
274 * have wrong result.
275 * @note The result of this function could be incorrect when using fractional
276 * value for HSE crystal.
277 * @note This function can be used by the user application to compute the
278 * baud-rate for the communication peripherals or configure other parameters.
279 * @{
283 * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks
284 * @note Each time SYSCLK, HCLK, PCLK1 and/or PCLK2 clock changes, this function
285 * must be called to update structure fields. Otherwise, any
286 * configuration based on this function will be incorrect.
287 * @param RCC_Clocks pointer to a @ref LL_RCC_ClocksTypeDef structure which will hold the clocks frequencies
288 * @retval None
290 void LL_RCC_GetSystemClocksFreq(LL_RCC_ClocksTypeDef *RCC_Clocks)
292 /* Get SYSCLK frequency */
293 RCC_Clocks->SYSCLK_Frequency = RCC_GetSystemClockFreq();
295 /* HCLK clock frequency */
296 RCC_Clocks->HCLK_Frequency = RCC_GetHCLKClockFreq(RCC_Clocks->SYSCLK_Frequency);
298 /* PCLK1 clock frequency */
299 RCC_Clocks->PCLK1_Frequency = RCC_GetPCLK1ClockFreq(RCC_Clocks->HCLK_Frequency);
301 /* PCLK2 clock frequency */
302 RCC_Clocks->PCLK2_Frequency = RCC_GetPCLK2ClockFreq(RCC_Clocks->HCLK_Frequency);
305 #if defined(FMPI2C1)
307 * @brief Return FMPI2Cx clock frequency
308 * @param FMPI2CxSource This parameter can be one of the following values:
309 * @arg @ref LL_RCC_FMPI2C1_CLKSOURCE
310 * @retval FMPI2C clock frequency (in Hz)
311 * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that HSI oscillator is not ready
313 uint32_t LL_RCC_GetFMPI2CClockFreq(uint32_t FMPI2CxSource)
315 uint32_t FMPI2C_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
317 /* Check parameter */
318 assert_param(IS_LL_RCC_FMPI2C_CLKSOURCE(FMPI2CxSource));
320 if (FMPI2CxSource == LL_RCC_FMPI2C1_CLKSOURCE)
322 /* FMPI2C1 CLK clock frequency */
323 switch (LL_RCC_GetFMPI2CClockSource(FMPI2CxSource))
325 case LL_RCC_FMPI2C1_CLKSOURCE_SYSCLK: /* FMPI2C1 Clock is System Clock */
326 FMPI2C_frequency = RCC_GetSystemClockFreq();
327 break;
329 case LL_RCC_FMPI2C1_CLKSOURCE_HSI: /* FMPI2C1 Clock is HSI Osc. */
330 if (LL_RCC_HSI_IsReady())
332 FMPI2C_frequency = HSI_VALUE;
334 break;
336 case LL_RCC_FMPI2C1_CLKSOURCE_PCLK1: /* FMPI2C1 Clock is PCLK1 */
337 default:
338 FMPI2C_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
339 break;
343 return FMPI2C_frequency;
345 #endif /* FMPI2C1 */
348 * @brief Return I2Sx clock frequency
349 * @param I2SxSource This parameter can be one of the following values:
350 * @arg @ref LL_RCC_I2S1_CLKSOURCE
351 * @arg @ref LL_RCC_I2S2_CLKSOURCE (*)
353 * (*) value not defined in all devices.
354 * @retval I2S clock frequency (in Hz)
355 * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready
357 uint32_t LL_RCC_GetI2SClockFreq(uint32_t I2SxSource)
359 uint32_t i2s_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
361 /* Check parameter */
362 assert_param(IS_LL_RCC_I2S_CLKSOURCE(I2SxSource));
364 if (I2SxSource == LL_RCC_I2S1_CLKSOURCE)
366 /* I2S1 CLK clock frequency */
367 switch (LL_RCC_GetI2SClockSource(I2SxSource))
369 #if defined(RCC_PLLI2S_SUPPORT)
370 case LL_RCC_I2S1_CLKSOURCE_PLLI2S: /* I2S1 Clock is PLLI2S */
371 if (LL_RCC_PLLI2S_IsReady())
373 i2s_frequency = RCC_PLLI2S_GetFreqDomain_I2S();
375 break;
376 #endif /* RCC_PLLI2S_SUPPORT */
378 #if defined(RCC_DCKCFGR_I2SSRC) || defined(RCC_DCKCFGR_I2S1SRC)
379 case LL_RCC_I2S1_CLKSOURCE_PLL: /* I2S1 Clock is PLL */
380 if (LL_RCC_PLL_IsReady())
382 i2s_frequency = RCC_PLL_GetFreqDomain_I2S();
384 break;
386 case LL_RCC_I2S1_CLKSOURCE_PLLSRC: /* I2S1 Clock is PLL Main source */
387 switch (LL_RCC_PLL_GetMainSource())
389 case LL_RCC_PLLSOURCE_HSE: /* I2S1 Clock is HSE Osc. */
390 if (LL_RCC_HSE_IsReady())
392 i2s_frequency = HSE_VALUE;
394 break;
396 case LL_RCC_PLLSOURCE_HSI: /* I2S1 Clock is HSI Osc. */
397 default:
398 if (LL_RCC_HSI_IsReady())
400 i2s_frequency = HSI_VALUE;
402 break;
404 break;
405 #endif /* RCC_DCKCFGR_I2SSRC || RCC_DCKCFGR_I2S1SRC */
407 case LL_RCC_I2S1_CLKSOURCE_PIN: /* I2S1 Clock is External clock */
408 default:
409 i2s_frequency = EXTERNAL_CLOCK_VALUE;
410 break;
413 #if defined(RCC_DCKCFGR_I2S2SRC)
414 else
416 /* I2S2 CLK clock frequency */
417 switch (LL_RCC_GetI2SClockSource(I2SxSource))
419 case LL_RCC_I2S2_CLKSOURCE_PLLI2S: /* I2S2 Clock is PLLI2S */
420 if (LL_RCC_PLLI2S_IsReady())
422 i2s_frequency = RCC_PLLI2S_GetFreqDomain_I2S();
424 break;
426 case LL_RCC_I2S2_CLKSOURCE_PLL: /* I2S2 Clock is PLL */
427 if (LL_RCC_PLL_IsReady())
429 i2s_frequency = RCC_PLL_GetFreqDomain_I2S();
431 break;
433 case LL_RCC_I2S2_CLKSOURCE_PLLSRC: /* I2S2 Clock is PLL Main source */
434 switch (LL_RCC_PLL_GetMainSource())
436 case LL_RCC_PLLSOURCE_HSE: /* I2S2 Clock is HSE Osc. */
437 if (LL_RCC_HSE_IsReady())
439 i2s_frequency = HSE_VALUE;
441 break;
443 case LL_RCC_PLLSOURCE_HSI: /* I2S2 Clock is HSI Osc. */
444 default:
445 if (LL_RCC_HSI_IsReady())
447 i2s_frequency = HSI_VALUE;
449 break;
451 break;
453 case LL_RCC_I2S2_CLKSOURCE_PIN: /* I2S2 Clock is External clock */
454 default:
455 i2s_frequency = EXTERNAL_CLOCK_VALUE;
456 break;
459 #endif /* RCC_DCKCFGR_I2S2SRC */
461 return i2s_frequency;
464 #if defined(LPTIM1)
466 * @brief Return LPTIMx clock frequency
467 * @param LPTIMxSource This parameter can be one of the following values:
468 * @arg @ref LL_RCC_LPTIM1_CLKSOURCE
469 * @retval LPTIM clock frequency (in Hz)
470 * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI, LSI or LSE) is not ready
472 uint32_t LL_RCC_GetLPTIMClockFreq(uint32_t LPTIMxSource)
474 uint32_t lptim_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
476 /* Check parameter */
477 assert_param(IS_LL_RCC_LPTIM_CLKSOURCE(LPTIMxSource));
479 if (LPTIMxSource == LL_RCC_LPTIM1_CLKSOURCE)
481 /* LPTIM1CLK clock frequency */
482 switch (LL_RCC_GetLPTIMClockSource(LPTIMxSource))
484 case LL_RCC_LPTIM1_CLKSOURCE_LSI: /* LPTIM1 Clock is LSI Osc. */
485 if (LL_RCC_LSI_IsReady())
487 lptim_frequency = LSI_VALUE;
489 break;
491 case LL_RCC_LPTIM1_CLKSOURCE_HSI: /* LPTIM1 Clock is HSI Osc. */
492 if (LL_RCC_HSI_IsReady())
494 lptim_frequency = HSI_VALUE;
496 break;
498 case LL_RCC_LPTIM1_CLKSOURCE_LSE: /* LPTIM1 Clock is LSE Osc. */
499 if (LL_RCC_LSE_IsReady())
501 lptim_frequency = LSE_VALUE;
503 break;
505 case LL_RCC_LPTIM1_CLKSOURCE_PCLK1: /* LPTIM1 Clock is PCLK1 */
506 default:
507 lptim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
508 break;
512 return lptim_frequency;
514 #endif /* LPTIM1 */
516 #if defined(SAI1)
518 * @brief Return SAIx clock frequency
519 * @param SAIxSource This parameter can be one of the following values:
520 * @arg @ref LL_RCC_SAI1_CLKSOURCE (*)
521 * @arg @ref LL_RCC_SAI2_CLKSOURCE (*)
522 * @arg @ref LL_RCC_SAI1_A_CLKSOURCE (*)
523 * @arg @ref LL_RCC_SAI1_B_CLKSOURCE (*)
525 * (*) value not defined in all devices.
526 * @retval SAI clock frequency (in Hz)
527 * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready
529 uint32_t LL_RCC_GetSAIClockFreq(uint32_t SAIxSource)
531 uint32_t sai_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
533 /* Check parameter */
534 assert_param(IS_LL_RCC_SAI_CLKSOURCE(SAIxSource));
536 #if defined(RCC_DCKCFGR_SAI1SRC)
537 if ((SAIxSource == LL_RCC_SAI1_CLKSOURCE) || (SAIxSource == LL_RCC_SAI2_CLKSOURCE))
539 /* SAI1CLK clock frequency */
540 switch (LL_RCC_GetSAIClockSource(SAIxSource))
542 case LL_RCC_SAI1_CLKSOURCE_PLLSAI: /* PLLSAI clock used as SAI1 clock source */
543 case LL_RCC_SAI2_CLKSOURCE_PLLSAI: /* PLLSAI clock used as SAI2 clock source */
544 if (LL_RCC_PLLSAI_IsReady())
546 sai_frequency = RCC_PLLSAI_GetFreqDomain_SAI();
548 break;
550 case LL_RCC_SAI1_CLKSOURCE_PLLI2S: /* PLLI2S clock used as SAI1 clock source */
551 case LL_RCC_SAI2_CLKSOURCE_PLLI2S: /* PLLI2S clock used as SAI2 clock source */
552 if (LL_RCC_PLLI2S_IsReady())
554 sai_frequency = RCC_PLLI2S_GetFreqDomain_SAI();
556 break;
558 case LL_RCC_SAI1_CLKSOURCE_PLL: /* PLL clock used as SAI1 clock source */
559 case LL_RCC_SAI2_CLKSOURCE_PLL: /* PLL clock used as SAI2 clock source */
560 if (LL_RCC_PLL_IsReady())
562 sai_frequency = RCC_PLL_GetFreqDomain_SAI();
564 break;
566 case LL_RCC_SAI2_CLKSOURCE_PLLSRC:
567 switch (LL_RCC_PLL_GetMainSource())
569 case LL_RCC_PLLSOURCE_HSE: /* HSE clock used as SAI2 clock source */
570 if (LL_RCC_HSE_IsReady())
572 sai_frequency = HSE_VALUE;
574 break;
576 case LL_RCC_PLLSOURCE_HSI: /* HSI clock used as SAI2 clock source */
577 default:
578 if (LL_RCC_HSI_IsReady())
580 sai_frequency = HSI_VALUE;
582 break;
584 break;
586 case LL_RCC_SAI1_CLKSOURCE_PIN: /* External input clock used as SAI1 clock source */
587 default:
588 sai_frequency = EXTERNAL_CLOCK_VALUE;
589 break;
592 #endif /* RCC_DCKCFGR_SAI1SRC */
593 #if defined(RCC_DCKCFGR_SAI1ASRC)
594 if ((SAIxSource == LL_RCC_SAI1_A_CLKSOURCE) || (SAIxSource == LL_RCC_SAI1_B_CLKSOURCE))
596 /* SAI1CLK clock frequency */
597 switch (LL_RCC_GetSAIClockSource(SAIxSource))
599 #if defined(RCC_PLLSAI_SUPPORT)
600 case LL_RCC_SAI1_A_CLKSOURCE_PLLSAI: /* PLLSAI clock used as SAI1 Block A clock source */
601 case LL_RCC_SAI1_B_CLKSOURCE_PLLSAI: /* PLLSAI clock used as SAI1 Block B clock source */
602 if (LL_RCC_PLLSAI_IsReady())
604 sai_frequency = RCC_PLLSAI_GetFreqDomain_SAI();
606 break;
607 #endif /* RCC_PLLSAI_SUPPORT */
609 case LL_RCC_SAI1_A_CLKSOURCE_PLLI2S: /* PLLI2S clock used as SAI1 Block A clock source */
610 case LL_RCC_SAI1_B_CLKSOURCE_PLLI2S: /* PLLI2S clock used as SAI1 Block B clock source */
611 if (LL_RCC_PLLI2S_IsReady())
613 sai_frequency = RCC_PLLI2S_GetFreqDomain_SAI();
615 break;
617 #if defined(RCC_SAI1A_PLLSOURCE_SUPPORT)
618 case LL_RCC_SAI1_A_CLKSOURCE_PLL: /* PLL clock used as SAI1 Block A clock source */
619 case LL_RCC_SAI1_B_CLKSOURCE_PLL: /* PLL clock used as SAI1 Block B clock source */
620 if (LL_RCC_PLL_IsReady())
622 sai_frequency = RCC_PLL_GetFreqDomain_SAI();
624 break;
626 case LL_RCC_SAI1_A_CLKSOURCE_PLLSRC:
627 case LL_RCC_SAI1_B_CLKSOURCE_PLLSRC:
628 switch (LL_RCC_PLL_GetMainSource())
630 case LL_RCC_PLLSOURCE_HSE: /* HSE clock used as SAI1 Block A or B clock source */
631 if (LL_RCC_HSE_IsReady())
633 sai_frequency = HSE_VALUE;
635 break;
637 case LL_RCC_PLLSOURCE_HSI: /* HSI clock used as SAI1 Block A or B clock source */
638 default:
639 if (LL_RCC_HSI_IsReady())
641 sai_frequency = HSI_VALUE;
643 break;
645 break;
646 #endif /* RCC_SAI1A_PLLSOURCE_SUPPORT */
648 case LL_RCC_SAI1_A_CLKSOURCE_PIN: /* External input clock used as SAI1 Block A clock source */
649 case LL_RCC_SAI1_B_CLKSOURCE_PIN: /* External input clock used as SAI1 Block B clock source */
650 default:
651 sai_frequency = EXTERNAL_CLOCK_VALUE;
652 break;
655 #endif /* RCC_DCKCFGR_SAI1ASRC */
657 return sai_frequency;
659 #endif /* SAI1 */
661 #if defined(SDIO)
663 * @brief Return SDIOx clock frequency
664 * @param SDIOxSource This parameter can be one of the following values:
665 * @arg @ref LL_RCC_SDIO_CLKSOURCE
666 * @retval SDIO clock frequency (in Hz)
667 * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready
669 uint32_t LL_RCC_GetSDIOClockFreq(uint32_t SDIOxSource)
671 uint32_t SDIO_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
673 /* Check parameter */
674 assert_param(IS_LL_RCC_SDIO_CLKSOURCE(SDIOxSource));
676 if (SDIOxSource == LL_RCC_SDIO_CLKSOURCE)
678 #if defined(RCC_DCKCFGR_SDIOSEL) || defined(RCC_DCKCFGR2_SDIOSEL)
679 /* SDIOCLK clock frequency */
680 switch (LL_RCC_GetSDIOClockSource(SDIOxSource))
682 case LL_RCC_SDIO_CLKSOURCE_PLL48CLK: /* PLL48M clock used as SDIO clock source */
683 switch (LL_RCC_GetCK48MClockSource(LL_RCC_CK48M_CLKSOURCE))
685 case LL_RCC_CK48M_CLKSOURCE_PLL: /* PLL clock used as 48Mhz domain clock */
686 if (LL_RCC_PLL_IsReady())
688 SDIO_frequency = RCC_PLL_GetFreqDomain_48M();
690 break;
692 #if defined(RCC_PLLSAI_SUPPORT)
693 case LL_RCC_CK48M_CLKSOURCE_PLLSAI: /* PLLSAI clock used as 48Mhz domain clock */
694 default:
695 if (LL_RCC_PLLSAI_IsReady())
697 SDIO_frequency = RCC_PLLSAI_GetFreqDomain_48M();
699 break;
700 #endif /* RCC_PLLSAI_SUPPORT */
702 #if defined(RCC_PLLI2SCFGR_PLLI2SQ) && !defined(RCC_DCKCFGR_PLLI2SDIVQ)
703 case LL_RCC_CK48M_CLKSOURCE_PLLI2S: /* PLLI2S clock used as 48Mhz domain clock */
704 default:
705 if (LL_RCC_PLLI2S_IsReady())
707 SDIO_frequency = RCC_PLLI2S_GetFreqDomain_48M();
709 break;
710 #endif /* RCC_PLLI2SCFGR_PLLI2SQ && !RCC_DCKCFGR_PLLI2SDIVQ */
712 break;
714 case LL_RCC_SDIO_CLKSOURCE_SYSCLK: /* PLL clock used as SDIO clock source */
715 default:
716 SDIO_frequency = RCC_GetSystemClockFreq();
717 break;
719 #else
720 /* PLL clock used as 48Mhz domain clock */
721 if (LL_RCC_PLL_IsReady())
723 SDIO_frequency = RCC_PLL_GetFreqDomain_48M();
725 #endif /* RCC_DCKCFGR_SDIOSEL || RCC_DCKCFGR2_SDIOSEL */
728 return SDIO_frequency;
730 #endif /* SDIO */
732 #if defined(RNG)
734 * @brief Return RNGx clock frequency
735 * @param RNGxSource This parameter can be one of the following values:
736 * @arg @ref LL_RCC_RNG_CLKSOURCE
737 * @retval RNG clock frequency (in Hz)
738 * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready
740 uint32_t LL_RCC_GetRNGClockFreq(uint32_t RNGxSource)
742 uint32_t rng_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
744 /* Check parameter */
745 assert_param(IS_LL_RCC_RNG_CLKSOURCE(RNGxSource));
747 #if defined(RCC_DCKCFGR_CK48MSEL) || defined(RCC_DCKCFGR2_CK48MSEL)
748 /* RNGCLK clock frequency */
749 switch (LL_RCC_GetRNGClockSource(RNGxSource))
751 #if defined(RCC_PLLI2SCFGR_PLLI2SQ) && !defined(RCC_DCKCFGR_PLLI2SDIVQ)
752 case LL_RCC_RNG_CLKSOURCE_PLLI2S: /* PLLI2S clock used as RNG clock source */
753 if (LL_RCC_PLLI2S_IsReady())
755 rng_frequency = RCC_PLLI2S_GetFreqDomain_48M();
757 break;
758 #endif /* RCC_PLLI2SCFGR_PLLI2SQ && !RCC_DCKCFGR_PLLI2SDIVQ */
760 #if defined(RCC_PLLSAI_SUPPORT)
761 case LL_RCC_RNG_CLKSOURCE_PLLSAI: /* PLLSAI clock used as RNG clock source */
762 if (LL_RCC_PLLSAI_IsReady())
764 rng_frequency = RCC_PLLSAI_GetFreqDomain_48M();
766 break;
767 #endif /* RCC_PLLSAI_SUPPORT */
769 case LL_RCC_RNG_CLKSOURCE_PLL: /* PLL clock used as RNG clock source */
770 default:
771 if (LL_RCC_PLL_IsReady())
773 rng_frequency = RCC_PLL_GetFreqDomain_48M();
775 break;
777 #else
778 /* PLL clock used as RNG clock source */
779 if (LL_RCC_PLL_IsReady())
781 rng_frequency = RCC_PLL_GetFreqDomain_48M();
783 #endif /* RCC_DCKCFGR_CK48MSEL || RCC_DCKCFGR2_CK48MSEL */
785 return rng_frequency;
787 #endif /* RNG */
789 #if defined(CEC)
791 * @brief Return CEC clock frequency
792 * @param CECxSource This parameter can be one of the following values:
793 * @arg @ref LL_RCC_CEC_CLKSOURCE
794 * @retval CEC clock frequency (in Hz)
795 * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
797 uint32_t LL_RCC_GetCECClockFreq(uint32_t CECxSource)
799 uint32_t cec_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
801 /* Check parameter */
802 assert_param(IS_LL_RCC_CEC_CLKSOURCE(CECxSource));
804 /* CECCLK clock frequency */
805 switch (LL_RCC_GetCECClockSource(CECxSource))
807 case LL_RCC_CEC_CLKSOURCE_LSE: /* CEC Clock is LSE Osc. */
808 if (LL_RCC_LSE_IsReady())
810 cec_frequency = LSE_VALUE;
812 break;
814 case LL_RCC_CEC_CLKSOURCE_HSI_DIV488: /* CEC Clock is HSI Osc. */
815 default:
816 if (LL_RCC_HSI_IsReady())
818 cec_frequency = HSI_VALUE/488U;
820 break;
823 return cec_frequency;
825 #endif /* CEC */
827 #if defined(USB_OTG_FS) || defined(USB_OTG_HS)
829 * @brief Return USBx clock frequency
830 * @param USBxSource This parameter can be one of the following values:
831 * @arg @ref LL_RCC_USB_CLKSOURCE
832 * @retval USB clock frequency (in Hz)
833 * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready
835 uint32_t LL_RCC_GetUSBClockFreq(uint32_t USBxSource)
837 uint32_t usb_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
839 /* Check parameter */
840 assert_param(IS_LL_RCC_USB_CLKSOURCE(USBxSource));
842 #if defined(RCC_DCKCFGR_CK48MSEL) || defined(RCC_DCKCFGR2_CK48MSEL)
843 /* USBCLK clock frequency */
844 switch (LL_RCC_GetUSBClockSource(USBxSource))
846 #if defined(RCC_PLLI2SCFGR_PLLI2SQ) && !defined(RCC_DCKCFGR_PLLI2SDIVQ)
847 case LL_RCC_USB_CLKSOURCE_PLLI2S: /* PLLI2S clock used as USB clock source */
848 if (LL_RCC_PLLI2S_IsReady())
850 usb_frequency = RCC_PLLI2S_GetFreqDomain_48M();
852 break;
854 #endif /* RCC_PLLI2SCFGR_PLLI2SQ && !RCC_DCKCFGR_PLLI2SDIVQ */
856 #if defined(RCC_PLLSAI_SUPPORT)
857 case LL_RCC_USB_CLKSOURCE_PLLSAI: /* PLLSAI clock used as USB clock source */
858 if (LL_RCC_PLLSAI_IsReady())
860 usb_frequency = RCC_PLLSAI_GetFreqDomain_48M();
862 break;
863 #endif /* RCC_PLLSAI_SUPPORT */
865 case LL_RCC_USB_CLKSOURCE_PLL: /* PLL clock used as USB clock source */
866 default:
867 if (LL_RCC_PLL_IsReady())
869 usb_frequency = RCC_PLL_GetFreqDomain_48M();
871 break;
873 #else
874 /* PLL clock used as USB clock source */
875 if (LL_RCC_PLL_IsReady())
877 usb_frequency = RCC_PLL_GetFreqDomain_48M();
879 #endif /* RCC_DCKCFGR_CK48MSEL || RCC_DCKCFGR2_CK48MSEL */
881 return usb_frequency;
883 #endif /* USB_OTG_FS || USB_OTG_HS */
885 #if defined(DFSDM1_Channel0)
887 * @brief Return DFSDMx clock frequency
888 * @param DFSDMxSource This parameter can be one of the following values:
889 * @arg @ref LL_RCC_DFSDM1_CLKSOURCE
890 * @arg @ref LL_RCC_DFSDM2_CLKSOURCE (*)
892 * (*) value not defined in all devices.
893 * @retval DFSDM clock frequency (in Hz)
895 uint32_t LL_RCC_GetDFSDMClockFreq(uint32_t DFSDMxSource)
897 uint32_t dfsdm_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
899 /* Check parameter */
900 assert_param(IS_LL_RCC_DFSDM_CLKSOURCE(DFSDMxSource));
902 if (DFSDMxSource == LL_RCC_DFSDM1_CLKSOURCE)
904 /* DFSDM1CLK clock frequency */
905 switch (LL_RCC_GetDFSDMClockSource(DFSDMxSource))
907 case LL_RCC_DFSDM1_CLKSOURCE_SYSCLK: /* DFSDM1 Clock is SYSCLK */
908 dfsdm_frequency = RCC_GetSystemClockFreq();
909 break;
911 case LL_RCC_DFSDM1_CLKSOURCE_PCLK2: /* DFSDM1 Clock is PCLK2 */
912 default:
913 dfsdm_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
914 break;
917 #if defined(DFSDM2_Channel0)
918 else
920 /* DFSDM2CLK clock frequency */
921 switch (LL_RCC_GetDFSDMClockSource(DFSDMxSource))
923 case LL_RCC_DFSDM2_CLKSOURCE_SYSCLK: /* DFSDM2 Clock is SYSCLK */
924 dfsdm_frequency = RCC_GetSystemClockFreq();
925 break;
927 case LL_RCC_DFSDM2_CLKSOURCE_PCLK2: /* DFSDM2 Clock is PCLK2 */
928 default:
929 dfsdm_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
930 break;
933 #endif /* DFSDM2_Channel0 */
935 return dfsdm_frequency;
939 * @brief Return DFSDMx Audio clock frequency
940 * @param DFSDMxSource This parameter can be one of the following values:
941 * @arg @ref LL_RCC_DFSDM1_AUDIO_CLKSOURCE
942 * @arg @ref LL_RCC_DFSDM2_AUDIO_CLKSOURCE (*)
944 * (*) value not defined in all devices.
945 * @retval DFSDM clock frequency (in Hz)
946 * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready
948 uint32_t LL_RCC_GetDFSDMAudioClockFreq(uint32_t DFSDMxSource)
950 uint32_t dfsdm_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
952 /* Check parameter */
953 assert_param(IS_LL_RCC_DFSDM_AUDIO_CLKSOURCE(DFSDMxSource));
955 if (DFSDMxSource == LL_RCC_DFSDM1_AUDIO_CLKSOURCE)
957 /* DFSDM1CLK clock frequency */
958 switch (LL_RCC_GetDFSDMAudioClockSource(DFSDMxSource))
960 case LL_RCC_DFSDM1_AUDIO_CLKSOURCE_I2S1: /* I2S1 clock used as DFSDM1 clock */
961 dfsdm_frequency = LL_RCC_GetI2SClockFreq(LL_RCC_I2S1_CLKSOURCE);
962 break;
964 case LL_RCC_DFSDM1_AUDIO_CLKSOURCE_I2S2: /* I2S2 clock used as DFSDM1 clock */
965 default:
966 dfsdm_frequency = LL_RCC_GetI2SClockFreq(LL_RCC_I2S2_CLKSOURCE);
967 break;
970 #if defined(DFSDM2_Channel0)
971 else
973 /* DFSDM2CLK clock frequency */
974 switch (LL_RCC_GetDFSDMAudioClockSource(DFSDMxSource))
976 case LL_RCC_DFSDM2_AUDIO_CLKSOURCE_I2S1: /* I2S1 clock used as DFSDM2 clock */
977 dfsdm_frequency = LL_RCC_GetI2SClockFreq(LL_RCC_I2S1_CLKSOURCE);
978 break;
980 case LL_RCC_DFSDM2_AUDIO_CLKSOURCE_I2S2: /* I2S2 clock used as DFSDM2 clock */
981 default:
982 dfsdm_frequency = LL_RCC_GetI2SClockFreq(LL_RCC_I2S2_CLKSOURCE);
983 break;
986 #endif /* DFSDM2_Channel0 */
988 return dfsdm_frequency;
990 #endif /* DFSDM1_Channel0 */
992 #if defined(DSI)
994 * @brief Return DSI clock frequency
995 * @param DSIxSource This parameter can be one of the following values:
996 * @arg @ref LL_RCC_DSI_CLKSOURCE
997 * @retval DSI clock frequency (in Hz)
998 * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready
999 * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that external clock is used
1001 uint32_t LL_RCC_GetDSIClockFreq(uint32_t DSIxSource)
1003 uint32_t dsi_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
1005 /* Check parameter */
1006 assert_param(IS_LL_RCC_DSI_CLKSOURCE(DSIxSource));
1008 /* DSICLK clock frequency */
1009 switch (LL_RCC_GetDSIClockSource(DSIxSource))
1011 case LL_RCC_DSI_CLKSOURCE_PLL: /* DSI Clock is PLL Osc. */
1012 if (LL_RCC_PLL_IsReady())
1014 dsi_frequency = RCC_PLL_GetFreqDomain_DSI();
1016 break;
1018 case LL_RCC_DSI_CLKSOURCE_PHY: /* DSI Clock is DSI physical clock. */
1019 default:
1020 dsi_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
1021 break;
1024 return dsi_frequency;
1026 #endif /* DSI */
1028 #if defined(LTDC)
1030 * @brief Return LTDC clock frequency
1031 * @param LTDCxSource This parameter can be one of the following values:
1032 * @arg @ref LL_RCC_LTDC_CLKSOURCE
1033 * @retval LTDC clock frequency (in Hz)
1034 * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator PLLSAI is not ready
1036 uint32_t LL_RCC_GetLTDCClockFreq(uint32_t LTDCxSource)
1038 uint32_t ltdc_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
1040 /* Check parameter */
1041 assert_param(IS_LL_RCC_LTDC_CLKSOURCE(LTDCxSource));
1043 if (LL_RCC_PLLSAI_IsReady())
1045 ltdc_frequency = RCC_PLLSAI_GetFreqDomain_LTDC();
1048 return ltdc_frequency;
1050 #endif /* LTDC */
1052 #if defined(SPDIFRX)
1054 * @brief Return SPDIFRX clock frequency
1055 * @param SPDIFRXxSource This parameter can be one of the following values:
1056 * @arg @ref LL_RCC_SPDIFRX1_CLKSOURCE
1057 * @retval SPDIFRX clock frequency (in Hz)
1058 * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready
1060 uint32_t LL_RCC_GetSPDIFRXClockFreq(uint32_t SPDIFRXxSource)
1062 uint32_t spdifrx_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
1064 /* Check parameter */
1065 assert_param(IS_LL_RCC_SPDIFRX_CLKSOURCE(SPDIFRXxSource));
1067 /* SPDIFRX1CLK clock frequency */
1068 switch (LL_RCC_GetSPDIFRXClockSource(SPDIFRXxSource))
1070 case LL_RCC_SPDIFRX1_CLKSOURCE_PLLI2S: /* SPDIFRX Clock is PLLI2S Osc. */
1071 if (LL_RCC_PLLI2S_IsReady())
1073 spdifrx_frequency = RCC_PLLI2S_GetFreqDomain_SPDIFRX();
1075 break;
1077 case LL_RCC_SPDIFRX1_CLKSOURCE_PLL: /* SPDIFRX Clock is PLL Osc. */
1078 default:
1079 if (LL_RCC_PLL_IsReady())
1081 spdifrx_frequency = RCC_PLL_GetFreqDomain_SPDIFRX();
1083 break;
1086 return spdifrx_frequency;
1088 #endif /* SPDIFRX */
1091 * @}
1095 * @}
1098 /** @addtogroup RCC_LL_Private_Functions
1099 * @{
1103 * @brief Return SYSTEM clock frequency
1104 * @retval SYSTEM clock frequency (in Hz)
1106 uint32_t RCC_GetSystemClockFreq(void)
1108 uint32_t frequency = 0U;
1110 /* Get SYSCLK source -------------------------------------------------------*/
1111 switch (LL_RCC_GetSysClkSource())
1113 case LL_RCC_SYS_CLKSOURCE_STATUS_HSI: /* HSI used as system clock source */
1114 frequency = HSI_VALUE;
1115 break;
1117 case LL_RCC_SYS_CLKSOURCE_STATUS_HSE: /* HSE used as system clock source */
1118 frequency = HSE_VALUE;
1119 break;
1121 case LL_RCC_SYS_CLKSOURCE_STATUS_PLL: /* PLL used as system clock source */
1122 frequency = RCC_PLL_GetFreqDomain_SYS(LL_RCC_SYS_CLKSOURCE_STATUS_PLL);
1123 break;
1125 #if defined(RCC_PLLR_SYSCLK_SUPPORT)
1126 case LL_RCC_SYS_CLKSOURCE_STATUS_PLLR: /* PLLR used as system clock source */
1127 frequency = RCC_PLL_GetFreqDomain_SYS(LL_RCC_SYS_CLKSOURCE_STATUS_PLLR);
1128 break;
1129 #endif /* RCC_PLLR_SYSCLK_SUPPORT */
1131 default:
1132 frequency = HSI_VALUE;
1133 break;
1136 return frequency;
1140 * @brief Return HCLK clock frequency
1141 * @param SYSCLK_Frequency SYSCLK clock frequency
1142 * @retval HCLK clock frequency (in Hz)
1144 uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency)
1146 /* HCLK clock frequency */
1147 return __LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, LL_RCC_GetAHBPrescaler());
1151 * @brief Return PCLK1 clock frequency
1152 * @param HCLK_Frequency HCLK clock frequency
1153 * @retval PCLK1 clock frequency (in Hz)
1155 uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency)
1157 /* PCLK1 clock frequency */
1158 return __LL_RCC_CALC_PCLK1_FREQ(HCLK_Frequency, LL_RCC_GetAPB1Prescaler());
1162 * @brief Return PCLK2 clock frequency
1163 * @param HCLK_Frequency HCLK clock frequency
1164 * @retval PCLK2 clock frequency (in Hz)
1166 uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency)
1168 /* PCLK2 clock frequency */
1169 return __LL_RCC_CALC_PCLK2_FREQ(HCLK_Frequency, LL_RCC_GetAPB2Prescaler());
1173 * @brief Return PLL clock frequency used for system domain
1174 * @param SYSCLK_Source System clock source
1175 * @retval PLL clock frequency (in Hz)
1177 uint32_t RCC_PLL_GetFreqDomain_SYS(uint32_t SYSCLK_Source)
1179 uint32_t pllinputfreq = 0U, pllsource = 0U, plloutputfreq = 0U;
1181 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
1182 SYSCLK = PLL_VCO / (PLLP or PLLR)
1184 pllsource = LL_RCC_PLL_GetMainSource();
1186 switch (pllsource)
1188 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
1189 pllinputfreq = HSI_VALUE;
1190 break;
1192 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
1193 pllinputfreq = HSE_VALUE;
1194 break;
1196 default:
1197 pllinputfreq = HSI_VALUE;
1198 break;
1201 if (SYSCLK_Source == LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
1203 plloutputfreq = __LL_RCC_CALC_PLLCLK_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
1204 LL_RCC_PLL_GetN(), LL_RCC_PLL_GetP());
1206 #if defined(RCC_PLLR_SYSCLK_SUPPORT)
1207 else
1209 plloutputfreq = __LL_RCC_CALC_PLLRCLK_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
1210 LL_RCC_PLL_GetN(), LL_RCC_PLL_GetR());
1212 #endif /* RCC_PLLR_SYSCLK_SUPPORT */
1214 return plloutputfreq;
1218 * @brief Return PLL clock frequency used for 48 MHz domain
1219 * @retval PLL clock frequency (in Hz)
1221 uint32_t RCC_PLL_GetFreqDomain_48M(void)
1223 uint32_t pllinputfreq = 0U, pllsource = 0U;
1225 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM ) * PLLN
1226 48M Domain clock = PLL_VCO / PLLQ
1228 pllsource = LL_RCC_PLL_GetMainSource();
1230 switch (pllsource)
1232 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
1233 pllinputfreq = HSI_VALUE;
1234 break;
1236 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
1237 pllinputfreq = HSE_VALUE;
1238 break;
1240 default:
1241 pllinputfreq = HSI_VALUE;
1242 break;
1244 return __LL_RCC_CALC_PLLCLK_48M_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
1245 LL_RCC_PLL_GetN(), LL_RCC_PLL_GetQ());
1248 #if defined(DSI)
1250 * @brief Return PLL clock frequency used for DSI clock
1251 * @retval PLL clock frequency (in Hz)
1253 uint32_t RCC_PLL_GetFreqDomain_DSI(void)
1255 uint32_t pllinputfreq = 0U, pllsource = 0U;
1257 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
1258 DSICLK = PLL_VCO / PLLR
1260 pllsource = LL_RCC_PLL_GetMainSource();
1262 switch (pllsource)
1264 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
1265 pllinputfreq = HSE_VALUE;
1266 break;
1268 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
1269 default:
1270 pllinputfreq = HSI_VALUE;
1271 break;
1273 return __LL_RCC_CALC_PLLCLK_DSI_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
1274 LL_RCC_PLL_GetN(), LL_RCC_PLL_GetR());
1276 #endif /* DSI */
1278 #if defined(RCC_DCKCFGR_I2SSRC) || defined(RCC_DCKCFGR_I2S1SRC)
1280 * @brief Return PLL clock frequency used for I2S clock
1281 * @retval PLL clock frequency (in Hz)
1283 uint32_t RCC_PLL_GetFreqDomain_I2S(void)
1285 uint32_t pllinputfreq = 0U, pllsource = 0U;
1287 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
1288 I2SCLK = PLL_VCO / PLLR
1290 pllsource = LL_RCC_PLL_GetMainSource();
1292 switch (pllsource)
1294 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
1295 pllinputfreq = HSE_VALUE;
1296 break;
1298 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
1299 default:
1300 pllinputfreq = HSI_VALUE;
1301 break;
1303 return __LL_RCC_CALC_PLLCLK_I2S_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
1304 LL_RCC_PLL_GetN(), LL_RCC_PLL_GetR());
1306 #endif /* RCC_DCKCFGR_I2SSRC || RCC_DCKCFGR_I2S1SRC */
1308 #if defined(SPDIFRX)
1310 * @brief Return PLL clock frequency used for SPDIFRX clock
1311 * @retval PLL clock frequency (in Hz)
1313 uint32_t RCC_PLL_GetFreqDomain_SPDIFRX(void)
1315 uint32_t pllinputfreq = 0U, pllsource = 0U;
1317 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
1318 SPDIFRXCLK = PLL_VCO / PLLR
1320 pllsource = LL_RCC_PLL_GetMainSource();
1322 switch (pllsource)
1324 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
1325 pllinputfreq = HSE_VALUE;
1326 break;
1328 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
1329 default:
1330 pllinputfreq = HSI_VALUE;
1331 break;
1333 return __LL_RCC_CALC_PLLCLK_SPDIFRX_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
1334 LL_RCC_PLL_GetN(), LL_RCC_PLL_GetR());
1336 #endif /* SPDIFRX */
1338 #if defined(RCC_PLLCFGR_PLLR)
1339 #if defined(SAI1)
1341 * @brief Return PLL clock frequency used for SAI clock
1342 * @retval PLL clock frequency (in Hz)
1344 uint32_t RCC_PLL_GetFreqDomain_SAI(void)
1346 uint32_t pllinputfreq = 0U, pllsource = 0U, plloutputfreq = 0U;
1348 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
1349 SAICLK = (PLL_VCO / PLLR) / PLLDIVR
1351 SAICLK = PLL_VCO / PLLR
1353 pllsource = LL_RCC_PLL_GetMainSource();
1355 switch (pllsource)
1357 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
1358 pllinputfreq = HSE_VALUE;
1359 break;
1361 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
1362 default:
1363 pllinputfreq = HSI_VALUE;
1364 break;
1367 #if defined(RCC_DCKCFGR_PLLDIVR)
1368 plloutputfreq = __LL_RCC_CALC_PLLCLK_SAI_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
1369 LL_RCC_PLL_GetN(), LL_RCC_PLL_GetR(), LL_RCC_PLL_GetDIVR());
1370 #else
1371 plloutputfreq = __LL_RCC_CALC_PLLCLK_SAI_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
1372 LL_RCC_PLL_GetN(), LL_RCC_PLL_GetR());
1373 #endif /* RCC_DCKCFGR_PLLDIVR */
1375 return plloutputfreq;
1377 #endif /* SAI1 */
1378 #endif /* RCC_PLLCFGR_PLLR */
1380 #if defined(RCC_PLLSAI_SUPPORT)
1382 * @brief Return PLLSAI clock frequency used for SAI domain
1383 * @retval PLLSAI clock frequency (in Hz)
1385 uint32_t RCC_PLLSAI_GetFreqDomain_SAI(void)
1387 uint32_t pllinputfreq = 0U, pllsource = 0U;
1389 /* PLLSAI_VCO = (HSE_VALUE or HSI_VALUE / PLLSAIM) * PLLSAIN
1390 SAI domain clock = (PLLSAI_VCO / PLLSAIQ) / PLLSAIDIVQ
1392 pllsource = LL_RCC_PLL_GetMainSource();
1394 switch (pllsource)
1396 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI clock source */
1397 pllinputfreq = HSI_VALUE;
1398 break;
1400 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI clock source */
1401 pllinputfreq = HSE_VALUE;
1402 break;
1404 default:
1405 pllinputfreq = HSI_VALUE;
1406 break;
1408 return __LL_RCC_CALC_PLLSAI_SAI_FREQ(pllinputfreq, LL_RCC_PLLSAI_GetDivider(),
1409 LL_RCC_PLLSAI_GetN(), LL_RCC_PLLSAI_GetQ(), LL_RCC_PLLSAI_GetDIVQ());
1412 #if defined(RCC_PLLSAICFGR_PLLSAIP)
1414 * @brief Return PLLSAI clock frequency used for 48Mhz domain
1415 * @retval PLLSAI clock frequency (in Hz)
1417 uint32_t RCC_PLLSAI_GetFreqDomain_48M(void)
1419 uint32_t pllinputfreq = 0U, pllsource = 0U;
1421 /* PLLSAI_VCO = (HSE_VALUE or HSI_VALUE / PLLSAIM) * PLLSAIN
1422 48M Domain clock = PLLSAI_VCO / PLLSAIP
1424 pllsource = LL_RCC_PLL_GetMainSource();
1426 switch (pllsource)
1428 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI clock source */
1429 pllinputfreq = HSI_VALUE;
1430 break;
1432 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI clock source */
1433 pllinputfreq = HSE_VALUE;
1434 break;
1436 default:
1437 pllinputfreq = HSI_VALUE;
1438 break;
1440 return __LL_RCC_CALC_PLLSAI_48M_FREQ(pllinputfreq, LL_RCC_PLLSAI_GetDivider(),
1441 LL_RCC_PLLSAI_GetN(), LL_RCC_PLLSAI_GetP());
1443 #endif /* RCC_PLLSAICFGR_PLLSAIP */
1445 #if defined(LTDC)
1447 * @brief Return PLLSAI clock frequency used for LTDC domain
1448 * @retval PLLSAI clock frequency (in Hz)
1450 uint32_t RCC_PLLSAI_GetFreqDomain_LTDC(void)
1452 uint32_t pllinputfreq = 0U, pllsource = 0U;
1454 /* PLLSAI_VCO = (HSE_VALUE or HSI_VALUE / PLLSAIM) * PLLSAIN
1455 LTDC Domain clock = (PLLSAI_VCO / PLLSAIR) / PLLSAIDIVR
1457 pllsource = LL_RCC_PLL_GetMainSource();
1459 switch (pllsource)
1461 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI clock source */
1462 pllinputfreq = HSI_VALUE;
1463 break;
1465 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI clock source */
1466 pllinputfreq = HSE_VALUE;
1467 break;
1469 default:
1470 pllinputfreq = HSI_VALUE;
1471 break;
1473 return __LL_RCC_CALC_PLLSAI_LTDC_FREQ(pllinputfreq, LL_RCC_PLLSAI_GetDivider(),
1474 LL_RCC_PLLSAI_GetN(), LL_RCC_PLLSAI_GetR(), LL_RCC_PLLSAI_GetDIVR());
1476 #endif /* LTDC */
1477 #endif /* RCC_PLLSAI_SUPPORT */
1479 #if defined(RCC_PLLI2S_SUPPORT)
1480 #if defined(SAI1)
1482 * @brief Return PLLI2S clock frequency used for SAI domains
1483 * @retval PLLI2S clock frequency (in Hz)
1485 uint32_t RCC_PLLI2S_GetFreqDomain_SAI(void)
1487 uint32_t plli2sinputfreq = 0U, plli2ssource = 0U, plli2soutputfreq = 0U;
1489 /* PLLI2S_VCO = (HSE_VALUE or HSI_VALUE / PLLI2SM) * PLLI2SN
1490 SAI domain clock = (PLLI2S_VCO / PLLI2SQ) / PLLI2SDIVQ
1492 SAI domain clock = (PLLI2S_VCO / PLLI2SR) / PLLI2SDIVR
1494 plli2ssource = LL_RCC_PLLI2S_GetMainSource();
1496 switch (plli2ssource)
1498 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLI2S clock source */
1499 plli2sinputfreq = HSE_VALUE;
1500 break;
1502 #if defined(RCC_PLLI2SCFGR_PLLI2SSRC)
1503 case LL_RCC_PLLI2SSOURCE_PIN: /* External pin input clock used as PLLI2S clock source */
1504 plli2sinputfreq = EXTERNAL_CLOCK_VALUE;
1505 break;
1506 #endif /* RCC_PLLI2SCFGR_PLLI2SSRC */
1508 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLI2S clock source */
1509 default:
1510 plli2sinputfreq = HSI_VALUE;
1511 break;
1514 #if defined(RCC_DCKCFGR_PLLI2SDIVQ)
1515 plli2soutputfreq = __LL_RCC_CALC_PLLI2S_SAI_FREQ(plli2sinputfreq, LL_RCC_PLLI2S_GetDivider(),
1516 LL_RCC_PLLI2S_GetN(), LL_RCC_PLLI2S_GetQ(), LL_RCC_PLLI2S_GetDIVQ());
1517 #else
1518 plli2soutputfreq = __LL_RCC_CALC_PLLI2S_SAI_FREQ(plli2sinputfreq, LL_RCC_PLLI2S_GetDivider(),
1519 LL_RCC_PLLI2S_GetN(), LL_RCC_PLLI2S_GetR(), LL_RCC_PLLI2S_GetDIVR());
1520 #endif /* RCC_DCKCFGR_PLLI2SDIVQ */
1522 return plli2soutputfreq;
1524 #endif /* SAI1 */
1526 #if defined(SPDIFRX)
1528 * @brief Return PLLI2S clock frequency used for SPDIFRX domain
1529 * @retval PLLI2S clock frequency (in Hz)
1531 uint32_t RCC_PLLI2S_GetFreqDomain_SPDIFRX(void)
1533 uint32_t pllinputfreq = 0U, pllsource = 0U;
1535 /* PLLI2S_VCO = (HSE_VALUE or HSI_VALUE / PLLI2SM) * PLLI2SN
1536 SPDIFRX Domain clock = PLLI2S_VCO / PLLI2SP
1538 pllsource = LL_RCC_PLLI2S_GetMainSource();
1540 switch (pllsource)
1542 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLI2S clock source */
1543 pllinputfreq = HSE_VALUE;
1544 break;
1546 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLI2S clock source */
1547 default:
1548 pllinputfreq = HSI_VALUE;
1549 break;
1552 return __LL_RCC_CALC_PLLI2S_SPDIFRX_FREQ(pllinputfreq, LL_RCC_PLLI2S_GetDivider(),
1553 LL_RCC_PLLI2S_GetN(), LL_RCC_PLLI2S_GetP());
1555 #endif /* SPDIFRX */
1558 * @brief Return PLLI2S clock frequency used for I2S domain
1559 * @retval PLLI2S clock frequency (in Hz)
1561 uint32_t RCC_PLLI2S_GetFreqDomain_I2S(void)
1563 uint32_t plli2sinputfreq = 0U, plli2ssource = 0U, plli2soutputfreq = 0U;
1565 /* PLLI2S_VCO = (HSE_VALUE or HSI_VALUE / PLLI2SM) * PLLI2SN
1566 I2S Domain clock = PLLI2S_VCO / PLLI2SR
1568 plli2ssource = LL_RCC_PLLI2S_GetMainSource();
1570 switch (plli2ssource)
1572 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLI2S clock source */
1573 plli2sinputfreq = HSE_VALUE;
1574 break;
1576 #if defined(RCC_PLLI2SCFGR_PLLI2SSRC)
1577 case LL_RCC_PLLI2SSOURCE_PIN: /* External pin input clock used as PLLI2S clock source */
1578 plli2sinputfreq = EXTERNAL_CLOCK_VALUE;
1579 break;
1580 #endif /* RCC_PLLI2SCFGR_PLLI2SSRC */
1582 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLI2S clock source */
1583 default:
1584 plli2sinputfreq = HSI_VALUE;
1585 break;
1588 plli2soutputfreq = __LL_RCC_CALC_PLLI2S_I2S_FREQ(plli2sinputfreq, LL_RCC_PLLI2S_GetDivider(),
1589 LL_RCC_PLLI2S_GetN(), LL_RCC_PLLI2S_GetR());
1591 return plli2soutputfreq;
1594 #if defined(RCC_PLLI2SCFGR_PLLI2SQ) && !defined(RCC_DCKCFGR_PLLI2SDIVQ)
1596 * @brief Return PLLI2S clock frequency used for 48Mhz domain
1597 * @retval PLLI2S clock frequency (in Hz)
1599 uint32_t RCC_PLLI2S_GetFreqDomain_48M(void)
1601 uint32_t plli2sinputfreq = 0U, plli2ssource = 0U, plli2soutputfreq = 0U;
1603 /* PLL48M_VCO = (HSE_VALUE or HSI_VALUE / PLLI2SM) * PLLI2SN
1604 48M Domain clock = PLLI2S_VCO / PLLI2SQ
1606 plli2ssource = LL_RCC_PLLI2S_GetMainSource();
1608 switch (plli2ssource)
1610 case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLI2S clock source */
1611 plli2sinputfreq = HSE_VALUE;
1612 break;
1614 #if defined(RCC_PLLI2SCFGR_PLLI2SSRC)
1615 case LL_RCC_PLLI2SSOURCE_PIN: /* External pin input clock used as PLLI2S clock source */
1616 plli2sinputfreq = EXTERNAL_CLOCK_VALUE;
1617 break;
1618 #endif /* RCC_PLLI2SCFGR_PLLI2SSRC */
1620 case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLI2S clock source */
1621 default:
1622 plli2sinputfreq = HSI_VALUE;
1623 break;
1626 plli2soutputfreq = __LL_RCC_CALC_PLLI2S_48M_FREQ(plli2sinputfreq, LL_RCC_PLLI2S_GetDivider(),
1627 LL_RCC_PLLI2S_GetN(), LL_RCC_PLLI2S_GetQ());
1629 return plli2soutputfreq;
1631 #endif /* RCC_PLLI2SCFGR_PLLI2SQ && !RCC_DCKCFGR_PLLI2SDIVQ */
1632 #endif /* RCC_PLLI2S_SUPPORT */
1634 * @}
1638 * @}
1641 #endif /* defined(RCC) */
1644 * @}
1647 #endif /* USE_FULL_LL_DRIVER */
1649 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/