stm32g0xx_ll_rcc.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_ll_rcc.c
  4. * @author MCD Application Team
  5. * @brief RCC LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2018 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 "stm32g0xx_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 STM32G0xx_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. #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
  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(STM32G081xx) || defined(STM32G071xx) || defined(STM32G070xx)
  46. #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \
  47. || ((__VALUE__) == LL_RCC_USART2_CLKSOURCE))
  48. #else
  49. #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_USART1_CLKSOURCE)
  50. #endif /* STM32G0C1xx || STM32G0B1xx || STM32G0B0xx */
  51. #if defined(LPUART1) && defined(LPUART2)
  52. #define IS_LL_RCC_LPUART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LPUART1_CLKSOURCE) \
  53. || ((__VALUE__) == LL_RCC_LPUART2_CLKSOURCE))
  54. #elif defined(LPUART1)
  55. #define IS_LL_RCC_LPUART_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_LPUART1_CLKSOURCE)
  56. #endif /* LPUART1 && LPUART2 */
  57. #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
  58. #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2C1_CLKSOURCE) \
  59. || ((__VALUE__) == LL_RCC_I2C2_CLKSOURCE))
  60. #else
  61. #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_I2C1_CLKSOURCE)
  62. #endif /* STM32G0C1xx || STM32G0B1xx || STM32G0B0xx */
  63. #if defined(LPTIM1) || defined(LPTIM2)
  64. #define IS_LL_RCC_LPTIM_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LPTIM1_CLKSOURCE) \
  65. || ((__VALUE__) == LL_RCC_LPTIM2_CLKSOURCE))
  66. #endif /* LPTIM1 || LPTIM2 */
  67. #if defined(RNG)
  68. #define IS_LL_RCC_RNG_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_RNG_CLKSOURCE))
  69. #endif /* RNG */
  70. #define IS_LL_RCC_ADC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_ADC_CLKSOURCE))
  71. #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
  72. #define IS_LL_RCC_I2S_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2S1_CLKSOURCE) \
  73. || ((__VALUE__) == LL_RCC_I2S2_CLKSOURCE))
  74. #else
  75. #define IS_LL_RCC_I2S_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2S1_CLKSOURCE))
  76. #endif /* STM32G0C1xx || STM32G0B1xx || STM32G0B0xx */
  77. #if defined(CEC)
  78. #define IS_LL_RCC_CEC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_CEC_CLKSOURCE))
  79. #endif /* CEC */
  80. #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
  81. #define IS_LL_RCC_USB_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USB_CLKSOURCE))
  82. #endif /* STM32G0C1xx || STM32G0B1xx || STM32G0B0xx */
  83. #if defined(FDCAN1) || defined(FDCAN2)
  84. #define IS_LL_RCC_FDCAN_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_FDCAN_CLKSOURCE))
  85. #endif /* FDCAN1 || FDCAN2 */
  86. #if defined(RCC_CCIPR_TIM1SEL) && defined(RCC_CCIPR_TIM15SEL)
  87. #define IS_LL_RCC_TIM_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_TIM1_CLKSOURCE) \
  88. || ((__VALUE__) == LL_RCC_TIM15_CLKSOURCE))
  89. #elif defined(RCC_CCIPR_TIM1SEL)
  90. #define IS_LL_RCC_TIM_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_TIM1_CLKSOURCE))
  91. #endif /* RCC_CCIPR_TIM1SEL */
  92. /**
  93. * @}
  94. */
  95. /* Private function prototypes -----------------------------------------------*/
  96. /** @defgroup RCC_LL_Private_Functions RCC Private functions
  97. * @{
  98. */
  99. uint32_t RCC_GetSystemClockFreq(void);
  100. uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency);
  101. uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency);
  102. uint32_t RCC_PLL_GetFreqDomain_SYS(void);
  103. uint32_t RCC_PLL_GetFreqDomain_ADC(void);
  104. uint32_t RCC_PLL_GetFreqDomain_I2S1(void);
  105. #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
  106. uint32_t RCC_PLL_GetFreqDomain_I2S2(void);
  107. uint32_t RCC_PLL_GetFreqDomain_USB(void);
  108. uint32_t RCC_PLL_GetFreqDomain_FDCAN(void);
  109. #endif /* STM32G0C1xx || STM32G0B1xx || STM32G0B0xx */
  110. uint32_t RCC_PLL_GetFreqDomain_RNG(void);
  111. uint32_t RCC_PLL_GetFreqDomain_TIM1(void);
  112. uint32_t RCC_PLL_GetFreqDomain_TIM15(void);
  113. /**
  114. * @}
  115. */
  116. /* Exported functions --------------------------------------------------------*/
  117. /** @addtogroup RCC_LL_Exported_Functions
  118. * @{
  119. */
  120. /** @addtogroup RCC_LL_EF_Init
  121. * @{
  122. */
  123. /**
  124. * @brief Reset the RCC clock configuration to the default reset state.
  125. * @note The default reset state of the clock configuration is given below:
  126. * - HSI ON and used as system clock source
  127. * - HSE and PLL OFF
  128. * - AHB and APB1 prescaler set to 1.
  129. * - CSS, MCO OFF
  130. * - All interrupts disabled
  131. * @note This function does not modify the configuration of the
  132. * - Peripheral clocks
  133. * - LSI, LSE and RTC clocks
  134. * @retval An ErrorStatus enumeration value:
  135. * - SUCCESS: RCC registers are de-initialized
  136. * - ERROR: not applicable
  137. */
  138. ErrorStatus LL_RCC_DeInit(void)
  139. {
  140. /* Set HSION bit and wait for HSI READY bit */
  141. LL_RCC_HSI_Enable();
  142. while (LL_RCC_HSI_IsReady() != 1U)
  143. {}
  144. /* Set HSITRIM bits to reset value*/
  145. LL_RCC_HSI_SetCalibTrimming(0x40U);
  146. /* Reset CFGR register */
  147. LL_RCC_WriteReg(CFGR, 0x00000000U);
  148. /* Reset whole CR register but HSI in 2 steps in case HSEBYP is set */
  149. LL_RCC_WriteReg(CR, RCC_CR_HSION);
  150. while (LL_RCC_HSE_IsReady() != 0U)
  151. {}
  152. LL_RCC_WriteReg(CR, RCC_CR_HSION);
  153. /* Wait for PLL READY bit to be reset */
  154. while (LL_RCC_PLL_IsReady() != 0U)
  155. {}
  156. /* Reset PLLCFGR register */
  157. LL_RCC_WriteReg(PLLCFGR, 16U << RCC_PLLCFGR_PLLN_Pos);
  158. /* Disable all interrupts */
  159. LL_RCC_WriteReg(CIER, 0x00000000U);
  160. /* Clear all interrupts flags */
  161. LL_RCC_WriteReg(CICR, 0xFFFFFFFFU);
  162. return SUCCESS;
  163. }
  164. /**
  165. * @}
  166. */
  167. /** @addtogroup RCC_LL_EF_Get_Freq
  168. * @brief Return the frequencies of different on chip clocks; System, AHB and APB1 buses clocks
  169. * and different peripheral clocks available on the device.
  170. * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE divided by HSI division factor(**)
  171. * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(***)
  172. * @note If SYSCLK source is PLL, function returns values based on HSE_VALUE(***)
  173. * or HSI_VALUE(**) multiplied/divided by the PLL factors.
  174. * @note (**) HSI_VALUE is a constant defined in this file (default value
  175. * 16 MHz) but the real value may vary depending on the variations
  176. * in voltage and temperature.
  177. * @note (***) HSE_VALUE is a constant defined in this file (default value
  178. * 8 MHz), user has to ensure that HSE_VALUE is same as the real
  179. * frequency of the crystal used. Otherwise, this function may
  180. * have wrong result.
  181. * @note The result of this function could be incorrect when using fractional
  182. * value for HSE crystal.
  183. * @note This function can be used by the user application to compute the
  184. * baud-rate for the communication peripherals or configure other parameters.
  185. * @{
  186. */
  187. /**
  188. * @brief Return the frequencies of different on chip clocks; System, AHB and APB1 buses clocks
  189. * @note Each time SYSCLK, HCLK and/or PCLK1 clock changes, this function
  190. * must be called to update structure fields. Otherwise, any
  191. * configuration based on this function will be incorrect.
  192. * @param RCC_Clocks pointer to a @ref LL_RCC_ClocksTypeDef structure which will hold the clocks frequencies
  193. * @retval None
  194. */
  195. void LL_RCC_GetSystemClocksFreq(LL_RCC_ClocksTypeDef *RCC_Clocks)
  196. {
  197. /* Get SYSCLK frequency */
  198. RCC_Clocks->SYSCLK_Frequency = RCC_GetSystemClockFreq();
  199. /* HCLK clock frequency */
  200. RCC_Clocks->HCLK_Frequency = RCC_GetHCLKClockFreq(RCC_Clocks->SYSCLK_Frequency);
  201. /* PCLK1 clock frequency */
  202. RCC_Clocks->PCLK1_Frequency = RCC_GetPCLK1ClockFreq(RCC_Clocks->HCLK_Frequency);
  203. }
  204. /**
  205. * @brief Return USARTx clock frequency
  206. * @param USARTxSource This parameter can be one of the following values:
  207. * @arg @ref LL_RCC_USART1_CLKSOURCE
  208. * @arg @ref LL_RCC_USART2_CLKSOURCE
  209. * @arg @ref LL_RCC_USART3_CLKSOURCE
  210. * @retval USART clock frequency (in Hz)
  211. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
  212. */
  213. uint32_t LL_RCC_GetUSARTClockFreq(uint32_t USARTxSource)
  214. {
  215. uint32_t usart_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  216. /* Check parameter */
  217. assert_param(IS_LL_RCC_USART_CLKSOURCE(USARTxSource));
  218. if (USARTxSource == LL_RCC_USART1_CLKSOURCE)
  219. {
  220. /* USART1CLK clock frequency */
  221. switch (LL_RCC_GetUSARTClockSource(USARTxSource))
  222. {
  223. case LL_RCC_USART1_CLKSOURCE_SYSCLK: /* USART1 Clock is System Clock */
  224. usart_frequency = RCC_GetSystemClockFreq();
  225. break;
  226. case LL_RCC_USART1_CLKSOURCE_HSI: /* USART1 Clock is HSI Osc. */
  227. if (LL_RCC_HSI_IsReady() == 1U)
  228. {
  229. usart_frequency = HSI_VALUE;
  230. }
  231. break;
  232. case LL_RCC_USART1_CLKSOURCE_LSE: /* USART1 Clock is LSE Osc. */
  233. if (LL_RCC_LSE_IsReady() == 1U)
  234. {
  235. usart_frequency = LSE_VALUE;
  236. }
  237. break;
  238. case LL_RCC_USART1_CLKSOURCE_PCLK1: /* USART1 Clock is PCLK1 */
  239. default:
  240. usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  241. break;
  242. }
  243. }
  244. #if defined(RCC_CCIPR_USART2SEL)
  245. else if (USARTxSource == LL_RCC_USART2_CLKSOURCE)
  246. {
  247. /* USART2CLK clock frequency */
  248. switch (LL_RCC_GetUSARTClockSource(USARTxSource))
  249. {
  250. case LL_RCC_USART2_CLKSOURCE_SYSCLK: /* USART2 Clock is System Clock */
  251. usart_frequency = RCC_GetSystemClockFreq();
  252. break;
  253. case LL_RCC_USART2_CLKSOURCE_HSI: /* USART2 Clock is HSI Osc. */
  254. if (LL_RCC_HSI_IsReady() == 1U)
  255. {
  256. usart_frequency = HSI_VALUE;
  257. }
  258. break;
  259. case LL_RCC_USART2_CLKSOURCE_LSE: /* USART2 Clock is LSE Osc. */
  260. if (LL_RCC_LSE_IsReady() == 1U)
  261. {
  262. usart_frequency = LSE_VALUE;
  263. }
  264. break;
  265. case LL_RCC_USART2_CLKSOURCE_PCLK1: /* USART2 Clock is PCLK1 */
  266. default:
  267. usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  268. break;
  269. }
  270. }
  271. #endif /* RCC_CCIPR_USART2SEL */
  272. #if defined(RCC_CCIPR_USART3SEL)
  273. else if (USARTxSource == LL_RCC_USART3_CLKSOURCE)
  274. {
  275. /* USART3CLK clock frequency */
  276. switch (LL_RCC_GetUSARTClockSource(USARTxSource))
  277. {
  278. case LL_RCC_USART3_CLKSOURCE_SYSCLK: /* USART3 Clock is System Clock */
  279. usart_frequency = RCC_GetSystemClockFreq();
  280. break;
  281. case LL_RCC_USART3_CLKSOURCE_HSI: /* USART3 Clock is HSI Osc. */
  282. if (LL_RCC_HSI_IsReady() == 1U)
  283. {
  284. usart_frequency = HSI_VALUE;
  285. }
  286. break;
  287. case LL_RCC_USART3_CLKSOURCE_LSE: /* USART3 Clock is LSE Osc. */
  288. if (LL_RCC_LSE_IsReady() == 1U)
  289. {
  290. usart_frequency = LSE_VALUE;
  291. }
  292. break;
  293. case LL_RCC_USART3_CLKSOURCE_PCLK1: /* USART3 Clock is PCLK1 */
  294. default:
  295. usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  296. break;
  297. }
  298. }
  299. #endif /* RCC_CCIPR_USART3SEL */
  300. else
  301. {
  302. /* nothing to do */
  303. }
  304. return usart_frequency;
  305. }
  306. /**
  307. * @brief Return I2Cx clock frequency
  308. * @param I2CxSource This parameter can be one of the following values:
  309. * @arg @ref LL_RCC_I2C1_CLKSOURCE
  310. * @retval I2C clock frequency (in Hz)
  311. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that HSI oscillator is not ready
  312. */
  313. uint32_t LL_RCC_GetI2CClockFreq(uint32_t I2CxSource)
  314. {
  315. uint32_t i2c_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  316. /* Check parameter */
  317. assert_param(IS_LL_RCC_I2C_CLKSOURCE(I2CxSource));
  318. if (I2CxSource == LL_RCC_I2C1_CLKSOURCE)
  319. {
  320. /* I2C1 CLK clock frequency */
  321. switch (LL_RCC_GetI2CClockSource(I2CxSource))
  322. {
  323. case LL_RCC_I2C1_CLKSOURCE_SYSCLK: /* I2C1 Clock is System Clock */
  324. i2c_frequency = RCC_GetSystemClockFreq();
  325. break;
  326. case LL_RCC_I2C1_CLKSOURCE_HSI: /* I2C1 Clock is HSI Osc. */
  327. if (LL_RCC_HSI_IsReady() == 1U)
  328. {
  329. i2c_frequency = HSI_VALUE;
  330. }
  331. break;
  332. case LL_RCC_I2C1_CLKSOURCE_PCLK1: /* I2C1 Clock is PCLK1 */
  333. default:
  334. i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  335. break;
  336. }
  337. }
  338. #if defined(RCC_CCIPR_I2C2SEL)
  339. else if (I2CxSource == LL_RCC_I2C2_CLKSOURCE)
  340. {
  341. /* I2C2 CLK clock frequency */
  342. switch (LL_RCC_GetI2CClockSource(I2CxSource))
  343. {
  344. case LL_RCC_I2C2_CLKSOURCE_SYSCLK: /* I2C2 Clock is System Clock */
  345. i2c_frequency = RCC_GetSystemClockFreq();
  346. break;
  347. case LL_RCC_I2C2_CLKSOURCE_HSI: /* I2C2 Clock is HSI Osc. */
  348. if (LL_RCC_HSI_IsReady() == 1U)
  349. {
  350. i2c_frequency = HSI_VALUE;
  351. }
  352. break;
  353. case LL_RCC_I2C2_CLKSOURCE_PCLK1: /* I2C2 Clock is PCLK1 */
  354. default:
  355. i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  356. break;
  357. }
  358. }
  359. #endif /* RCC_CCIPR_I2C2SEL */
  360. else
  361. {
  362. }
  363. return i2c_frequency;
  364. }
  365. /**
  366. * @brief Return I2Sx clock frequency
  367. * @param I2SxSource This parameter can be one of the following values:
  368. * @arg @ref LL_RCC_I2S1_CLKSOURCE
  369. * @retval I2S clock frequency (in Hz)
  370. * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready
  371. */
  372. uint32_t LL_RCC_GetI2SClockFreq(uint32_t I2SxSource)
  373. {
  374. uint32_t i2s_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  375. /* Check parameter */
  376. assert_param(IS_LL_RCC_I2S_CLKSOURCE(I2SxSource));
  377. if (I2SxSource == LL_RCC_I2S1_CLKSOURCE)
  378. {
  379. /* I2S1 CLK clock frequency */
  380. switch (LL_RCC_GetI2SClockSource(I2SxSource))
  381. {
  382. case LL_RCC_I2S1_CLKSOURCE_HSI: /* I2S1 Clock is HSI */
  383. i2s_frequency = HSI_VALUE;
  384. break;
  385. case LL_RCC_I2S1_CLKSOURCE_PLL: /* I2S1 Clock is PLL"P" */
  386. if (LL_RCC_PLL_IsReady() == 1U)
  387. {
  388. i2s_frequency = RCC_PLL_GetFreqDomain_I2S1();
  389. }
  390. break;
  391. case LL_RCC_I2S1_CLKSOURCE_PIN: /* I2S1 Clock is External clock */
  392. i2s_frequency = EXTERNAL_CLOCK_VALUE;
  393. break;
  394. case LL_RCC_I2S1_CLKSOURCE_SYSCLK: /* I2S1 Clock is System Clock */
  395. default:
  396. i2s_frequency = RCC_GetSystemClockFreq();
  397. break;
  398. }
  399. }
  400. #if defined(RCC_CCIPR2_I2S2SEL)
  401. else if (I2SxSource == LL_RCC_I2S2_CLKSOURCE)
  402. {
  403. /* I2S2 CLK clock frequency */
  404. switch (LL_RCC_GetI2SClockSource(I2SxSource))
  405. {
  406. case LL_RCC_I2S2_CLKSOURCE_HSI: /* I2S2 Clock is HSI */
  407. i2s_frequency = HSI_VALUE;
  408. break;
  409. case LL_RCC_I2S2_CLKSOURCE_PLL: /* I2S2 Clock is PLL"P" */
  410. if (LL_RCC_PLL_IsReady() == 1U)
  411. {
  412. i2s_frequency = RCC_PLL_GetFreqDomain_I2S2();
  413. }
  414. break;
  415. case LL_RCC_I2S2_CLKSOURCE_PIN: /* I2S2 Clock is External clock */
  416. i2s_frequency = EXTERNAL_CLOCK_VALUE;
  417. break;
  418. case LL_RCC_I2S2_CLKSOURCE_SYSCLK: /* I2S2 Clock is System Clock */
  419. default:
  420. i2s_frequency = RCC_GetSystemClockFreq();
  421. break;
  422. }
  423. }
  424. #endif /* RCC_CCIPR2_I2S2SEL */
  425. else
  426. {
  427. }
  428. return i2s_frequency;
  429. }
  430. #if defined(LPUART1) || defined(LPUART2)
  431. /**
  432. * @brief Return LPUARTx clock frequency
  433. * @param LPUARTxSource This parameter can be one of the following values:
  434. * @arg @ref LL_RCC_LPUART1_CLKSOURCE
  435. * @arg @ref LL_RCC_LPUART2_CLKSOURCE (*)
  436. * @retval LPUART clock frequency (in Hz)
  437. * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
  438. * (*) feature not available on all devices
  439. */
  440. uint32_t LL_RCC_GetLPUARTClockFreq(uint32_t LPUARTxSource)
  441. {
  442. uint32_t lpuart_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  443. /* Check parameter */
  444. assert_param(IS_LL_RCC_LPUART_CLKSOURCE(LPUARTxSource));
  445. if (LPUARTxSource == LL_RCC_LPUART1_CLKSOURCE)
  446. {
  447. /* LPUART1CLK clock frequency */
  448. switch (LL_RCC_GetLPUARTClockSource(LPUARTxSource))
  449. {
  450. case LL_RCC_LPUART1_CLKSOURCE_SYSCLK: /* LPUART1 Clock is System Clock */
  451. lpuart_frequency = RCC_GetSystemClockFreq();
  452. break;
  453. case LL_RCC_LPUART1_CLKSOURCE_HSI: /* LPUART1 Clock is HSI Osc. */
  454. if (LL_RCC_HSI_IsReady() == 1U)
  455. {
  456. lpuart_frequency = HSI_VALUE;
  457. }
  458. break;
  459. case LL_RCC_LPUART1_CLKSOURCE_LSE: /* LPUART1 Clock is LSE Osc. */
  460. if (LL_RCC_LSE_IsReady() == 1U)
  461. {
  462. lpuart_frequency = LSE_VALUE;
  463. }
  464. break;
  465. case LL_RCC_LPUART1_CLKSOURCE_PCLK1: /* LPUART1 Clock is PCLK1 */
  466. default:
  467. lpuart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  468. break;
  469. }
  470. }
  471. #if defined(LPUART2)
  472. else if (LPUARTxSource == LL_RCC_LPUART2_CLKSOURCE)
  473. {
  474. /* LPUART2CLK clock frequency */
  475. switch (LL_RCC_GetLPUARTClockSource(LPUARTxSource))
  476. {
  477. case LL_RCC_LPUART2_CLKSOURCE_SYSCLK: /* LPUART2 Clock is System Clock */
  478. lpuart_frequency = RCC_GetSystemClockFreq();
  479. break;
  480. case LL_RCC_LPUART2_CLKSOURCE_HSI: /* LPUART2 Clock is HSI Osc. */
  481. if (LL_RCC_HSI_IsReady() == 1U)
  482. {
  483. lpuart_frequency = HSI_VALUE;
  484. }
  485. break;
  486. case LL_RCC_LPUART2_CLKSOURCE_LSE: /* LPUART2 Clock is LSE Osc. */
  487. if (LL_RCC_LSE_IsReady() == 1U)
  488. {
  489. lpuart_frequency = LSE_VALUE;
  490. }
  491. break;
  492. case LL_RCC_LPUART2_CLKSOURCE_PCLK1: /* LPUART2 Clock is PCLK1 */
  493. default:
  494. lpuart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  495. break;
  496. }
  497. }
  498. #endif /* LPUART2 */
  499. else
  500. {
  501. }
  502. return lpuart_frequency;
  503. }
  504. #endif /* LPUART1 */
  505. #if defined(LPTIM1) && defined(LPTIM2)
  506. /**
  507. * @brief Return LPTIMx clock frequency
  508. * @param LPTIMxSource This parameter can be one of the following values:
  509. * @arg @ref LL_RCC_LPTIM1_CLKSOURCE
  510. * @arg @ref LL_RCC_LPTIM2_CLKSOURCE
  511. * @retval LPTIM clock frequency (in Hz)
  512. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI, LSI or LSE) is not ready
  513. */
  514. uint32_t LL_RCC_GetLPTIMClockFreq(uint32_t LPTIMxSource)
  515. {
  516. uint32_t lptim_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  517. /* Check parameter */
  518. assert_param(IS_LL_RCC_LPTIM_CLKSOURCE(LPTIMxSource));
  519. if (LPTIMxSource == LL_RCC_LPTIM1_CLKSOURCE)
  520. {
  521. /* LPTIM1CLK clock frequency */
  522. switch (LL_RCC_GetLPTIMClockSource(LPTIMxSource))
  523. {
  524. case LL_RCC_LPTIM1_CLKSOURCE_LSI: /* LPTIM1 Clock is LSI Osc. */
  525. if (LL_RCC_LSI_IsReady() == 1U)
  526. {
  527. lptim_frequency = LSI_VALUE;
  528. }
  529. break;
  530. case LL_RCC_LPTIM1_CLKSOURCE_HSI: /* LPTIM1 Clock is HSI Osc. */
  531. if (LL_RCC_HSI_IsReady() == 1U)
  532. {
  533. lptim_frequency = HSI_VALUE;
  534. }
  535. break;
  536. case LL_RCC_LPTIM1_CLKSOURCE_LSE: /* LPTIM1 Clock is LSE Osc. */
  537. if (LL_RCC_LSE_IsReady() == 1U)
  538. {
  539. lptim_frequency = LSE_VALUE;
  540. }
  541. break;
  542. case LL_RCC_LPTIM1_CLKSOURCE_PCLK1: /* LPTIM1 Clock is PCLK1 */
  543. default:
  544. lptim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  545. break;
  546. }
  547. }
  548. else
  549. {
  550. /* LPTIM2CLK clock frequency */
  551. switch (LL_RCC_GetLPTIMClockSource(LPTIMxSource))
  552. {
  553. case LL_RCC_LPTIM2_CLKSOURCE_LSI: /* LPTIM2 Clock is LSI Osc. */
  554. if (LL_RCC_LSI_IsReady() == 1U)
  555. {
  556. lptim_frequency = LSI_VALUE;
  557. }
  558. break;
  559. case LL_RCC_LPTIM2_CLKSOURCE_HSI: /* LPTIM2 Clock is HSI Osc. */
  560. if (LL_RCC_HSI_IsReady() == 1U)
  561. {
  562. lptim_frequency = HSI_VALUE;
  563. }
  564. break;
  565. case LL_RCC_LPTIM2_CLKSOURCE_LSE: /* LPTIM2 Clock is LSE Osc. */
  566. if (LL_RCC_LSE_IsReady() == 1U)
  567. {
  568. lptim_frequency = LSE_VALUE;
  569. }
  570. break;
  571. case LL_RCC_LPTIM2_CLKSOURCE_PCLK1: /* LPTIM2 Clock is PCLK1 */
  572. default:
  573. lptim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  574. break;
  575. }
  576. }
  577. return lptim_frequency;
  578. }
  579. #endif /* LPTIM1 && LPTIM2 */
  580. #if defined(RCC_CCIPR_TIM1SEL) || defined(RCC_CCIPR_TIM15SEL)
  581. /**
  582. * @brief Return TIMx clock frequency
  583. * @param TIMxSource This parameter can be one of the following values:
  584. * @arg @ref LL_RCC_TIM1_CLKSOURCE
  585. * @if defined(STM32G081xx)
  586. * @arg @ref LL_RCC_TIM15_CLKSOURCE
  587. * @endif
  588. * @retval TIMx clock frequency (in Hz)
  589. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
  590. */
  591. uint32_t LL_RCC_GetTIMClockFreq(uint32_t TIMxSource)
  592. {
  593. uint32_t tim_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  594. /* Check parameter */
  595. assert_param(IS_LL_RCC_TIM_CLKSOURCE(TIMxSource));
  596. if (TIMxSource == LL_RCC_TIM1_CLKSOURCE)
  597. {
  598. /* TIM1CLK clock frequency */
  599. switch (LL_RCC_GetTIMClockSource(TIMxSource))
  600. {
  601. case LL_RCC_TIM1_CLKSOURCE_PLL: /* TIM1 Clock is PLLQ */
  602. if (LL_RCC_PLL_IsReady() == 1U)
  603. {
  604. tim_frequency = RCC_PLL_GetFreqDomain_TIM1();
  605. }
  606. break;
  607. case LL_RCC_TIM1_CLKSOURCE_PCLK1: /* TIM1 Clock is PCLK1 */
  608. default:
  609. tim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  610. break;
  611. }
  612. }
  613. #if defined(TIM15)
  614. else
  615. {
  616. if (TIMxSource == LL_RCC_TIM15_CLKSOURCE)
  617. {
  618. /* TIM15CLK clock frequency */
  619. switch (LL_RCC_GetTIMClockSource(TIMxSource))
  620. {
  621. case LL_RCC_TIM15_CLKSOURCE_PLL: /* TIM1 Clock is PLLQ */
  622. if (LL_RCC_PLL_IsReady() == 1U)
  623. {
  624. tim_frequency = RCC_PLL_GetFreqDomain_TIM15();
  625. }
  626. break;
  627. case LL_RCC_TIM15_CLKSOURCE_PCLK1: /* TIM15 Clock is PCLK1 */
  628. default:
  629. tim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  630. break;
  631. }
  632. }
  633. }
  634. #endif /* TIM15 */
  635. return tim_frequency;
  636. }
  637. #endif /* RCC_CCIPR_TIM1SEL && RCC_CCIPR_TIM15SEL */
  638. #if defined(RNG)
  639. /**
  640. * @brief Return RNGx clock frequency
  641. * @param RNGxSource This parameter can be one of the following values:
  642. * @arg @ref LL_RCC_RNG_CLKSOURCE
  643. * @retval RNG clock frequency (in Hz)
  644. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI) or PLL is not ready
  645. * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
  646. */
  647. uint32_t LL_RCC_GetRNGClockFreq(uint32_t RNGxSource)
  648. {
  649. uint32_t rng_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  650. uint32_t rngdiv;
  651. /* Check parameter */
  652. assert_param(IS_LL_RCC_RNG_CLKSOURCE(RNGxSource));
  653. /* RNGCLK clock frequency */
  654. switch (LL_RCC_GetRNGClockSource(RNGxSource))
  655. {
  656. case LL_RCC_RNG_CLKSOURCE_PLL: /* PLL clock used as RNG clock source */
  657. if (LL_RCC_PLL_IsReady() == 1U)
  658. {
  659. rng_frequency = RCC_PLL_GetFreqDomain_RNG();
  660. rngdiv = (1UL << ((READ_BIT(RCC->CCIPR, RCC_CCIPR_RNGDIV)) >> RCC_CCIPR_RNGDIV_Pos));
  661. rng_frequency = (rng_frequency / rngdiv);
  662. }
  663. break;
  664. case LL_RCC_RNG_CLKSOURCE_HSI_DIV8: /* HSI clock divided by 8 used as RNG clock source */
  665. rng_frequency = HSI_VALUE / 8U;
  666. rngdiv = (1UL << ((READ_BIT(RCC->CCIPR, RCC_CCIPR_RNGDIV)) >> RCC_CCIPR_RNGDIV_Pos));
  667. rng_frequency = (rng_frequency / rngdiv);
  668. break;
  669. case LL_RCC_RNG_CLKSOURCE_SYSCLK: /* SYSCLK clock used as RNG clock source */
  670. rng_frequency = RCC_GetSystemClockFreq();
  671. rngdiv = (1UL << ((READ_BIT(RCC->CCIPR, RCC_CCIPR_RNGDIV)) >> RCC_CCIPR_RNGDIV_Pos));
  672. rng_frequency = (rng_frequency / rngdiv);
  673. break;
  674. case LL_RCC_RNG_CLKSOURCE_NONE: /* No clock used as RNG clock source */
  675. default:
  676. rng_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
  677. break;
  678. }
  679. return rng_frequency;
  680. }
  681. #endif /* RNG */
  682. #if defined(CEC)
  683. /**
  684. * @brief Return CEC clock frequency
  685. * @param CECxSource This parameter can be one of the following values:
  686. * @arg @ref LL_RCC_CEC_CLKSOURCE
  687. * @retval CEC clock frequency (in Hz)
  688. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
  689. */
  690. uint32_t LL_RCC_GetCECClockFreq(uint32_t CECxSource)
  691. {
  692. uint32_t cec_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  693. /* Check parameter */
  694. assert_param(IS_LL_RCC_CEC_CLKSOURCE(CECxSource));
  695. /* CECCLK clock frequency */
  696. switch (LL_RCC_GetCECClockSource(CECxSource))
  697. {
  698. case LL_RCC_CEC_CLKSOURCE_LSE: /* CEC Clock is LSE Osc. */
  699. if (LL_RCC_LSE_IsReady() == 1U)
  700. {
  701. cec_frequency = LSE_VALUE;
  702. }
  703. break;
  704. case LL_RCC_CEC_CLKSOURCE_HSI_DIV488: /* CEC Clock is HSI Osc. */
  705. default:
  706. if (LL_RCC_HSI_IsReady() == 1U)
  707. {
  708. cec_frequency = (HSI_VALUE / 488U);
  709. }
  710. break;
  711. }
  712. return cec_frequency;
  713. }
  714. #endif /* CEC */
  715. #if defined(FDCAN1) || defined(FDCAN2)
  716. /**
  717. * @brief Return FDCANx clock frequency
  718. * @param FDCANxSource This parameter can be one of the following values:
  719. * @arg @ref LL_RCC_FDCAN_CLKSOURCE
  720. * @retval FDCANx clock frequency (in Hz)
  721. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI, LSI or LSE) is not ready
  722. */
  723. uint32_t LL_RCC_GetFDCANClockFreq(uint32_t FDCANxSource)
  724. {
  725. uint32_t fdcan_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  726. /* Check parameter */
  727. assert_param(IS_LL_RCC_FDCAN_CLKSOURCE(FDCANxSource));
  728. /* FDCANCLK clock frequency */
  729. switch (LL_RCC_GetFDCANClockSource(FDCANxSource))
  730. {
  731. case LL_RCC_FDCAN_CLKSOURCE_PLL: /* FDCAN Clock is PLL "Q" Osc. */
  732. if (LL_RCC_PLL_IsReady() == 1U)
  733. {
  734. fdcan_frequency = RCC_PLL_GetFreqDomain_FDCAN();
  735. }
  736. break;
  737. case LL_RCC_FDCAN_CLKSOURCE_HSE: /* FDCAN Clock is HSE Osc. */
  738. if (LL_RCC_HSE_IsReady() == 1U)
  739. {
  740. fdcan_frequency = HSE_VALUE;
  741. }
  742. break;
  743. case LL_RCC_FDCAN_CLKSOURCE_PCLK1: /* FDCAN Clock is PCLK1 */
  744. default:
  745. fdcan_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
  746. break;
  747. }
  748. return fdcan_frequency;
  749. }
  750. #endif /* FDCAN1 || FDCAN2 */
  751. /**
  752. * @brief Return ADCx clock frequency
  753. * @param ADCxSource This parameter can be one of the following values:
  754. * @arg @ref LL_RCC_ADC_CLKSOURCE
  755. * @retval ADC clock frequency (in Hz)
  756. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI) or PLL is not ready
  757. * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
  758. */
  759. uint32_t LL_RCC_GetADCClockFreq(uint32_t ADCxSource)
  760. {
  761. uint32_t adc_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  762. /* Check parameter */
  763. assert_param(IS_LL_RCC_ADC_CLKSOURCE(ADCxSource));
  764. /* ADCCLK clock frequency */
  765. switch (LL_RCC_GetADCClockSource(ADCxSource))
  766. {
  767. case LL_RCC_ADC_CLKSOURCE_SYSCLK: /* SYSCLK clock used as ADC clock source */
  768. adc_frequency = RCC_GetSystemClockFreq();
  769. break;
  770. case LL_RCC_ADC_CLKSOURCE_HSI : /* HSI clock used as ADC clock source */
  771. adc_frequency = HSI_VALUE;
  772. break;
  773. case LL_RCC_ADC_CLKSOURCE_PLL: /* PLLP clock used as ADC clock source */
  774. if (LL_RCC_PLL_IsReady() == 1U)
  775. {
  776. adc_frequency = RCC_PLL_GetFreqDomain_ADC();
  777. }
  778. break;
  779. default:
  780. adc_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
  781. break;
  782. }
  783. return adc_frequency;
  784. }
  785. /**
  786. * @brief Return RTC clock frequency
  787. * @retval RTC clock frequency (in Hz)
  788. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillators (LSI, LSE or HSE) are not ready
  789. * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
  790. */
  791. uint32_t LL_RCC_GetRTCClockFreq(void)
  792. {
  793. uint32_t rtc_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  794. /* RTCCLK clock frequency */
  795. switch (LL_RCC_GetRTCClockSource())
  796. {
  797. case LL_RCC_RTC_CLKSOURCE_LSE: /* LSE clock used as RTC clock source */
  798. if (LL_RCC_LSE_IsReady() == 1U)
  799. {
  800. rtc_frequency = LSE_VALUE;
  801. }
  802. break;
  803. case LL_RCC_RTC_CLKSOURCE_LSI: /* LSI clock used as RTC clock source */
  804. if (LL_RCC_LSI_IsReady() == 1U)
  805. {
  806. rtc_frequency = LSI_VALUE;
  807. }
  808. break;
  809. case LL_RCC_RTC_CLKSOURCE_HSE_DIV32: /* HSE clock used as ADC clock source */
  810. rtc_frequency = HSE_VALUE / 32U;
  811. break;
  812. case LL_RCC_RTC_CLKSOURCE_NONE: /* No clock used as RTC clock source */
  813. default:
  814. rtc_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
  815. break;
  816. }
  817. return rtc_frequency;
  818. }
  819. #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
  820. /**
  821. * @brief Return USBx clock frequency
  822. * @param USBxSource This parameter can be one of the following values:
  823. * @arg @ref LL_RCC_USB_CLKSOURCE
  824. * @retval USB clock frequency (in Hz)
  825. * - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI48) or PLL is not ready
  826. * - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
  827. */
  828. uint32_t LL_RCC_GetUSBClockFreq(uint32_t USBxSource)
  829. {
  830. uint32_t usb_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
  831. /* Check parameter */
  832. assert_param(IS_LL_RCC_USB_CLKSOURCE(USBxSource));
  833. /* USBCLK clock frequency */
  834. switch (LL_RCC_GetUSBClockSource(USBxSource))
  835. {
  836. #if defined(RCC_HSI48_SUPPORT)
  837. case LL_RCC_USB_CLKSOURCE_HSI48: /* HSI48 used as USB clock source */
  838. if (LL_RCC_HSI48_IsReady() != 0U)
  839. {
  840. usb_frequency = HSI48_VALUE;
  841. }
  842. break;
  843. #endif /* RCC_HSI48_SUPPORT */
  844. case LL_RCC_USB_CLKSOURCE_HSE: /* HSE used as USB clock source */
  845. if (LL_RCC_HSE_IsReady() != 0U)
  846. {
  847. usb_frequency = HSE_VALUE;
  848. }
  849. break;
  850. case LL_RCC_USB_CLKSOURCE_PLL: /* PLL clock used as USB clock source */
  851. if (LL_RCC_PLL_IsReady() != 0U)
  852. {
  853. usb_frequency = RCC_PLL_GetFreqDomain_USB();
  854. }
  855. break;
  856. default:
  857. usb_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
  858. break;
  859. }
  860. return usb_frequency;
  861. }
  862. #endif /* STM32G0C1xx || STM32G0B1xx || STM32G0B0xx) */
  863. /**
  864. * @}
  865. */
  866. /**
  867. * @}
  868. */
  869. /** @addtogroup RCC_LL_Private_Functions
  870. * @{
  871. */
  872. /**
  873. * @brief Return SYSTEM clock frequency
  874. * @retval SYSTEM clock frequency (in Hz)
  875. */
  876. uint32_t RCC_GetSystemClockFreq(void)
  877. {
  878. uint32_t frequency;
  879. uint32_t hsidiv;
  880. /* Get SYSCLK source -------------------------------------------------------*/
  881. switch (LL_RCC_GetSysClkSource())
  882. {
  883. case LL_RCC_SYS_CLKSOURCE_STATUS_HSE: /* HSE used as system clock source */
  884. frequency = HSE_VALUE;
  885. break;
  886. case LL_RCC_SYS_CLKSOURCE_STATUS_PLL: /* PLL used as system clock source */
  887. frequency = RCC_PLL_GetFreqDomain_SYS();
  888. break;
  889. case LL_RCC_SYS_CLKSOURCE_STATUS_HSI: /* HSI used as system clock source */
  890. default:
  891. hsidiv = (1UL << ((READ_BIT(RCC->CR, RCC_CR_HSIDIV)) >> RCC_CR_HSIDIV_Pos));
  892. frequency = (HSI_VALUE / hsidiv);
  893. break;
  894. }
  895. return frequency;
  896. }
  897. /**
  898. * @brief Return HCLK clock frequency
  899. * @param SYSCLK_Frequency SYSCLK clock frequency
  900. * @retval HCLK clock frequency (in Hz)
  901. */
  902. uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency)
  903. {
  904. /* HCLK clock frequency */
  905. return __LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, LL_RCC_GetAHBPrescaler());
  906. }
  907. /**
  908. * @brief Return PCLK1 clock frequency
  909. * @param HCLK_Frequency HCLK clock frequency
  910. * @retval PCLK1 clock frequency (in Hz)
  911. */
  912. uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency)
  913. {
  914. /* PCLK1 clock frequency */
  915. return __LL_RCC_CALC_PCLK1_FREQ(HCLK_Frequency, LL_RCC_GetAPB1Prescaler());
  916. }
  917. /**
  918. * @brief Return PLL clock frequency used for system domain
  919. * @retval PLL clock frequency (in Hz)
  920. */
  921. uint32_t RCC_PLL_GetFreqDomain_SYS(void)
  922. {
  923. uint32_t pllinputfreq;
  924. uint32_t pllsource;
  925. /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
  926. SYSCLK = PLL_VCO / PLLR
  927. */
  928. pllsource = LL_RCC_PLL_GetMainSource();
  929. switch (pllsource)
  930. {
  931. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  932. pllinputfreq = HSI_VALUE;
  933. break;
  934. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  935. pllinputfreq = HSE_VALUE;
  936. break;
  937. default:
  938. pllinputfreq = HSI_VALUE;
  939. break;
  940. }
  941. return __LL_RCC_CALC_PLLCLK_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  942. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetR());
  943. }
  944. /**
  945. * @brief Return PLL clock frequency used for ADC domain
  946. * @retval PLL clock frequency (in Hz)
  947. */
  948. uint32_t RCC_PLL_GetFreqDomain_ADC(void)
  949. {
  950. uint32_t pllinputfreq;
  951. uint32_t pllsource;
  952. /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
  953. ADC Domain clock = PLL_VCO / PLLP
  954. */
  955. pllsource = LL_RCC_PLL_GetMainSource();
  956. switch (pllsource)
  957. {
  958. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  959. pllinputfreq = HSE_VALUE;
  960. break;
  961. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  962. default:
  963. pllinputfreq = HSI_VALUE;
  964. break;
  965. }
  966. return __LL_RCC_CALC_PLLCLK_ADC_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  967. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetP());
  968. }
  969. #if defined(FDCAN1) || defined(FDCAN2)
  970. /**
  971. * @brief Return PLL clock frequency used for FDCAN domain
  972. * @retval PLL clock frequency (in Hz)
  973. */
  974. uint32_t RCC_PLL_GetFreqDomain_FDCAN(void)
  975. {
  976. uint32_t pllinputfreq;
  977. uint32_t pllsource;
  978. /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM ) * PLLN
  979. FDCAN Domain clock = PLL_VCO / PLLQ
  980. */
  981. pllsource = LL_RCC_PLL_GetMainSource();
  982. switch (pllsource)
  983. {
  984. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  985. pllinputfreq = HSE_VALUE;
  986. break;
  987. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  988. default:
  989. pllinputfreq = HSI_VALUE;
  990. break;
  991. }
  992. return __LL_RCC_CALC_PLLCLK_FDCAN_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  993. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetQ());
  994. }
  995. #endif /* FDCAN1 || FDCAN2 */
  996. /**
  997. * @brief Return PLL clock frequency used for I2S1 domain
  998. * @retval PLL clock frequency (in Hz)
  999. */
  1000. uint32_t RCC_PLL_GetFreqDomain_I2S1(void)
  1001. {
  1002. uint32_t pllinputfreq;
  1003. uint32_t pllsource;
  1004. /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
  1005. I2S1 Domain clock = PLL_VCO / PLLP
  1006. */
  1007. pllsource = LL_RCC_PLL_GetMainSource();
  1008. switch (pllsource)
  1009. {
  1010. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  1011. pllinputfreq = HSE_VALUE;
  1012. break;
  1013. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  1014. default:
  1015. pllinputfreq = HSI_VALUE;
  1016. break;
  1017. }
  1018. return __LL_RCC_CALC_PLLCLK_I2S1_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  1019. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetP());
  1020. }
  1021. #if defined(RCC_CCIPR2_I2S2SEL)
  1022. /**
  1023. * @brief Return PLL clock frequency used for I2S2 domain
  1024. * @retval PLL clock frequency (in Hz)
  1025. */
  1026. uint32_t RCC_PLL_GetFreqDomain_I2S2(void)
  1027. {
  1028. uint32_t pllinputfreq;
  1029. uint32_t pllsource;
  1030. /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN
  1031. I2S2 Domain clock = PLL_VCO / PLLP
  1032. */
  1033. pllsource = LL_RCC_PLL_GetMainSource();
  1034. switch (pllsource)
  1035. {
  1036. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  1037. pllinputfreq = HSE_VALUE;
  1038. break;
  1039. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  1040. default:
  1041. pllinputfreq = HSI_VALUE;
  1042. break;
  1043. }
  1044. return __LL_RCC_CALC_PLLCLK_I2S2_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  1045. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetP());
  1046. }
  1047. #endif /* RCC_CCIPR2_I2S2SEL */
  1048. #if defined(RNG)
  1049. /**
  1050. * @brief Return PLL clock frequency used for RNG domain
  1051. * @retval PLL clock frequency (in Hz)
  1052. */
  1053. uint32_t RCC_PLL_GetFreqDomain_RNG(void)
  1054. {
  1055. uint32_t pllinputfreq;
  1056. uint32_t pllsource;
  1057. /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM ) * PLLN
  1058. RNG Domain clock = PLL_VCO / PLLQ
  1059. */
  1060. pllsource = LL_RCC_PLL_GetMainSource();
  1061. switch (pllsource)
  1062. {
  1063. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  1064. pllinputfreq = HSE_VALUE;
  1065. break;
  1066. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  1067. default:
  1068. pllinputfreq = HSI_VALUE;
  1069. break;
  1070. }
  1071. return __LL_RCC_CALC_PLLCLK_RNG_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  1072. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetQ());
  1073. }
  1074. #endif /* RNG */
  1075. #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
  1076. /**
  1077. * @brief Return PLL clock frequency used for USB domain
  1078. * @retval PLL clock frequency (in Hz)
  1079. */
  1080. uint32_t RCC_PLL_GetFreqDomain_USB(void)
  1081. {
  1082. uint32_t pllinputfreq;
  1083. uint32_t pllsource;
  1084. /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM ) * PLLN
  1085. RNG Domain clock = PLL_VCO / PLLQ
  1086. */
  1087. pllsource = LL_RCC_PLL_GetMainSource();
  1088. switch (pllsource)
  1089. {
  1090. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  1091. pllinputfreq = HSE_VALUE;
  1092. break;
  1093. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  1094. default:
  1095. pllinputfreq = HSI_VALUE;
  1096. break;
  1097. }
  1098. return __LL_RCC_CALC_PLLCLK_USB_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  1099. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetQ());
  1100. }
  1101. #endif /* STM32G0C1xx || STM32G0B1xx || STM32G0B0xx */
  1102. #if defined(RCC_PLLQ_SUPPORT)
  1103. /**
  1104. * @brief Return PLL clock frequency used for TIM1 domain
  1105. * @retval PLL clock frequency (in Hz)
  1106. */
  1107. uint32_t RCC_PLL_GetFreqDomain_TIM1(void)
  1108. {
  1109. uint32_t pllinputfreq;
  1110. uint32_t pllsource;
  1111. /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM ) * PLLN
  1112. TIM1 Domain clock = PLL_VCO / PLLQ
  1113. */
  1114. pllsource = LL_RCC_PLL_GetMainSource();
  1115. switch (pllsource)
  1116. {
  1117. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  1118. pllinputfreq = HSE_VALUE;
  1119. break;
  1120. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  1121. default:
  1122. pllinputfreq = HSI_VALUE;
  1123. break;
  1124. }
  1125. return __LL_RCC_CALC_PLLCLK_TIM1_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  1126. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetQ());
  1127. }
  1128. #endif /* RCC_PLLQ_SUPPORT */
  1129. #if defined(RCC_PLLQ_SUPPORT) && defined(TIM15)
  1130. /**
  1131. * @brief Return PLL clock frequency used for TIM15 domain
  1132. * @retval PLL clock frequency (in Hz)
  1133. */
  1134. uint32_t RCC_PLL_GetFreqDomain_TIM15(void)
  1135. {
  1136. uint32_t pllinputfreq;
  1137. uint32_t pllsource;
  1138. /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM ) * PLLN
  1139. TIM15 Domain clock = PLL_VCO / PLLQ
  1140. */
  1141. pllsource = LL_RCC_PLL_GetMainSource();
  1142. switch (pllsource)
  1143. {
  1144. case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */
  1145. pllinputfreq = HSE_VALUE;
  1146. break;
  1147. case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */
  1148. default:
  1149. pllinputfreq = HSI_VALUE;
  1150. break;
  1151. }
  1152. return __LL_RCC_CALC_PLLCLK_TIM15_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
  1153. LL_RCC_PLL_GetN(), LL_RCC_PLL_GetQ());
  1154. }
  1155. #endif /* RCC_PLLQ_SUPPORT && TIM15 */
  1156. /**
  1157. * @}
  1158. */
  1159. /**
  1160. * @}
  1161. */
  1162. #endif /* RCC */
  1163. /**
  1164. * @}
  1165. */
  1166. #endif /* USE_FULL_LL_DRIVER */
  1167. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/