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.
 
 
 

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