You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1343 lines
38 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32wbxx_ll_rcc.c
  4. * @author MCD Application Team
  5. * @brief RCC LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #if defined(USE_FULL_LL_DRIVER)
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32wbxx_ll_rcc.h"
  22. #ifdef USE_FULL_ASSERT
  23. #include "stm32_assert.h"
  24. #else
  25. #define assert_param(expr) ((void)0U)
  26. #endif
  27. /** @addtogroup STM32WBxx_LL_Driver
  28. * @{
  29. */
  30. #if defined(RCC)
  31. /** @addtogroup RCC_LL
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. /** @addtogroup RCC_LL_Private_Macros
  39. * @{
  40. */
  41. #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_USART1_CLKSOURCE)
  42. #if defined(LPUART1)
  43. #define IS_LL_RCC_LPUART_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_LPUART1_CLKSOURCE)
  44. #endif
  45. #if defined(I2C3)
  46. #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2C1_CLKSOURCE) \
  47. || ((__VALUE__) == LL_RCC_I2C3_CLKSOURCE))
  48. #else
  49. #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_I2C1_CLKSOURCE)
  50. #endif
  51. #define IS_LL_RCC_LPTIM_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LPTIM1_CLKSOURCE) \
  52. || ((__VALUE__) == LL_RCC_LPTIM2_CLKSOURCE))
  53. #if defined(SAI1)
  54. #define IS_LL_RCC_SAI_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_SAI1_CLKSOURCE)
  55. #endif
  56. #define IS_LL_RCC_RNG_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_RNG_CLKSOURCE))
  57. #define IS_LL_RCC_CLK48_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_CLK48_CLKSOURCE))
  58. #if defined(USB)
  59. #define IS_LL_RCC_USB_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USB_CLKSOURCE))
  60. #endif
  61. #define IS_LL_RCC_ADC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_ADC_CLKSOURCE))
  62. /**
  63. * @}
  64. */
  65. /* Private function prototypes -----------------------------------------------*/
  66. /** @defgroup RCC_LL_Private_Functions RCC Private functions
  67. * @{
  68. */
  69. uint32_t RCC_PLL_GetFreqDomain_SYS(void);
  70. #if defined(SAI1)
  71. uint32_t RCC_PLL_GetFreqDomain_SAI(void);
  72. #endif
  73. uint32_t RCC_PLL_GetFreqDomain_ADC(void);
  74. uint32_t RCC_PLL_GetFreqDomain_48M(void);
  75. #if defined(SAI1)
  76. uint32_t RCC_PLLSAI1_GetFreqDomain_SAI(void);
  77. uint32_t RCC_PLLSAI1_GetFreqDomain_48M(void);
  78. uint32_t RCC_PLLSAI1_GetFreqDomain_ADC(void);
  79. #endif
  80. uint32_t RCC_GetSystemClockFreq(void);
  81. uint32_t RCC_GetHCLK1ClockFreq(uint32_t SYSCLK_Frequency);
  82. uint32_t RCC_GetHCLK2ClockFreq(uint32_t SYSCLK_Frequency);
  83. uint32_t RCC_GetHCLK4ClockFreq(uint32_t SYSCLK_Frequency);
  84. uint32_t RCC_GetHCLK5ClockFreq(void);
  85. uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency);
  86. uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency);
  87. /**
  88. * @}
  89. */
  90. /* Exported functions --------------------------------------------------------*/
  91. /** @addtogroup RCC_LL_Exported_Functions
  92. * @{
  93. */
  94. /** @addtogroup RCC_LL_EF_Init
  95. * @{
  96. */
  97. /**
  98. * @brief Reset the RCC clock to the default reset state.
  99. * @note The default reset state of the clock configuration is given below:
  100. * - MSI ON and used as system clock source
  101. * - HSE, HSI, HSI48, PLL and PLLSAI1 Source OFF
  102. * - CPU1, CPU2, AHB4, APB1 and APB2 prescaler set to 1.
  103. * - CSS, MCO OFF
  104. * - All interrupts disabled
  105. * @note This function doesn't modify the configuration of the
  106. * - Peripheral clocks
  107. * - LSI, LSE and RTC clocks
  108. * @retval An ErrorStatus enumeration value:
  109. * - SUCCESS: RCC registers are de-initialized
  110. * - ERROR: not applicable
  111. */
  112. ErrorStatus LL_RCC_DeInit(void)
  113. {
  114. uint32_t vl_mask;
  115. /* Set MSION bit */
  116. LL_RCC_MSI_Enable();
  117. /* Insure MSIRDY bit is set before writing default MSIRANGE value */
  118. while (LL_RCC_MSI_IsReady() == 0U)
  119. {}
  120. /* Set MSIRANGE default value */
  121. LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_6);
  122. /* Set MSITRIM bits to the reset value*/
  123. LL_RCC_MSI_SetCalibTrimming(0);
  124. /* Set HSITRIM bits to the reset value*/
  125. LL_RCC_HSI_SetCalibTrimming(0x40U);
  126. /* Reset CFGR register */
  127. LL_RCC_WriteReg(CFGR, 0x00070000U); /* MSI selected as System Clock and all prescaler to not divided */
  128. /* Wait for MSI oscillator used as system clock */
  129. while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_MSI)
  130. {}
  131. /* Write new mask in CR register */
  132. LL_RCC_WriteReg(CR, 0x00000061);
  133. /* Wait for PLL READY bit to be reset */
  134. while (LL_RCC_PLL_IsReady() != 0U)
  135. {}
  136. /* Reset PLLCFGR register */
  137. LL_RCC_WriteReg(PLLCFGR, 0x22041000U);
  138. #if defined(SAI1)
  139. /* Wait for PLLSAI READY bit to be reset */
  140. while (LL_RCC_PLLSAI1_IsReady() != 0U)
  141. {}
  142. /* Reset PLLSAI1CFGR register */
  143. LL_RCC_WriteReg(PLLSAI1CFGR, 0x22041000U);
  144. #endif
  145. /* Disable all interrupts */
  146. LL_RCC_WriteReg(CIER, 0x00000000U);
  147. /* Clear all interrupt flags */
  148. vl_mask = RCC_CICR_LSI1RDYC | RCC_CICR_LSERDYC | RCC_CICR_MSIRDYC | RCC_CICR_HSIRDYC | RCC_CICR_HSERDYC | RCC_CICR_PLLRDYC | \
  149. RCC_CICR_CSSC | RCC_CICR_LSECSSC | RCC_CICR_LSI2RDYC;
  150. #if defined(SAI1)
  151. vl_mask |= RCC_CICR_PLLSAI1RDYC;
  152. #endif
  153. #if defined(RCC_HSI48_SUPPORT)
  154. vl_mask |= RCC_CICR_HSI48RDYC;
  155. #endif
  156. LL_RCC_WriteReg(CICR, vl_mask);
  157. /* Clear reset flags */
  158. LL_RCC_ClearResetFlags();
  159. #if defined(RCC_SMPS_SUPPORT)
  160. /* SMPS reset */
  161. LL_RCC_WriteReg(SMPSCR, 0x00000301U); /* MSI default clock source */
  162. #endif
  163. /* RF Wakeup Clock Source selection */
  164. LL_RCC_SetRFWKPClockSource(LL_RCC_RFWKP_CLKSOURCE_NONE);
  165. #if defined(RCC_HSI48_SUPPORT)
  166. /* HSI48 reset */
  167. LL_RCC_HSI48_Disable();
  168. #endif
  169. /* HSECR register write unlock & then reset*/
  170. LL_RCC_WriteReg(HSECR, HSE_CONTROL_UNLOCK_KEY);
  171. LL_RCC_WriteReg(HSECR, LL_RCC_HSE_CURRENTMAX_3); /* HSEGMC set to default value 011, current max limit 1.13 mA/V */
  172. /* EXTCFGR reset*/
  173. LL_RCC_WriteReg(EXTCFGR, 0x00030000U);
  174. return SUCCESS;
  175. }
  176. /**
  177. * @}
  178. */
  179. /** @addtogroup RCC_LL_EF_Get_Freq
  180. * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks
  181. * and different peripheral clocks available on the device.
  182. * @note If SYSCLK source is MSI, function returns values based on MSI values(*)
  183. * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(**)
  184. * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(***)
  185. * @note If SYSCLK source is PLL, function returns values based on HSE_VALUE(***)
  186. * or HSI_VALUE(**) or MSI values(*) multiplied/divided by the PLL factors.
  187. * @note (*) MSI values are retrieved thanks to __LL_RCC_CALC_MSI_FREQ macro
  188. * @note (**) HSI_VALUE is a constant defined in this file (default value
  189. * 16 MHz) but the real value may vary depending on the variations
  190. * in voltage and temperature.
  191. * @note (***) HSE_VALUE is a constant defined in this file (default value
  192. * 32 MHz), user has to ensure that HSE_VALUE is same as the real
  193. * frequency of the crystal used. Otherwise, this function may
  194. * have wrong result.
  195. * @note The result of this function could be incorrect when using fractional
  196. * value for HSE crystal.
  197. * @note This function can be used by the user application to compute the
  198. * baud-rate for the communication peripherals or configure other parameters.
  199. * @{
  200. */
  201. /**
  202. * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks
  203. * @note Each time SYSCLK, HCLK, PCLK1 and/or PCLK2 clock changes, this function
  204. * must be called to update structure fields. Otherwise, any
  205. * configuration based on this function will be incorrect.
  206. * @param RCC_Clocks pointer to a @ref LL_RCC_ClocksTypeDef structure which will hold the clocks frequencies
  207. * @retval None
  208. */
  209. void LL_RCC_GetSystemClocksFreq(LL_RCC_ClocksTypeDef *RCC_Clocks)
  210. {
  211. /* Get SYSCLK frequency */
  212. RCC_Clocks->SYSCLK_Frequency = RCC_GetSystemClockFreq();
  213. /* HCLK1 clock frequency */
  214. RCC_Clocks->HCLK1_Frequency = RCC_GetHCLK1ClockFreq(RCC_Clocks->SYSCLK_Frequency);
  215. /* HCLK2 clock frequency */
  216. RCC_Clocks->HCLK2_Frequency = RCC_GetHCLK2ClockFreq(RCC_Clocks->SYSCLK_Frequency);
  217. /* HCLK4 clock frequency */
  218. RCC_Clocks->HCLK4_Frequency = RCC_GetHCLK4ClockFreq(RCC_Clocks->SYSCLK_Frequency);
  219. /* HCLK5 clock frequency */
  220. RCC_Clocks->HCLK5_Frequency = RCC_GetHCLK5ClockFreq();
  221. /* PCLK1 clock frequency */
  222. RCC_Clocks->PCLK1_Frequency = RCC_GetPCLK1ClockFreq(RCC_Clocks->HCLK1_Frequency);
  223. /* PCLK2 clock frequency */
  224. RCC_Clocks->PCLK2_Frequency = RCC_GetPCLK2ClockFreq(RCC_Clocks->HCLK1_Frequency);
  225. }
  226. #if defined(RCC_SMPS_SUPPORT)
  227. /**
  228. * @brief Return SMPS clock frequency
  229. * @note This function is only applicable when CPU runs,
  230. * When waking up from Standby mode and powering on the VCODE supply, the HSI is
  231. * selected as SMPS Step Down converter clock, independent from the selection in
  232. * SMPSSEL.
  233. * @retval SMPS clock frequency (in Hz)
  234. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
  235. */
  236. uint32_t LL_RCC_GetSMPSClockFreq(void)
  237. {
  238. uint32_t smps_frequency;
  239. uint32_t smps_prescaler_index = ((LL_RCC_GetSMPSPrescaler()) >> RCC_SMPSCR_SMPSDIV_Pos);
  240. uint32_t smpsClockSource = LL_RCC_GetSMPSClockSource();
  241. if (smpsClockSource == LL_RCC_SMPS_CLKSOURCE_STATUS_HSI) /* SMPS Clock source is HSI Osc. */
  242. {
  243. if (LL_RCC_HSI_IsReady() == 1U)
  244. {
  245. smps_frequency = HSI_VALUE / SmpsPrescalerTable[smps_prescaler_index][0];
  246. }
  247. else
  248. {
  249. smps_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  250. }
  251. }
  252. else if (smpsClockSource == LL_RCC_SMPS_CLKSOURCE_STATUS_HSE) /* SMPS Clock source is HSE Osc. */
  253. {
  254. if (LL_RCC_HSE_IsReady() == 1U)
  255. {
  256. smps_frequency = HSE_VALUE / SmpsPrescalerTable[smps_prescaler_index][5];
  257. }
  258. else
  259. {
  260. smps_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  261. }
  262. }
  263. else if (smpsClockSource == LL_RCC_SMPS_CLKSOURCE_STATUS_MSI) /* SMPS Clock source is MSI Osc. */
  264. {
  265. uint32_t msiRange = LL_RCC_MSI_GetRange();
  266. if (msiRange == LL_RCC_MSIRANGE_8)
  267. {
  268. smps_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSIRANGE_8) / SmpsPrescalerTable[smps_prescaler_index][4];
  269. }
  270. else if (msiRange == LL_RCC_MSIRANGE_9)
  271. {
  272. smps_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSIRANGE_9) / SmpsPrescalerTable[smps_prescaler_index][3];
  273. }
  274. else if (msiRange == LL_RCC_MSIRANGE_10)
  275. {
  276. smps_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSIRANGE_10) / SmpsPrescalerTable[smps_prescaler_index][2];
  277. }
  278. else if (msiRange == LL_RCC_MSIRANGE_11)
  279. {
  280. smps_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSIRANGE_11) / SmpsPrescalerTable[smps_prescaler_index][1];
  281. }
  282. else
  283. {
  284. smps_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  285. }
  286. }
  287. else /* SMPS has no Clock */
  288. {
  289. smps_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  290. }
  291. if (smps_frequency != LL_RCC_PERIPH_FREQUENCY_NO)
  292. {
  293. /* Systematic div by 2 */
  294. smps_frequency = smps_frequency >> 1U;
  295. }
  296. return smps_frequency;
  297. }
  298. #endif
  299. /**
  300. * @brief Return USARTx clock frequency
  301. * @param USARTxSource This parameter can be one of the following values:
  302. * @arg @ref LL_RCC_USART1_CLKSOURCE
  303. * @retval USART clock frequency (in Hz)
  304. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
  305. */
  306. uint32_t LL_RCC_GetUSARTClockFreq(uint32_t USARTxSource)
  307. {
  308. uint32_t usart_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  309. /* Check parameter */
  310. assert_param(IS_LL_RCC_USART_CLKSOURCE(USARTxSource));
  311. /* USART1CLK clock frequency */
  312. switch (LL_RCC_GetUSARTClockSource(USARTxSource))
  313. {
  314. case LL_RCC_USART1_CLKSOURCE_SYSCLK: /* USART1 Clock is System Clock */
  315. usart_frequency = RCC_GetSystemClockFreq();
  316. break;
  317. case LL_RCC_USART1_CLKSOURCE_HSI: /* USART1 Clock is HSI Osc. */
  318. if (LL_RCC_HSI_IsReady() == 1U)
  319. {
  320. usart_frequency = HSI_VALUE;
  321. }
  322. break;
  323. case LL_RCC_USART1_CLKSOURCE_LSE: /* USART1 Clock is LSE Osc. */
  324. if (LL_RCC_LSE_IsReady() == 1U)
  325. {
  326. usart_frequency = LSE_VALUE;
  327. }
  328. break;
  329. case LL_RCC_USART1_CLKSOURCE_PCLK2: /* USART1 Clock is PCLK2 */
  330. default:
  331. usart_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLK1ClockFreq(RCC_GetSystemClockFreq()));
  332. break;
  333. }
  334. return usart_frequency;
  335. }
  336. /**
  337. * @brief Return I2Cx clock frequency
  338. * @param I2CxSource This parameter can be one of the following values:
  339. * @arg @ref LL_RCC_I2C1_CLKSOURCE
  340. * @arg @ref LL_RCC_I2C3_CLKSOURCE (*)
  341. * @note (*) Value not defined for all devices
  342. * @retval I2C clock frequency (in Hz)
  343. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that HSI oscillator is not ready
  344. */
  345. uint32_t LL_RCC_GetI2CClockFreq(uint32_t I2CxSource)
  346. {
  347. uint32_t i2c_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  348. /* Check parameter */
  349. assert_param(IS_LL_RCC_I2C_CLKSOURCE(I2CxSource));
  350. if (I2CxSource == LL_RCC_I2C1_CLKSOURCE)
  351. {
  352. /* I2C1 CLK clock frequency */
  353. switch (LL_RCC_GetI2CClockSource(I2CxSource))
  354. {
  355. case LL_RCC_I2C1_CLKSOURCE_SYSCLK: /* I2C1 Clock is System Clock */
  356. i2c_frequency = RCC_GetSystemClockFreq();
  357. break;
  358. case LL_RCC_I2C1_CLKSOURCE_HSI: /* I2C1 Clock is HSI Osc. */
  359. if (LL_RCC_HSI_IsReady() == 1U)
  360. {
  361. i2c_frequency = HSI_VALUE;
  362. }
  363. break;
  364. case LL_RCC_I2C1_CLKSOURCE_PCLK1: /* I2C1 Clock is PCLK1 */
  365. default:
  366. i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLK1ClockFreq(RCC_GetSystemClockFreq()));
  367. break;
  368. }
  369. }
  370. #if defined(I2C3)
  371. else
  372. {
  373. /* I2C3 CLK clock frequency */
  374. switch (LL_RCC_GetI2CClockSource(I2CxSource))
  375. {
  376. case LL_RCC_I2C3_CLKSOURCE_SYSCLK: /* I2C3 Clock is System Clock */
  377. i2c_frequency = RCC_GetSystemClockFreq();
  378. break;
  379. case LL_RCC_I2C3_CLKSOURCE_HSI: /* I2C3 Clock is HSI Osc. */
  380. if (LL_RCC_HSI_IsReady() == 1U)
  381. {
  382. i2c_frequency = HSI_VALUE;
  383. }
  384. break;
  385. case LL_RCC_I2C3_CLKSOURCE_PCLK1: /* I2C3 Clock is PCLK1 */
  386. default:
  387. i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLK1ClockFreq(RCC_GetSystemClockFreq()));
  388. break;
  389. }
  390. }
  391. #endif
  392. return i2c_frequency;
  393. }
  394. #if defined(LPUART1)
  395. /**
  396. * @brief Return LPUARTx clock frequency
  397. * @param LPUARTxSource This parameter can be one of the following values:
  398. * @arg @ref LL_RCC_LPUART1_CLKSOURCE
  399. * @retval LPUART clock frequency (in Hz)
  400. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
  401. */
  402. uint32_t LL_RCC_GetLPUARTClockFreq(uint32_t LPUARTxSource)
  403. {
  404. uint32_t lpuart_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  405. /* Check parameter */
  406. assert_param(IS_LL_RCC_LPUART_CLKSOURCE(LPUARTxSource));
  407. /* LPUART1CLK clock frequency */
  408. switch (LL_RCC_GetLPUARTClockSource(LPUARTxSource))
  409. {
  410. case LL_RCC_LPUART1_CLKSOURCE_SYSCLK: /* LPUART1 Clock is System Clock */
  411. lpuart_frequency = RCC_GetSystemClockFreq();
  412. break;
  413. case LL_RCC_LPUART1_CLKSOURCE_HSI: /* LPUART1 Clock is HSI Osc. */
  414. if (LL_RCC_HSI_IsReady() == 1U)
  415. {
  416. lpuart_frequency = HSI_VALUE;
  417. }
  418. break;
  419. case LL_RCC_LPUART1_CLKSOURCE_LSE: /* LPUART1 Clock is LSE Osc. */
  420. if (LL_RCC_LSE_IsReady() == 1U)
  421. {
  422. lpuart_frequency = LSE_VALUE;
  423. }
  424. break;
  425. case LL_RCC_LPUART1_CLKSOURCE_PCLK1: /* LPUART1 Clock is PCLK1 */
  426. default:
  427. lpuart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLK1ClockFreq(RCC_GetSystemClockFreq()));
  428. break;
  429. }
  430. return lpuart_frequency;
  431. }
  432. #endif
  433. /**
  434. * @brief Return LPTIMx clock frequency
  435. * @param LPTIMxSource This parameter can be one of the following values:
  436. * @arg @ref LL_RCC_LPTIM1_CLKSOURCE
  437. * @arg @ref LL_RCC_LPTIM2_CLKSOURCE
  438. * @retval LPTIM clock frequency (in Hz)
  439. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI, LSI or LSE) is not ready
  440. */
  441. uint32_t LL_RCC_GetLPTIMClockFreq(uint32_t LPTIMxSource)
  442. {
  443. uint32_t lptim_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  444. uint32_t temp = LL_RCC_LSI2_IsReady();
  445. /* Check parameter */
  446. assert_param(IS_LL_RCC_LPTIM_CLKSOURCE(LPTIMxSource));
  447. if (LPTIMxSource == LL_RCC_LPTIM1_CLKSOURCE)
  448. {
  449. /* LPTIM1CLK clock frequency */
  450. switch (LL_RCC_GetLPTIMClockSource(LPTIMxSource))
  451. {
  452. case LL_RCC_LPTIM1_CLKSOURCE_LSI: /* LPTIM1 Clock is LSI Osc. */
  453. if ((LL_RCC_LSI1_IsReady() == 1UL) || (temp == 1UL))
  454. {
  455. lptim_frequency = LSI_VALUE;
  456. }
  457. break;
  458. case LL_RCC_LPTIM1_CLKSOURCE_HSI: /* LPTIM1 Clock is HSI Osc. */
  459. if (LL_RCC_HSI_IsReady() == 1U)
  460. {
  461. lptim_frequency = HSI_VALUE;
  462. }
  463. break;
  464. case LL_RCC_LPTIM1_CLKSOURCE_LSE: /* LPTIM1 Clock is LSE Osc. */
  465. if (LL_RCC_LSE_IsReady() == 1U)
  466. {
  467. lptim_frequency = LSE_VALUE;
  468. }
  469. break;
  470. case LL_RCC_LPTIM1_CLKSOURCE_PCLK1: /* LPTIM1 Clock is PCLK1 */
  471. default:
  472. lptim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLK1ClockFreq(RCC_GetSystemClockFreq()));
  473. break;
  474. }
  475. }
  476. else
  477. {
  478. /* LPTIM2CLK clock frequency */
  479. switch (LL_RCC_GetLPTIMClockSource(LPTIMxSource))
  480. {
  481. case LL_RCC_LPTIM2_CLKSOURCE_LSI: /* LPTIM2 Clock is LSI Osc. */
  482. if ((LL_RCC_LSI1_IsReady() == 1UL) || (temp == 1UL))
  483. {
  484. lptim_frequency = LSI_VALUE;
  485. }
  486. break;
  487. case LL_RCC_LPTIM2_CLKSOURCE_HSI: /* LPTIM2 Clock is HSI Osc. */
  488. if (LL_RCC_HSI_IsReady() == 1U)
  489. {
  490. lptim_frequency = HSI_VALUE;
  491. }
  492. break;
  493. case LL_RCC_LPTIM2_CLKSOURCE_LSE: /* LPTIM2 Clock is LSE Osc. */
  494. if (LL_RCC_LSE_IsReady() == 1U)
  495. {
  496. lptim_frequency = LSE_VALUE;
  497. }
  498. break;
  499. case LL_RCC_LPTIM2_CLKSOURCE_PCLK1: /* LPTIM2 Clock is PCLK1 */
  500. default:
  501. lptim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLK1ClockFreq(RCC_GetSystemClockFreq()));
  502. break;
  503. }
  504. }
  505. return lptim_frequency;
  506. }
  507. #if defined(SAI1)
  508. /**
  509. * @brief Return SAIx clock frequency
  510. * @param SAIxSource This parameter can be one of the following values:
  511. * @arg @ref LL_RCC_SAI1_CLKSOURCE
  512. *
  513. * @retval SAI clock frequency (in Hz)
  514. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that PLL is not ready
  515. * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that external clock is used
  516. */
  517. uint32_t LL_RCC_GetSAIClockFreq(uint32_t SAIxSource)
  518. {
  519. uint32_t sai_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  520. /* Check parameter */
  521. assert_param(IS_LL_RCC_SAI_CLKSOURCE(SAIxSource));
  522. switch (LL_RCC_GetSAIClockSource(SAIxSource))
  523. {
  524. case LL_RCC_SAI1_CLKSOURCE_HSI: /* HSI clock used as SAI1 clock source */
  525. if (LL_RCC_HSI_IsReady() == 1U)
  526. {
  527. sai_frequency = HSI_VALUE;
  528. }
  529. break;
  530. #if defined(SAI1)
  531. case LL_RCC_SAI1_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as SAI1 clock source */
  532. if (LL_RCC_PLLSAI1_IsReady() == 1U)
  533. {
  534. sai_frequency = RCC_PLLSAI1_GetFreqDomain_SAI();
  535. }
  536. break;
  537. #endif
  538. case LL_RCC_SAI1_CLKSOURCE_PLL: /* PLL clock used as SAI1 clock source */
  539. if (LL_RCC_PLL_IsReady() == 1U)
  540. {
  541. sai_frequency = RCC_PLL_GetFreqDomain_SAI();
  542. }
  543. break;
  544. case LL_RCC_SAI1_CLKSOURCE_PIN: /* External input clock used as SAI1 clock source */
  545. default:
  546. sai_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
  547. break;
  548. }
  549. return sai_frequency;
  550. }
  551. #endif
  552. /**
  553. * @brief Return CLK48x clock frequency
  554. * @param CLK48xSource This parameter can be one of the following values:
  555. * @arg @ref LL_RCC_CLK48_CLKSOURCE
  556. * @retval USB clock frequency (in Hz)
  557. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI or HSI48) or PLLs (PLL or PLLSAI1) is not ready
  558. */
  559. uint32_t LL_RCC_GetCLK48ClockFreq(uint32_t CLK48xSource)
  560. {
  561. uint32_t clk48_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  562. /* Check parameter */
  563. assert_param(IS_LL_RCC_CLK48_CLKSOURCE(CLK48xSource));
  564. /* CLK48CLK clock frequency */
  565. switch (LL_RCC_GetCLK48ClockSource(CLK48xSource))
  566. {
  567. #if defined(SAI1)
  568. case LL_RCC_CLK48_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as CLK48 clock source */
  569. if (LL_RCC_PLLSAI1_IsReady() == 1U)
  570. {
  571. clk48_frequency = RCC_PLLSAI1_GetFreqDomain_48M();
  572. }
  573. break;
  574. #endif
  575. case LL_RCC_CLK48_CLKSOURCE_PLL: /* PLL clock used as CLK48 clock source */
  576. if (LL_RCC_PLL_IsReady() == 1U)
  577. {
  578. clk48_frequency = RCC_PLL_GetFreqDomain_48M();
  579. }
  580. break;
  581. case LL_RCC_CLK48_CLKSOURCE_MSI: /* MSI clock used as CLK48 clock source */
  582. if (LL_RCC_MSI_IsReady() == 1U)
  583. {
  584. clk48_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  585. }
  586. break;
  587. #if defined(RCC_HSI48_SUPPORT)
  588. case LL_RCC_CLK48_CLKSOURCE_HSI48: /* HSI48 clock used as CLK48 clock source */
  589. default:
  590. if (LL_RCC_HSI48_IsReady() == 1U)
  591. {
  592. clk48_frequency = HSI48_VALUE;
  593. }
  594. break;
  595. #else
  596. default:
  597. /* Nothing to do */
  598. break;
  599. #endif
  600. }
  601. return clk48_frequency;
  602. }
  603. #if defined(USB)
  604. /**
  605. * @brief Return USBx clock frequency
  606. * @param USBxSource This parameter can be one of the following values:
  607. * @arg @ref LL_RCC_CLK48_CLKSOURCE
  608. * @retval USB clock frequency (in Hz)
  609. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI or HSI48) or PLLs (PLL or PLLSAI1) is not ready
  610. */
  611. uint32_t LL_RCC_GetUSBClockFreq(uint32_t USBxSource)
  612. {
  613. return LL_RCC_GetCLK48ClockFreq(USBxSource);
  614. }
  615. #endif
  616. /**
  617. * @brief Return RNGx clock frequency
  618. * @param RNGxSource This parameter can be one of the following values:
  619. * @arg @ref LL_RCC_RNG_CLKSOURCE
  620. * @retval RNG clock frequency (in Hz)
  621. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI or HSI48) or PLLs (PLL or PLLSAI1) is not ready
  622. */
  623. uint32_t LL_RCC_GetRNGClockFreq(uint32_t RNGxSource)
  624. {
  625. uint32_t rng_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  626. uint32_t rngClockSource = LL_RCC_GetRNGClockSource(RNGxSource);
  627. /* Check parameter */
  628. assert_param(IS_LL_RCC_RNG_CLKSOURCE(RNGxSource));
  629. /* RNGCLK clock frequency */
  630. if (rngClockSource == LL_RCC_RNG_CLKSOURCE_LSI) /* LSI clock used as RNG clock source */
  631. {
  632. const uint32_t temp_lsi1Status = LL_RCC_LSI1_IsReady();
  633. const uint32_t temp_lsi2Status = LL_RCC_LSI2_IsReady();
  634. if ((temp_lsi1Status == 1U) || (temp_lsi2Status == 1U))
  635. {
  636. rng_frequency = LSI_VALUE;
  637. }
  638. }
  639. else if (rngClockSource == LL_RCC_RNG_CLKSOURCE_LSE) /* LSE clock used as RNG clock source */
  640. {
  641. if (LL_RCC_LSE_IsReady() == 1U)
  642. {
  643. rng_frequency = LSE_VALUE;
  644. }
  645. }
  646. else /* CLK48 clock used as RNG clock source */
  647. {
  648. /* Systematic Div by 3 */
  649. rng_frequency = LL_RCC_GetCLK48ClockFreq(LL_RCC_CLK48_CLKSOURCE) / 3U;
  650. }
  651. return rng_frequency;
  652. }
  653. /**
  654. * @brief Return ADCx clock frequency
  655. * @param ADCxSource This parameter can be one of the following values:
  656. * @arg @ref LL_RCC_ADC_CLKSOURCE
  657. * @retval ADC clock frequency (in Hz)
  658. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI) or PLL is not ready
  659. * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
  660. */
  661. uint32_t LL_RCC_GetADCClockFreq(uint32_t ADCxSource)
  662. {
  663. uint32_t adc_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  664. /* Check parameter */
  665. assert_param(IS_LL_RCC_ADC_CLKSOURCE(ADCxSource));
  666. /* ADCCLK clock frequency */
  667. switch (LL_RCC_GetADCClockSource(ADCxSource))
  668. {
  669. #if defined(SAI1)
  670. case LL_RCC_ADC_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as ADC clock source */
  671. if (LL_RCC_PLLSAI1_IsReady() == 1U)
  672. {
  673. adc_frequency = RCC_PLLSAI1_GetFreqDomain_ADC();
  674. }
  675. break;
  676. #endif
  677. case LL_RCC_ADC_CLKSOURCE_SYSCLK: /* SYSCLK clock used as ADC clock source */
  678. adc_frequency = RCC_GetSystemClockFreq();
  679. break;
  680. case LL_RCC_ADC_CLKSOURCE_PLL: /* PLL clock used as ADC clock source */
  681. if (LL_RCC_PLL_IsReady() == 1U)
  682. {
  683. adc_frequency = RCC_PLL_GetFreqDomain_ADC();
  684. }
  685. break;
  686. case LL_RCC_ADC_CLKSOURCE_NONE: /* No clock used as ADC clock source */
  687. default:
  688. adc_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
  689. break;
  690. }
  691. return adc_frequency;
  692. }
  693. /**
  694. * @brief Return RTC & LCD clock frequency
  695. * @retval RTC clock frequency (in Hz)
  696. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillators (LSI, LSE or HSE) are not ready
  697. * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
  698. */
  699. uint32_t LL_RCC_GetRTCClockFreq(void)
  700. {
  701. uint32_t rtc_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  702. uint32_t temp = LL_RCC_LSI2_IsReady();
  703. /* RTCCLK clock frequency */
  704. switch (LL_RCC_GetRTCClockSource())
  705. {
  706. case LL_RCC_RTC_CLKSOURCE_LSE: /* LSE clock used as RTC clock source */
  707. if (LL_RCC_LSE_IsReady() == 1U)
  708. {
  709. rtc_frequency = LSE_VALUE;
  710. }
  711. break;
  712. case LL_RCC_RTC_CLKSOURCE_LSI: /* LSI clock used as RTC clock source */
  713. if ((LL_RCC_LSI1_IsReady() == 1UL) || (temp == 1UL))
  714. {
  715. rtc_frequency = LSI_VALUE;
  716. }
  717. break;
  718. case LL_RCC_RTC_CLKSOURCE_HSE_DIV32: /* HSE clock used as ADC clock source */
  719. rtc_frequency = HSE_VALUE / 32U;
  720. break;
  721. case LL_RCC_RTC_CLKSOURCE_NONE: /* No clock used as RTC clock source */
  722. default:
  723. rtc_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
  724. break;
  725. }
  726. return rtc_frequency;
  727. }
  728. /**
  729. * @brief Return RF Wakeup clock frequency
  730. * @retval RFWKP clock frequency (in Hz)
  731. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillators (LSI, LSE or HSE) are not ready
  732. * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
  733. */
  734. uint32_t LL_RCC_GetRFWKPClockFreq(void)
  735. {
  736. uint32_t rfwkp_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  737. /* RTCCLK clock frequency */
  738. switch (LL_RCC_GetRFWKPClockSource())
  739. {
  740. case LL_RCC_RFWKP_CLKSOURCE_LSE: /* LSE clock used as RF Wakeup clock source */
  741. if (LL_RCC_LSE_IsReady() == 1U)
  742. {
  743. rfwkp_frequency = LSE_VALUE;
  744. }
  745. break;
  746. case LL_RCC_RFWKP_CLKSOURCE_HSE_DIV1024: /* HSE clock used as RF Wakeup clock source */
  747. rfwkp_frequency = HSE_VALUE / 1024U;
  748. break;
  749. case LL_RCC_RFWKP_CLKSOURCE_NONE: /* No clock used as RF Wakeup clock source */
  750. default:
  751. rfwkp_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
  752. break;
  753. }
  754. return rfwkp_frequency;
  755. }
  756. /**
  757. * @}
  758. */
  759. /**
  760. * @}
  761. */
  762. /** @addtogroup RCC_LL_Private_Functions
  763. * @{
  764. */
  765. /**
  766. * @brief Return SYSTEM clock (SYSCLK) frequency
  767. * @retval SYSTEM clock frequency (in Hz)
  768. */
  769. uint32_t RCC_GetSystemClockFreq(void)
  770. {
  771. uint32_t frequency;
  772. /* Get SYSCLK source -------------------------------------------------------*/
  773. switch (LL_RCC_GetSysClkSource())
  774. {
  775. case LL_RCC_SYS_CLKSOURCE_STATUS_MSI: /* MSI used as system clock source */
  776. frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  777. break;
  778. case LL_RCC_SYS_CLKSOURCE_STATUS_HSI: /* HSI used as system clock source */
  779. frequency = HSI_VALUE;
  780. break;
  781. case LL_RCC_SYS_CLKSOURCE_STATUS_HSE: /* HSE used as system clock source */
  782. if (LL_RCC_HSE_IsEnabledDiv2() == 1U)
  783. {
  784. frequency = HSE_VALUE / 2U;
  785. }
  786. else
  787. {
  788. frequency = HSE_VALUE;
  789. }
  790. break;
  791. case LL_RCC_SYS_CLKSOURCE_STATUS_PLL: /* PLL used as system clock source */
  792. frequency = RCC_PLL_GetFreqDomain_SYS();
  793. break;
  794. default:
  795. frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  796. break;
  797. }
  798. return frequency;
  799. }
  800. /**
  801. * @brief Return HCLK1 clock frequency
  802. * @param SYSCLK_Frequency SYSCLK clock frequency
  803. * @retval HCLK1 clock frequency (in Hz)
  804. */
  805. uint32_t RCC_GetHCLK1ClockFreq(uint32_t SYSCLK_Frequency)
  806. {
  807. /* HCLK clock frequency */
  808. return __LL_RCC_CALC_HCLK1_FREQ(SYSCLK_Frequency, LL_RCC_GetAHBPrescaler());
  809. }
  810. /**
  811. * @brief Return HCLK2 clock frequency
  812. * @param SYSCLK_Frequency SYSCLK clock frequency
  813. * @retval HCLK2 clock frequency (in Hz)
  814. */
  815. uint32_t RCC_GetHCLK2ClockFreq(uint32_t SYSCLK_Frequency)
  816. {
  817. /* HCLK clock frequency */
  818. return __LL_RCC_CALC_HCLK2_FREQ(SYSCLK_Frequency, LL_C2_RCC_GetAHBPrescaler());
  819. }
  820. /**
  821. * @brief Return HCLK clock frequency
  822. * @param SYSCLK_Frequency SYSCLK clock frequency
  823. * @retval HCLK4 clock frequency (in Hz)
  824. */
  825. uint32_t RCC_GetHCLK4ClockFreq(uint32_t SYSCLK_Frequency)
  826. {
  827. /* HCLK clock frequency */
  828. return __LL_RCC_CALC_HCLK4_FREQ(SYSCLK_Frequency, LL_RCC_GetAHB4Prescaler());
  829. }
  830. /**
  831. * @brief Return HCLK5 clock frequency
  832. * @retval HCLK5 clock frequency (in Hz)
  833. */
  834. uint32_t RCC_GetHCLK5ClockFreq(void)
  835. {
  836. uint32_t frequency;
  837. /* Get SYSCLK source -------------------------------------------------------*/
  838. switch (LL_RCC_GetRFClockSource())
  839. {
  840. case LL_RCC_RF_CLKSOURCE_HSI: /* HSI used as system clock source */
  841. frequency = HSI_VALUE;
  842. break;
  843. case LL_RCC_RF_CLKSOURCE_HSE_DIV2: /* HSE Div2 used as system clock source */
  844. frequency = HSE_VALUE / 2U;
  845. break;
  846. default:
  847. frequency = HSI_VALUE;
  848. break;
  849. }
  850. return frequency;
  851. }
  852. /**
  853. * @brief Return PCLK1 clock frequency
  854. * @param HCLK_Frequency HCLK clock frequency
  855. * @retval PCLK1 clock frequency (in Hz)
  856. */
  857. uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency)
  858. {
  859. /* PCLK1 clock frequency */
  860. return __LL_RCC_CALC_PCLK1_FREQ(HCLK_Frequency, LL_RCC_GetAPB1Prescaler());
  861. }
  862. /**
  863. * @brief Return PCLK2 clock frequency
  864. * @param HCLK_Frequency HCLK clock frequency
  865. * @retval PCLK2 clock frequency (in Hz)
  866. */
  867. uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency)
  868. {
  869. /* PCLK2 clock frequency */
  870. return __LL_RCC_CALC_PCLK2_FREQ(HCLK_Frequency, LL_RCC_GetAPB2Prescaler());
  871. }
  872. /**
  873. * @brief Return PLL clock (PLLRCLK) frequency used for system domain
  874. * @retval PLLRCLK clock frequency (in Hz)
  875. */
  876. uint32_t RCC_PLL_GetFreqDomain_SYS(void)
  877. {
  878. uint32_t pllinputfreq, pllsource;
  879. /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI Value/ PLLM) * PLLN
  880. SYSCLK = PLL_VCO / PLLR
  881. */
  882. pllsource = LL_RCC_PLL_GetMainSource();
  883. switch (pllsource)
  884. {
  885. case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLL clock source */
  886. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  887. break;
  888. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  889. pllinputfreq = HSI_VALUE;
  890. break;
  891. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  892. if (LL_RCC_HSE_IsEnabledDiv2() == 1U)
  893. {
  894. pllinputfreq = HSE_VALUE / 2U;
  895. }
  896. else
  897. {
  898. pllinputfreq = HSE_VALUE;
  899. }
  900. break;
  901. default:
  902. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  903. break;
  904. }
  905. return __LL_RCC_CALC_PLLCLK_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  906. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetR());
  907. }
  908. #if defined(SAI1)
  909. /**
  910. * @brief Return PLL clock (PLLPCLK) frequency used for SAI domain
  911. * @retval PLLPCLK clock frequency (in Hz)
  912. */
  913. uint32_t RCC_PLL_GetFreqDomain_SAI(void)
  914. {
  915. uint32_t pllinputfreq, pllsource;
  916. /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI Value / PLLM) * PLLN
  917. SAI Domain clock = PLL_VCO / PLLP
  918. */
  919. pllsource = LL_RCC_PLL_GetMainSource();
  920. switch (pllsource)
  921. {
  922. case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLL clock source */
  923. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  924. break;
  925. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  926. pllinputfreq = HSI_VALUE;
  927. break;
  928. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  929. if (LL_RCC_HSE_IsEnabledDiv2() == 1U)
  930. {
  931. pllinputfreq = HSE_VALUE / 2U;
  932. }
  933. else
  934. {
  935. pllinputfreq = HSE_VALUE;
  936. }
  937. break;
  938. default:
  939. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  940. break;
  941. }
  942. return __LL_RCC_CALC_PLLCLK_SAI_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  943. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetP());
  944. }
  945. #endif
  946. /**
  947. * @brief Return PLL clock (PLLPCLK) frequency used for ADC domain
  948. * @retval PLLPCLK clock frequency (in Hz)
  949. */
  950. uint32_t RCC_PLL_GetFreqDomain_ADC(void)
  951. {
  952. uint32_t pllinputfreq, pllsource;
  953. /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI Value / PLLM) * PLLN
  954. SAI Domain clock = PLL_VCO / PLLP
  955. */
  956. pllsource = LL_RCC_PLL_GetMainSource();
  957. switch (pllsource)
  958. {
  959. case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLL clock source */
  960. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  961. break;
  962. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  963. pllinputfreq = HSI_VALUE;
  964. break;
  965. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  966. if (LL_RCC_HSE_IsEnabledDiv2() == 1U)
  967. {
  968. pllinputfreq = HSE_VALUE / 2U;
  969. }
  970. else
  971. {
  972. pllinputfreq = HSE_VALUE;
  973. }
  974. break;
  975. default:
  976. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  977. break;
  978. }
  979. return __LL_RCC_CALC_PLLCLK_ADC_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  980. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetP());
  981. }
  982. /**
  983. * @brief Return PLL clock (PLLQCLK) frequency used for 48 MHz domain
  984. * @retval PLLQCLK clock frequency (in Hz)
  985. */
  986. uint32_t RCC_PLL_GetFreqDomain_48M(void)
  987. {
  988. uint32_t pllinputfreq, pllsource;
  989. /* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI Value/ PLLM) * PLLN
  990. 48M Domain clock = PLL_VCO / PLLQ
  991. */
  992. pllsource = LL_RCC_PLL_GetMainSource();
  993. switch (pllsource)
  994. {
  995. case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLL clock source */
  996. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  997. break;
  998. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  999. pllinputfreq = HSI_VALUE;
  1000. break;
  1001. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  1002. if (LL_RCC_HSE_IsEnabledDiv2() == 1U)
  1003. {
  1004. pllinputfreq = HSE_VALUE / 2U;
  1005. }
  1006. else
  1007. {
  1008. pllinputfreq = HSE_VALUE;
  1009. }
  1010. break;
  1011. default:
  1012. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  1013. break;
  1014. }
  1015. return __LL_RCC_CALC_PLLCLK_48M_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  1016. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetQ());
  1017. }
  1018. #if defined(SAI1)
  1019. /**
  1020. * @brief Return PLLSAI1 clock (PLLSAI1PCLK) frequency used for SAI domain
  1021. * @retval PLLSAI1PCLK clock frequency (in Hz)
  1022. */
  1023. uint32_t RCC_PLLSAI1_GetFreqDomain_SAI(void)
  1024. {
  1025. uint32_t pllinputfreq, pllsource;
  1026. /* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI Value/ PLLM) * PLLSAI1N */
  1027. /* SAI Domain clock = PLLSAI1_VCO / PLLSAI1P */
  1028. pllsource = LL_RCC_PLL_GetMainSource();
  1029. switch (pllsource)
  1030. {
  1031. case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI1 clock source */
  1032. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  1033. break;
  1034. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI1 clock source */
  1035. pllinputfreq = HSI_VALUE;
  1036. break;
  1037. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI1 clock source */
  1038. if (LL_RCC_HSE_IsEnabledDiv2() == 1U)
  1039. {
  1040. pllinputfreq = HSE_VALUE / 2U;
  1041. }
  1042. else
  1043. {
  1044. pllinputfreq = HSE_VALUE;
  1045. }
  1046. break;
  1047. default:
  1048. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  1049. break;
  1050. }
  1051. return __LL_RCC_CALC_PLLSAI1_SAI_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  1052. LL_RCC_PLLSAI1_GetN(), LL_RCC_PLLSAI1_GetP());
  1053. }
  1054. /**
  1055. * @brief Return PLLSAI1 clock (PLLSAI1QCLK) frequency used for 48Mhz domain
  1056. * @retval PLLSAI1QCLK clock frequency (in Hz)
  1057. */
  1058. uint32_t RCC_PLLSAI1_GetFreqDomain_48M(void)
  1059. {
  1060. uint32_t pllinputfreq, pllsource;
  1061. /* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI Value/ PLLM) * PLLSAI1N */
  1062. /* 48M Domain clock = PLLSAI1_VCO / PLLSAI1Q */
  1063. pllsource = LL_RCC_PLL_GetMainSource();
  1064. switch (pllsource)
  1065. {
  1066. case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI1 clock source */
  1067. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  1068. break;
  1069. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI1 clock source */
  1070. pllinputfreq = HSI_VALUE;
  1071. break;
  1072. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI1 clock source */
  1073. if (LL_RCC_HSE_IsEnabledDiv2() == 1U)
  1074. {
  1075. pllinputfreq = HSE_VALUE / 2U;
  1076. }
  1077. else
  1078. {
  1079. pllinputfreq = HSE_VALUE;
  1080. }
  1081. break;
  1082. default:
  1083. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  1084. break;
  1085. }
  1086. return __LL_RCC_CALC_PLLSAI1_48M_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  1087. LL_RCC_PLLSAI1_GetN(), LL_RCC_PLLSAI1_GetQ());
  1088. }
  1089. /**
  1090. * @brief Return PLLSAI1 clock (PLLSAI1RCLK) frequency used for ADC domain
  1091. * @retval PLLSAI1RCLK clock frequency (in Hz)
  1092. */
  1093. uint32_t RCC_PLLSAI1_GetFreqDomain_ADC(void)
  1094. {
  1095. uint32_t pllinputfreq, pllsource;
  1096. /* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI Value/ PLLM) * PLLSAI1N */
  1097. /* 48M Domain clock = PLLSAI1_VCO / PLLSAI1R */
  1098. pllsource = LL_RCC_PLL_GetMainSource();
  1099. switch (pllsource)
  1100. {
  1101. case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI1 clock source */
  1102. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  1103. break;
  1104. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI1 clock source */
  1105. pllinputfreq = HSI_VALUE;
  1106. break;
  1107. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI1 clock source */
  1108. if (LL_RCC_HSE_IsEnabledDiv2() == 1U)
  1109. {
  1110. pllinputfreq = HSE_VALUE / 2U;
  1111. }
  1112. else
  1113. {
  1114. pllinputfreq = HSE_VALUE;
  1115. }
  1116. break;
  1117. default:
  1118. pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange());
  1119. break;
  1120. }
  1121. return __LL_RCC_CALC_PLLSAI1_ADC_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  1122. LL_RCC_PLLSAI1_GetN(), LL_RCC_PLLSAI1_GetR());
  1123. }
  1124. #endif
  1125. /**
  1126. * @}
  1127. */
  1128. /**
  1129. * @}
  1130. */
  1131. #endif /* defined(RCC) */
  1132. /**
  1133. * @}
  1134. */
  1135. #endif /* USE_FULL_LL_DRIVER */
  1136. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/