stm32f0xx_ll_rcc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_ll_rcc.c
  4. * @author MCD Application Team
  5. * @brief RCC LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 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 "stm32f0xx_ll_rcc.h"
  22. #ifdef USE_FULL_ASSERT
  23. #include "stm32_assert.h"
  24. #else
  25. #define assert_param(expr) ((void)0U)
  26. #endif /* USE_FULL_ASSERT */
  27. /** @addtogroup STM32F0xx_LL_Driver
  28. * @{
  29. */
  30. #if defined(RCC)
  31. /** @defgroup RCC_LL RCC
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. /** @addtogroup RCC_LL_Private_Macros
  39. * @{
  40. */
  41. #if defined(RCC_CFGR3_USART2SW) && defined(RCC_CFGR3_USART3SW)
  42. #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \
  43. || ((__VALUE__) == LL_RCC_USART2_CLKSOURCE) \
  44. || ((__VALUE__) == LL_RCC_USART3_CLKSOURCE))
  45. #elif defined(RCC_CFGR3_USART2SW) && !defined(RCC_CFGR3_USART3SW)
  46. #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \
  47. || ((__VALUE__) == LL_RCC_USART2_CLKSOURCE))
  48. #elif defined(RCC_CFGR3_USART3SW) && !defined(RCC_CFGR3_USART2SW)
  49. #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \
  50. || ((__VALUE__) == LL_RCC_USART3_CLKSOURCE))
  51. #else
  52. #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE))
  53. #endif /* RCC_CFGR3_USART2SW && RCC_CFGR3_USART3SW */
  54. #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_I2C1_CLKSOURCE)
  55. #if defined(USB)
  56. #define IS_LL_RCC_USB_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USB_CLKSOURCE))
  57. #endif /* USB */
  58. #if defined(CEC)
  59. #define IS_LL_RCC_CEC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_CEC_CLKSOURCE))
  60. #endif /* CEC */
  61. /**
  62. * @}
  63. */
  64. /* Private function prototypes -----------------------------------------------*/
  65. /** @defgroup RCC_LL_Private_Functions RCC Private functions
  66. * @{
  67. */
  68. uint32_t RCC_GetSystemClockFreq(void);
  69. uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency);
  70. uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency);
  71. uint32_t RCC_PLL_GetFreqDomain_SYS(void);
  72. /**
  73. * @}
  74. */
  75. /* Exported functions --------------------------------------------------------*/
  76. /** @addtogroup RCC_LL_Exported_Functions
  77. * @{
  78. */
  79. /** @addtogroup RCC_LL_EF_Init
  80. * @{
  81. */
  82. /**
  83. * @brief Reset the RCC clock configuration to the default reset state.
  84. * @note The default reset state of the clock configuration is given below:
  85. * - HSI ON and used as system clock source
  86. * - HSE and PLL OFF
  87. * - AHB and APB1 prescaler set to 1.
  88. * - CSS, MCO OFF
  89. * - All interrupts disabled
  90. * @note This function doesn't modify the configuration of the
  91. * - Peripheral clocks
  92. * - LSI, LSE and RTC clocks
  93. * @retval An ErrorStatus enumeration value:
  94. * - SUCCESS: RCC registers are de-initialized
  95. * - ERROR: not applicable
  96. */
  97. ErrorStatus LL_RCC_DeInit(void)
  98. {
  99. __IO uint32_t vl_mask;
  100. /* Set HSION bit */
  101. LL_RCC_HSI_Enable();
  102. /* Wait for HSI READY bit */
  103. while(LL_RCC_HSI_IsReady() != 1U)
  104. {}
  105. /* Set HSITRIM bits to the reset value*/
  106. LL_RCC_HSI_SetCalibTrimming(0x10U);
  107. /* Reset SW, HPRE, PPRE and MCOSEL bits */
  108. vl_mask = 0xFFFFFFFFU;
  109. CLEAR_BIT(vl_mask, (RCC_CFGR_SW | RCC_CFGR_HPRE | RCC_CFGR_PPRE | RCC_CFGR_MCOSEL));
  110. /* Write new value in CFGR register */
  111. LL_RCC_WriteReg(CFGR, vl_mask);
  112. /* Wait till system clock source is ready */
  113. while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
  114. {}
  115. /* Read CR register */
  116. vl_mask = LL_RCC_ReadReg(CR);
  117. /* Reset HSEON, CSSON, PLLON bits */
  118. CLEAR_BIT(vl_mask, (RCC_CR_PLLON | RCC_CR_CSSON | RCC_CR_HSEON));
  119. /* Write new value in CR register */
  120. LL_RCC_WriteReg(CR, vl_mask);
  121. /* Wait for PLL READY bit to be reset */
  122. while(LL_RCC_PLL_IsReady() != 0U)
  123. {}
  124. /* Reset HSEBYP bit */
  125. LL_RCC_HSE_DisableBypass();
  126. /* Reset CFGR register */
  127. LL_RCC_WriteReg(CFGR, 0x00000000U);
  128. #if defined(RCC_HSI48_SUPPORT)
  129. /* Reset CR2 register */
  130. LL_RCC_WriteReg(CR2, 0x00000000U);
  131. /* Disable HSI48 */
  132. LL_RCC_HSI48_Disable();
  133. #endif /*RCC_HSI48_SUPPORT*/
  134. /* Set HSI14TRIM/HSI14ON/HSI14DIS bits to the reset value*/
  135. LL_RCC_HSI14_SetCalibTrimming(0x10U);
  136. LL_RCC_HSI14_Disable();
  137. LL_RCC_HSI14_EnableADCControl();
  138. /* Reset CFGR2 register */
  139. LL_RCC_WriteReg(CFGR2, 0x00000000U);
  140. /* Reset CFGR3 register */
  141. LL_RCC_WriteReg(CFGR3, 0x00000000U);
  142. /* Clear pending flags */
  143. #if defined(RCC_HSI48_SUPPORT)
  144. vl_mask = (LL_RCC_CIR_LSIRDYC | LL_RCC_CIR_LSERDYC | LL_RCC_CIR_HSIRDYC | LL_RCC_CIR_HSERDYC |\
  145. LL_RCC_CIR_PLLRDYC | LL_RCC_CIR_HSI14RDYC | LL_RCC_CIR_HSI48RDYC | LL_RCC_CIR_CSSC);
  146. #else
  147. vl_mask = (LL_RCC_CIR_LSIRDYC | LL_RCC_CIR_LSERDYC | LL_RCC_CIR_HSIRDYC | LL_RCC_CIR_HSERDYC |\
  148. LL_RCC_CIR_PLLRDYC | LL_RCC_CIR_HSI14RDYC | LL_RCC_CIR_CSSC);
  149. #endif /* RCC_HSI48_SUPPORT */
  150. /* Write new value in CIR register */
  151. LL_RCC_WriteReg(CIR, vl_mask);
  152. /* Disable all interrupts */
  153. LL_RCC_WriteReg(CIR, 0x00000000U);
  154. /* Clear reset flags */
  155. LL_RCC_ClearResetFlags();
  156. return SUCCESS;
  157. }
  158. /**
  159. * @}
  160. */
  161. /** @addtogroup RCC_LL_EF_Get_Freq
  162. * @brief Return the frequencies of different on chip clocks; System, AHB and APB1 buses clocks
  163. * and different peripheral clocks available on the device.
  164. * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(**)
  165. * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(***)
  166. * @note If SYSCLK source is PLL, function returns values based on
  167. * HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors.
  168. * @note (**) HSI_VALUE is a defined constant but the real value may vary
  169. * depending on the variations in voltage and temperature.
  170. * @note (***) HSE_VALUE is a defined constant, user has to ensure that
  171. * HSE_VALUE is same as the real frequency of the crystal used.
  172. * Otherwise, this function may have wrong result.
  173. * @note The result of this function could be incorrect when using fractional
  174. * value for HSE crystal.
  175. * @note This function can be used by the user application to compute the
  176. * baud-rate for the communication peripherals or configure other parameters.
  177. * @{
  178. */
  179. /**
  180. * @brief Return the frequencies of different on chip clocks; System, AHB and APB1 buses clocks
  181. * @note Each time SYSCLK, HCLK and/or PCLK1 clock changes, this function
  182. * must be called to update structure fields. Otherwise, any
  183. * configuration based on this function will be incorrect.
  184. * @param RCC_Clocks pointer to a @ref LL_RCC_ClocksTypeDef structure which will hold the clocks frequencies
  185. * @retval None
  186. */
  187. void LL_RCC_GetSystemClocksFreq(LL_RCC_ClocksTypeDef *RCC_Clocks)
  188. {
  189. /* Get SYSCLK frequency */
  190. RCC_Clocks->SYSCLK_Frequency = RCC_GetSystemClockFreq();
  191. /* HCLK clock frequency */
  192. RCC_Clocks->HCLK_Frequency = RCC_GetHCLKClockFreq(RCC_Clocks->SYSCLK_Frequency);
  193. /* PCLK1 clock frequency */
  194. RCC_Clocks->PCLK1_Frequency = RCC_GetPCLK1ClockFreq(RCC_Clocks->HCLK_Frequency);
  195. }
  196. /**
  197. * @brief Return USARTx clock frequency
  198. * @param USARTxSource This parameter can be one of the following values:
  199. * @arg @ref LL_RCC_USART1_CLKSOURCE
  200. * @arg @ref LL_RCC_USART2_CLKSOURCE (*)
  201. * @arg @ref LL_RCC_USART3_CLKSOURCE (*)
  202. *
  203. * (*) value not defined in all devices.
  204. * @retval USART clock frequency (in Hz)
  205. * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
  206. */
  207. uint32_t LL_RCC_GetUSARTClockFreq(uint32_t USARTxSource)
  208. {
  209. uint32_t usart_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  210. /* Check parameter */
  211. assert_param(IS_LL_RCC_USART_CLKSOURCE(USARTxSource));
  212. #if defined(RCC_CFGR3_USART1SW)
  213. if (USARTxSource == LL_RCC_USART1_CLKSOURCE)
  214. {
  215. /* USART1CLK clock frequency */
  216. switch (LL_RCC_GetUSARTClockSource(USARTxSource))
  217. {
  218. case LL_RCC_USART1_CLKSOURCE_SYSCLK: /* USART1 Clock is System Clock */
  219. usart_frequency = RCC_GetSystemClockFreq();
  220. break;
  221. case LL_RCC_USART1_CLKSOURCE_HSI: /* USART1 Clock is HSI Osc. */
  222. if (LL_RCC_HSI_IsReady())
  223. {
  224. usart_frequency = HSI_VALUE;
  225. }
  226. break;
  227. case LL_RCC_USART1_CLKSOURCE_LSE: /* USART1 Clock is LSE Osc. */
  228. if (LL_RCC_LSE_IsReady())
  229. {
  230. usart_frequency = LSE_VALUE;
  231. }
  232. break;
  233. case LL_RCC_USART1_CLKSOURCE_PCLK1: /* USART1 Clock is PCLK1 */
  234. default:
  235. usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  236. break;
  237. }
  238. }
  239. #endif /* RCC_CFGR3_USART1SW */
  240. #if defined(RCC_CFGR3_USART2SW)
  241. if (USARTxSource == LL_RCC_USART2_CLKSOURCE)
  242. {
  243. /* USART2CLK clock frequency */
  244. switch (LL_RCC_GetUSARTClockSource(USARTxSource))
  245. {
  246. case LL_RCC_USART2_CLKSOURCE_SYSCLK: /* USART2 Clock is System Clock */
  247. usart_frequency = RCC_GetSystemClockFreq();
  248. break;
  249. case LL_RCC_USART2_CLKSOURCE_HSI: /* USART2 Clock is HSI Osc. */
  250. if (LL_RCC_HSI_IsReady())
  251. {
  252. usart_frequency = HSI_VALUE;
  253. }
  254. break;
  255. case LL_RCC_USART2_CLKSOURCE_LSE: /* USART2 Clock is LSE Osc. */
  256. if (LL_RCC_LSE_IsReady())
  257. {
  258. usart_frequency = LSE_VALUE;
  259. }
  260. break;
  261. case LL_RCC_USART2_CLKSOURCE_PCLK1: /* USART2 Clock is PCLK1 */
  262. default:
  263. usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  264. break;
  265. }
  266. }
  267. #endif /* RCC_CFGR3_USART2SW */
  268. #if defined(RCC_CFGR3_USART3SW)
  269. if (USARTxSource == LL_RCC_USART3_CLKSOURCE)
  270. {
  271. /* USART3CLK clock frequency */
  272. switch (LL_RCC_GetUSARTClockSource(USARTxSource))
  273. {
  274. case LL_RCC_USART3_CLKSOURCE_SYSCLK: /* USART3 Clock is System Clock */
  275. usart_frequency = RCC_GetSystemClockFreq();
  276. break;
  277. case LL_RCC_USART3_CLKSOURCE_HSI: /* USART3 Clock is HSI Osc. */
  278. if (LL_RCC_HSI_IsReady())
  279. {
  280. usart_frequency = HSI_VALUE;
  281. }
  282. break;
  283. case LL_RCC_USART3_CLKSOURCE_LSE: /* USART3 Clock is LSE Osc. */
  284. if (LL_RCC_LSE_IsReady())
  285. {
  286. usart_frequency = LSE_VALUE;
  287. }
  288. break;
  289. case LL_RCC_USART3_CLKSOURCE_PCLK1: /* USART3 Clock is PCLK1 */
  290. default:
  291. usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  292. break;
  293. }
  294. }
  295. #endif /* RCC_CFGR3_USART3SW */
  296. return usart_frequency;
  297. }
  298. /**
  299. * @brief Return I2Cx clock frequency
  300. * @param I2CxSource This parameter can be one of the following values:
  301. * @arg @ref LL_RCC_I2C1_CLKSOURCE
  302. * @retval I2C clock frequency (in Hz)
  303. * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that HSI oscillator is not ready
  304. */
  305. uint32_t LL_RCC_GetI2CClockFreq(uint32_t I2CxSource)
  306. {
  307. uint32_t i2c_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  308. /* Check parameter */
  309. assert_param(IS_LL_RCC_I2C_CLKSOURCE(I2CxSource));
  310. /* I2C1 CLK clock frequency */
  311. if (I2CxSource == LL_RCC_I2C1_CLKSOURCE)
  312. {
  313. switch (LL_RCC_GetI2CClockSource(I2CxSource))
  314. {
  315. case LL_RCC_I2C1_CLKSOURCE_SYSCLK: /* I2C1 Clock is System Clock */
  316. i2c_frequency = RCC_GetSystemClockFreq();
  317. break;
  318. case LL_RCC_I2C1_CLKSOURCE_HSI: /* I2C1 Clock is HSI Osc. */
  319. default:
  320. if (LL_RCC_HSI_IsReady())
  321. {
  322. i2c_frequency = HSI_VALUE;
  323. }
  324. break;
  325. }
  326. }
  327. return i2c_frequency;
  328. }
  329. #if defined(USB)
  330. /**
  331. * @brief Return USBx clock frequency
  332. * @param USBxSource This parameter can be one of the following values:
  333. * @arg @ref LL_RCC_USB_CLKSOURCE
  334. * @retval USB clock frequency (in Hz)
  335. * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI48) or PLL is not ready
  336. * @arg @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
  337. */
  338. uint32_t LL_RCC_GetUSBClockFreq(uint32_t USBxSource)
  339. {
  340. uint32_t usb_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  341. /* Check parameter */
  342. assert_param(IS_LL_RCC_USB_CLKSOURCE(USBxSource));
  343. /* USBCLK clock frequency */
  344. switch (LL_RCC_GetUSBClockSource(USBxSource))
  345. {
  346. case LL_RCC_USB_CLKSOURCE_PLL: /* PLL clock used as USB clock source */
  347. if (LL_RCC_PLL_IsReady())
  348. {
  349. usb_frequency = RCC_PLL_GetFreqDomain_SYS();
  350. }
  351. break;
  352. #if defined(RCC_CFGR3_USBSW_HSI48)
  353. case LL_RCC_USB_CLKSOURCE_HSI48: /* HSI48 clock used as USB clock source */
  354. default:
  355. if (LL_RCC_HSI48_IsReady())
  356. {
  357. usb_frequency = HSI48_VALUE;
  358. }
  359. break;
  360. #else
  361. case LL_RCC_USB_CLKSOURCE_NONE: /* No clock used as USB clock source */
  362. default:
  363. usb_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
  364. break;
  365. #endif /* RCC_CFGR3_USBSW_HSI48 */
  366. }
  367. return usb_frequency;
  368. }
  369. #endif /* USB */
  370. #if defined(CEC)
  371. /**
  372. * @brief Return CECx clock frequency
  373. * @param CECxSource This parameter can be one of the following values:
  374. * @arg @ref LL_RCC_CEC_CLKSOURCE
  375. * @retval CEC clock frequency (in Hz)
  376. * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillators (HSI or LSE) are not ready
  377. */
  378. uint32_t LL_RCC_GetCECClockFreq(uint32_t CECxSource)
  379. {
  380. uint32_t cec_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  381. /* Check parameter */
  382. assert_param(IS_LL_RCC_CEC_CLKSOURCE(CECxSource));
  383. /* CECCLK clock frequency */
  384. switch (LL_RCC_GetCECClockSource(CECxSource))
  385. {
  386. case LL_RCC_CEC_CLKSOURCE_HSI_DIV244: /* HSI / 244 clock used as CEC clock source */
  387. if (LL_RCC_HSI_IsReady())
  388. {
  389. cec_frequency = HSI_VALUE / 244U;
  390. }
  391. break;
  392. case LL_RCC_CEC_CLKSOURCE_LSE: /* LSE clock used as CEC clock source */
  393. default:
  394. if (LL_RCC_LSE_IsReady())
  395. {
  396. cec_frequency = LSE_VALUE;
  397. }
  398. break;
  399. }
  400. return cec_frequency;
  401. }
  402. #endif /* CEC */
  403. /**
  404. * @}
  405. */
  406. /**
  407. * @}
  408. */
  409. /** @addtogroup RCC_LL_Private_Functions
  410. * @{
  411. */
  412. /**
  413. * @brief Return SYSTEM clock frequency
  414. * @retval SYSTEM clock frequency (in Hz)
  415. */
  416. uint32_t RCC_GetSystemClockFreq(void)
  417. {
  418. uint32_t frequency = 0U;
  419. /* Get SYSCLK source -------------------------------------------------------*/
  420. switch (LL_RCC_GetSysClkSource())
  421. {
  422. case LL_RCC_SYS_CLKSOURCE_STATUS_HSI: /* HSI used as system clock source */
  423. frequency = HSI_VALUE;
  424. break;
  425. case LL_RCC_SYS_CLKSOURCE_STATUS_HSE: /* HSE used as system clock source */
  426. frequency = HSE_VALUE;
  427. break;
  428. case LL_RCC_SYS_CLKSOURCE_STATUS_PLL: /* PLL used as system clock source */
  429. frequency = RCC_PLL_GetFreqDomain_SYS();
  430. break;
  431. #if defined(RCC_HSI48_SUPPORT)
  432. case LL_RCC_SYS_CLKSOURCE_STATUS_HSI48:/* HSI48 used as system clock source */
  433. frequency = HSI48_VALUE;
  434. break;
  435. #endif /* RCC_HSI48_SUPPORT */
  436. default:
  437. frequency = HSI_VALUE;
  438. break;
  439. }
  440. return frequency;
  441. }
  442. /**
  443. * @brief Return HCLK clock frequency
  444. * @param SYSCLK_Frequency SYSCLK clock frequency
  445. * @retval HCLK clock frequency (in Hz)
  446. */
  447. uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency)
  448. {
  449. /* HCLK clock frequency */
  450. return __LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, LL_RCC_GetAHBPrescaler());
  451. }
  452. /**
  453. * @brief Return PCLK1 clock frequency
  454. * @param HCLK_Frequency HCLK clock frequency
  455. * @retval PCLK1 clock frequency (in Hz)
  456. */
  457. uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency)
  458. {
  459. /* PCLK1 clock frequency */
  460. return __LL_RCC_CALC_PCLK1_FREQ(HCLK_Frequency, LL_RCC_GetAPB1Prescaler());
  461. }
  462. /**
  463. * @brief Return PLL clock frequency used for system domain
  464. * @retval PLL clock frequency (in Hz)
  465. */
  466. uint32_t RCC_PLL_GetFreqDomain_SYS(void)
  467. {
  468. uint32_t pllinputfreq = 0U, pllsource = 0U;
  469. /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL divider) * PLL Multiplicator */
  470. /* Get PLL source */
  471. pllsource = LL_RCC_PLL_GetMainSource();
  472. switch (pllsource)
  473. {
  474. #if defined(RCC_PLLSRC_PREDIV1_SUPPORT)
  475. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  476. pllinputfreq = HSI_VALUE;
  477. #else
  478. case LL_RCC_PLLSOURCE_HSI_DIV_2: /* HSI used as PLL clock source */
  479. pllinputfreq = HSI_VALUE / 2U;
  480. #endif /* RCC_PLLSRC_PREDIV1_SUPPORT */
  481. break;
  482. #if defined(RCC_HSI48_SUPPORT)
  483. case LL_RCC_PLLSOURCE_HSI48: /* HSI48 used as PLL clock source */
  484. pllinputfreq = HSI48_VALUE;
  485. break;
  486. #endif /* RCC_HSI48_SUPPORT */
  487. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  488. pllinputfreq = HSE_VALUE;
  489. break;
  490. default:
  491. #if defined(RCC_PLLSRC_PREDIV1_SUPPORT)
  492. pllinputfreq = HSI_VALUE;
  493. #else
  494. pllinputfreq = HSI_VALUE / 2U;
  495. #endif /* RCC_PLLSRC_PREDIV1_SUPPORT */
  496. break;
  497. }
  498. #if defined(RCC_PLLSRC_PREDIV1_SUPPORT)
  499. return __LL_RCC_CALC_PLLCLK_FREQ(pllinputfreq, LL_RCC_PLL_GetMultiplicator(), LL_RCC_PLL_GetPrediv());
  500. #else
  501. return __LL_RCC_CALC_PLLCLK_FREQ((pllinputfreq / (LL_RCC_PLL_GetPrediv() + 1U)), LL_RCC_PLL_GetMultiplicator());
  502. #endif /* RCC_PLLSRC_PREDIV1_SUPPORT */
  503. }
  504. /**
  505. * @}
  506. */
  507. /**
  508. * @}
  509. */
  510. #endif /* defined(RCC) */
  511. /**
  512. * @}
  513. */
  514. #endif /* USE_FULL_LL_DRIVER */
  515. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/