Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 3 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | ****************************************************************************** |
2 | ****************************************************************************** |
3 | * @file stm32f1xx_ll_rcc.c |
3 | * @file stm32f1xx_ll_rcc.c |
4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
5 | * @brief RCC LL module driver. |
5 | * @brief RCC LL module driver. |
6 | ****************************************************************************** |
6 | ****************************************************************************** |
7 | * @attention |
7 | * @attention |
8 | * |
8 | * |
9 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
9 | * Copyright (c) 2016 STMicroelectronics. |
10 | * All rights reserved.</center></h2> |
10 | * All rights reserved. |
11 | * |
11 | * |
12 | * This software component is licensed by ST under BSD 3-Clause license, |
12 | * This software is licensed under terms that can be found in the LICENSE file in |
13 | * the "License"; You may not use this file except in compliance with the |
13 | * the root directory of this software component. |
14 | * License. You may obtain a copy of the License at: |
14 | * If no LICENSE file comes with this software, it is provided AS-IS. |
15 | * opensource.org/licenses/BSD-3-Clause |
15 | ****************************************************************************** |
16 | * |
16 | */ |
17 | ****************************************************************************** |
17 | |
18 | */ |
18 | #if defined(USE_FULL_LL_DRIVER) |
19 | 19 | ||
20 | #if defined(USE_FULL_LL_DRIVER) |
20 | /* Includes ------------------------------------------------------------------*/ |
21 | 21 | #include "stm32f1xx_ll_rcc.h" |
|
22 | /* Includes ------------------------------------------------------------------*/ |
22 | #ifdef USE_FULL_ASSERT |
23 | #include "stm32f1xx_ll_rcc.h" |
23 | #include "stm32_assert.h" |
24 | #ifdef USE_FULL_ASSERT |
24 | #else |
25 | #include "stm32_assert.h" |
25 | #define assert_param(expr) ((void)0U) |
26 | #else |
26 | #endif /* USE_FULL_ASSERT */ |
27 | #define assert_param(expr) ((void)0U) |
27 | /** @addtogroup STM32F1xx_LL_Driver |
28 | #endif /* USE_FULL_ASSERT */ |
28 | * @{ |
29 | /** @addtogroup STM32F1xx_LL_Driver |
29 | */ |
30 | * @{ |
30 | |
31 | */ |
31 | #if defined(RCC) |
32 | 32 | ||
33 | #if defined(RCC) |
33 | /** @defgroup RCC_LL RCC |
34 | 34 | * @{ |
|
35 | /** @defgroup RCC_LL RCC |
35 | */ |
36 | * @{ |
36 | |
37 | */ |
37 | /* Private types -------------------------------------------------------------*/ |
38 | 38 | /* Private variables ---------------------------------------------------------*/ |
|
39 | /* Private types -------------------------------------------------------------*/ |
39 | /* Private constants ---------------------------------------------------------*/ |
40 | /* Private variables ---------------------------------------------------------*/ |
40 | /* Private macros ------------------------------------------------------------*/ |
41 | /* Private constants ---------------------------------------------------------*/ |
41 | /** @addtogroup RCC_LL_Private_Macros |
42 | /* Private macros ------------------------------------------------------------*/ |
42 | * @{ |
43 | /** @addtogroup RCC_LL_Private_Macros |
43 | */ |
44 | * @{ |
44 | #if defined(RCC_PLLI2S_SUPPORT) |
45 | */ |
45 | #define IS_LL_RCC_I2S_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2S2_CLKSOURCE) \ |
46 | #if defined(RCC_PLLI2S_SUPPORT) |
46 | || ((__VALUE__) == LL_RCC_I2S3_CLKSOURCE)) |
47 | #define IS_LL_RCC_I2S_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2S2_CLKSOURCE) \ |
47 | #endif /* RCC_PLLI2S_SUPPORT */ |
48 | || ((__VALUE__) == LL_RCC_I2S3_CLKSOURCE)) |
48 | |
49 | #endif /* RCC_PLLI2S_SUPPORT */ |
49 | #if defined(USB) || defined(USB_OTG_FS) |
50 | 50 | #define IS_LL_RCC_USB_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USB_CLKSOURCE)) |
|
51 | #if defined(USB) || defined(USB_OTG_FS) |
51 | #endif /* USB */ |
52 | #define IS_LL_RCC_USB_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USB_CLKSOURCE)) |
52 | |
53 | #endif /* USB */ |
53 | #define IS_LL_RCC_ADC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_ADC_CLKSOURCE)) |
54 | 54 | /** |
|
55 | #define IS_LL_RCC_ADC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_ADC_CLKSOURCE)) |
55 | * @} |
56 | /** |
56 | */ |
57 | * @} |
57 | |
58 | */ |
58 | /* Private function prototypes -----------------------------------------------*/ |
59 | 59 | /** @defgroup RCC_LL_Private_Functions RCC Private functions |
|
60 | /* Private function prototypes -----------------------------------------------*/ |
60 | * @{ |
61 | /** @defgroup RCC_LL_Private_Functions RCC Private functions |
61 | */ |
62 | * @{ |
62 | uint32_t RCC_GetSystemClockFreq(void); |
63 | */ |
63 | uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency); |
64 | uint32_t RCC_GetSystemClockFreq(void); |
64 | uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency); |
65 | uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency); |
65 | uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency); |
66 | uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency); |
66 | uint32_t RCC_PLL_GetFreqDomain_SYS(void); |
67 | uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency); |
67 | #if defined(RCC_PLLI2S_SUPPORT) |
68 | uint32_t RCC_PLL_GetFreqDomain_SYS(void); |
68 | uint32_t RCC_PLLI2S_GetFreqDomain_I2S(void); |
69 | #if defined(RCC_PLLI2S_SUPPORT) |
69 | #endif /* RCC_PLLI2S_SUPPORT */ |
70 | uint32_t RCC_PLLI2S_GetFreqDomain_I2S(void); |
70 | #if defined(RCC_PLL2_SUPPORT) |
71 | #endif /* RCC_PLLI2S_SUPPORT */ |
71 | uint32_t RCC_PLL2_GetFreqClockFreq(void); |
72 | #if defined(RCC_PLL2_SUPPORT) |
72 | #endif /* RCC_PLL2_SUPPORT */ |
73 | uint32_t RCC_PLL2_GetFreqClockFreq(void); |
73 | /** |
74 | #endif /* RCC_PLL2_SUPPORT */ |
74 | * @} |
75 | /** |
75 | */ |
76 | * @} |
76 | |
77 | */ |
77 | /* Exported functions --------------------------------------------------------*/ |
78 | 78 | /** @addtogroup RCC_LL_Exported_Functions |
|
79 | /* Exported functions --------------------------------------------------------*/ |
79 | * @{ |
80 | /** @addtogroup RCC_LL_Exported_Functions |
80 | */ |
81 | * @{ |
81 | |
82 | */ |
82 | /** @addtogroup RCC_LL_EF_Init |
83 | 83 | * @{ |
|
84 | /** @addtogroup RCC_LL_EF_Init |
84 | */ |
85 | * @{ |
85 | |
86 | */ |
86 | /** |
87 | 87 | * @brief Reset the RCC clock configuration to the default reset state. |
|
88 | /** |
88 | * @note The default reset state of the clock configuration is given below: |
89 | * @brief Reset the RCC clock configuration to the default reset state. |
89 | * - HSI ON and used as system clock source |
90 | * @note The default reset state of the clock configuration is given below: |
90 | * - HSE PLL, PLL2 & PLL3 are OFF |
91 | * - HSI ON and used as system clock source |
91 | * - AHB, APB1 and APB2 prescaler set to 1. |
92 | * - HSE PLL, PLL2 & PLL3 are OFF |
92 | * - CSS, MCO OFF |
93 | * - AHB, APB1 and APB2 prescaler set to 1. |
93 | * - All interrupts disabled |
94 | * - CSS, MCO OFF |
94 | * @note This function doesn't modify the configuration of the |
95 | * - All interrupts disabled |
95 | * - Peripheral clocks |
96 | * @note This function doesn't modify the configuration of the |
96 | * - LSI, LSE and RTC clocks |
97 | * - Peripheral clocks |
97 | * @retval An ErrorStatus enumeration value: |
98 | * - LSI, LSE and RTC clocks |
98 | * - SUCCESS: RCC registers are de-initialized |
99 | * @retval An ErrorStatus enumeration value: |
99 | * - ERROR: not applicable |
100 | * - SUCCESS: RCC registers are de-initialized |
100 | */ |
101 | * - ERROR: not applicable |
101 | ErrorStatus LL_RCC_DeInit(void) |
102 | */ |
102 | { |
103 | ErrorStatus LL_RCC_DeInit(void) |
103 | /* Set HSION bit */ |
104 | { |
104 | LL_RCC_HSI_Enable(); |
105 | /* Set HSION bit */ |
105 | |
106 | LL_RCC_HSI_Enable(); |
106 | /* Wait for HSI READY bit */ |
107 | 107 | while (LL_RCC_HSI_IsReady() != 1U) |
|
108 | /* Wait for HSI READY bit */ |
108 | {} |
109 | while (LL_RCC_HSI_IsReady() != 1U) |
109 | |
110 | {} |
110 | /* Configure HSI as system clock source */ |
111 | 111 | LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI); |
|
112 | /* Configure HSI as system clock source */ |
112 | |
113 | LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI); |
113 | /* Wait till clock switch is ready */ |
114 | 114 | while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI) |
|
115 | /* Wait till clock switch is ready */ |
115 | {} |
116 | while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI) |
116 | |
117 | {} |
117 | /* Reset PLLON bit */ |
118 | 118 | CLEAR_BIT(RCC->CR, RCC_CR_PLLON); |
|
119 | /* Reset PLLON bit */ |
119 | |
120 | CLEAR_BIT(RCC->CR, RCC_CR_PLLON); |
120 | /* Wait for PLL READY bit to be reset */ |
121 | 121 | while (LL_RCC_PLL_IsReady() != 0U) |
|
122 | /* Wait for PLL READY bit to be reset */ |
122 | {} |
123 | while (LL_RCC_PLL_IsReady() != 0U) |
123 | |
124 | {} |
124 | /* Reset CFGR register */ |
125 | 125 | LL_RCC_WriteReg(CFGR, 0x00000000U); |
|
126 | /* Reset CFGR register */ |
126 | |
127 | LL_RCC_WriteReg(CFGR, 0x00000000U); |
127 | /* Reset HSEON, HSEBYP & CSSON bits */ |
128 | 128 | CLEAR_BIT(RCC->CR, (RCC_CR_CSSON | RCC_CR_HSEON | RCC_CR_HSEBYP)); |
|
129 | /* Reset HSEON, HSEBYP & CSSON bits */ |
129 | |
130 | CLEAR_BIT(RCC->CR, (RCC_CR_CSSON | RCC_CR_HSEON | RCC_CR_HSEBYP)); |
130 | #if defined(RCC_CR_PLL2ON) |
131 | 131 | /* Reset PLL2ON bit */ |
|
132 | #if defined(RCC_CR_PLL2ON) |
132 | CLEAR_BIT(RCC->CR, RCC_CR_PLL2ON); |
133 | /* Reset PLL2ON bit */ |
133 | #endif /* RCC_CR_PLL2ON */ |
134 | CLEAR_BIT(RCC->CR, RCC_CR_PLL2ON); |
134 | |
135 | #endif /* RCC_CR_PLL2ON */ |
135 | #if defined(RCC_CR_PLL3ON) |
136 | 136 | /* Reset PLL3ON bit */ |
|
137 | #if defined(RCC_CR_PLL3ON) |
137 | CLEAR_BIT(RCC->CR, RCC_CR_PLL3ON); |
138 | /* Reset PLL3ON bit */ |
138 | #endif /* RCC_CR_PLL3ON */ |
139 | CLEAR_BIT(RCC->CR, RCC_CR_PLL3ON); |
139 | |
140 | #endif /* RCC_CR_PLL3ON */ |
140 | /* Set HSITRIM bits to the reset value */ |
141 | 141 | LL_RCC_HSI_SetCalibTrimming(0x10U); |
|
142 | /* Set HSITRIM bits to the reset value */ |
142 | |
143 | LL_RCC_HSI_SetCalibTrimming(0x10U); |
143 | #if defined(RCC_CFGR2_PREDIV1) |
144 | 144 | /* Reset CFGR2 register */ |
|
145 | #if defined(RCC_CFGR2_PREDIV1) |
145 | LL_RCC_WriteReg(CFGR2, 0x00000000U); |
146 | /* Reset CFGR2 register */ |
146 | #endif /* RCC_CFGR2_PREDIV1 */ |
147 | LL_RCC_WriteReg(CFGR2, 0x00000000U); |
147 | |
148 | #endif /* RCC_CFGR2_PREDIV1 */ |
148 | /* Disable all interrupts */ |
149 | 149 | LL_RCC_WriteReg(CIR, 0x00000000U); |
|
150 | /* Disable all interrupts */ |
150 | |
151 | LL_RCC_WriteReg(CIR, 0x00000000U); |
151 | /* Clear reset flags */ |
152 | 152 | LL_RCC_ClearResetFlags(); |
|
153 | /* Clear reset flags */ |
153 | |
154 | LL_RCC_ClearResetFlags(); |
154 | return SUCCESS; |
155 | 155 | } |
|
156 | return SUCCESS; |
156 | |
157 | } |
157 | /** |
158 | 158 | * @} |
|
159 | /** |
159 | */ |
160 | * @} |
160 | |
161 | */ |
161 | /** @addtogroup RCC_LL_EF_Get_Freq |
162 | 162 | * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks |
|
163 | /** @addtogroup RCC_LL_EF_Get_Freq |
163 | * and different peripheral clocks available on the device. |
164 | * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks |
164 | * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(**) |
165 | * and different peripheral clocks available on the device. |
165 | * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(***) |
166 | * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(**) |
166 | * @note If SYSCLK source is PLL, function returns values based on |
167 | * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(***) |
167 | * HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors. |
168 | * @note If SYSCLK source is PLL, function returns values based on |
168 | * @note (**) HSI_VALUE is a defined constant but the real value may vary |
169 | * HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors. |
169 | * depending on the variations in voltage and temperature. |
170 | * @note (**) HSI_VALUE is a defined constant but the real value may vary |
170 | * @note (***) HSE_VALUE is a defined constant, user has to ensure that |
171 | * depending on the variations in voltage and temperature. |
171 | * HSE_VALUE is same as the real frequency of the crystal used. |
172 | * @note (***) HSE_VALUE is a defined constant, user has to ensure that |
172 | * Otherwise, this function may have wrong result. |
173 | * HSE_VALUE is same as the real frequency of the crystal used. |
173 | * @note The result of this function could be incorrect when using fractional |
174 | * Otherwise, this function may have wrong result. |
174 | * value for HSE crystal. |
175 | * @note The result of this function could be incorrect when using fractional |
175 | * @note This function can be used by the user application to compute the |
176 | * value for HSE crystal. |
176 | * baud-rate for the communication peripherals or configure other parameters. |
177 | * @note This function can be used by the user application to compute the |
177 | * @{ |
178 | * baud-rate for the communication peripherals or configure other parameters. |
178 | */ |
179 | * @{ |
179 | |
180 | */ |
180 | /** |
181 | 181 | * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks |
|
182 | /** |
182 | * @note Each time SYSCLK, HCLK, PCLK1 and/or PCLK2 clock changes, this function |
183 | * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks |
183 | * must be called to update structure fields. Otherwise, any |
184 | * @note Each time SYSCLK, HCLK, PCLK1 and/or PCLK2 clock changes, this function |
184 | * configuration based on this function will be incorrect. |
185 | * must be called to update structure fields. Otherwise, any |
185 | * @param RCC_Clocks pointer to a @ref LL_RCC_ClocksTypeDef structure which will hold the clocks frequencies |
186 | * configuration based on this function will be incorrect. |
186 | * @retval None |
187 | * @param RCC_Clocks pointer to a @ref LL_RCC_ClocksTypeDef structure which will hold the clocks frequencies |
187 | */ |
188 | * @retval None |
188 | void LL_RCC_GetSystemClocksFreq(LL_RCC_ClocksTypeDef *RCC_Clocks) |
189 | */ |
189 | { |
190 | void LL_RCC_GetSystemClocksFreq(LL_RCC_ClocksTypeDef *RCC_Clocks) |
190 | /* Get SYSCLK frequency */ |
191 | { |
191 | RCC_Clocks->SYSCLK_Frequency = RCC_GetSystemClockFreq(); |
192 | /* Get SYSCLK frequency */ |
192 | |
193 | RCC_Clocks->SYSCLK_Frequency = RCC_GetSystemClockFreq(); |
193 | /* HCLK clock frequency */ |
194 | 194 | RCC_Clocks->HCLK_Frequency = RCC_GetHCLKClockFreq(RCC_Clocks->SYSCLK_Frequency); |
|
195 | /* HCLK clock frequency */ |
195 | |
196 | RCC_Clocks->HCLK_Frequency = RCC_GetHCLKClockFreq(RCC_Clocks->SYSCLK_Frequency); |
196 | /* PCLK1 clock frequency */ |
197 | 197 | RCC_Clocks->PCLK1_Frequency = RCC_GetPCLK1ClockFreq(RCC_Clocks->HCLK_Frequency); |
|
198 | /* PCLK1 clock frequency */ |
198 | |
199 | RCC_Clocks->PCLK1_Frequency = RCC_GetPCLK1ClockFreq(RCC_Clocks->HCLK_Frequency); |
199 | /* PCLK2 clock frequency */ |
200 | 200 | RCC_Clocks->PCLK2_Frequency = RCC_GetPCLK2ClockFreq(RCC_Clocks->HCLK_Frequency); |
|
201 | /* PCLK2 clock frequency */ |
201 | } |
202 | RCC_Clocks->PCLK2_Frequency = RCC_GetPCLK2ClockFreq(RCC_Clocks->HCLK_Frequency); |
202 | |
203 | } |
203 | #if defined(RCC_CFGR2_I2S2SRC) |
204 | 204 | /** |
|
205 | #if defined(RCC_CFGR2_I2S2SRC) |
205 | * @brief Return I2Sx clock frequency |
206 | /** |
206 | * @param I2SxSource This parameter can be one of the following values: |
207 | * @brief Return I2Sx clock frequency |
207 | * @arg @ref LL_RCC_I2S2_CLKSOURCE |
208 | * @param I2SxSource This parameter can be one of the following values: |
208 | * @arg @ref LL_RCC_I2S3_CLKSOURCE |
209 | * @arg @ref LL_RCC_I2S2_CLKSOURCE |
209 | * @retval I2S clock frequency (in Hz) |
210 | * @arg @ref LL_RCC_I2S3_CLKSOURCE |
210 | */ |
211 | * @retval I2S clock frequency (in Hz) |
211 | uint32_t LL_RCC_GetI2SClockFreq(uint32_t I2SxSource) |
212 | */ |
212 | { |
213 | uint32_t LL_RCC_GetI2SClockFreq(uint32_t I2SxSource) |
213 | uint32_t i2s_frequency = LL_RCC_PERIPH_FREQUENCY_NO; |
214 | { |
214 | |
215 | uint32_t i2s_frequency = LL_RCC_PERIPH_FREQUENCY_NO; |
215 | /* Check parameter */ |
216 | 216 | assert_param(IS_LL_RCC_I2S_CLKSOURCE(I2SxSource)); |
|
217 | /* Check parameter */ |
217 | |
218 | assert_param(IS_LL_RCC_I2S_CLKSOURCE(I2SxSource)); |
218 | /* I2S1CLK clock frequency */ |
219 | 219 | switch (LL_RCC_GetI2SClockSource(I2SxSource)) |
|
220 | /* I2S1CLK clock frequency */ |
220 | { |
221 | switch (LL_RCC_GetI2SClockSource(I2SxSource)) |
221 | case LL_RCC_I2S2_CLKSOURCE_SYSCLK: /*!< System clock selected as I2S clock source */ |
222 | { |
222 | case LL_RCC_I2S3_CLKSOURCE_SYSCLK: |
223 | case LL_RCC_I2S2_CLKSOURCE_SYSCLK: /*!< System clock selected as I2S clock source */ |
223 | i2s_frequency = RCC_GetSystemClockFreq(); |
224 | case LL_RCC_I2S3_CLKSOURCE_SYSCLK: |
224 | break; |
225 | i2s_frequency = RCC_GetSystemClockFreq(); |
225 | |
226 | break; |
226 | case LL_RCC_I2S2_CLKSOURCE_PLLI2S_VCO: /*!< PLLI2S oscillator clock selected as I2S clock source */ |
227 | 227 | case LL_RCC_I2S3_CLKSOURCE_PLLI2S_VCO: |
|
228 | case LL_RCC_I2S2_CLKSOURCE_PLLI2S_VCO: /*!< PLLI2S oscillator clock selected as I2S clock source */ |
228 | default: |
229 | case LL_RCC_I2S3_CLKSOURCE_PLLI2S_VCO: |
229 | i2s_frequency = RCC_PLLI2S_GetFreqDomain_I2S() * 2U; |
230 | default: |
230 | break; |
231 | i2s_frequency = RCC_PLLI2S_GetFreqDomain_I2S() * 2U; |
231 | } |
232 | break; |
232 | |
233 | } |
233 | return i2s_frequency; |
234 | 234 | } |
|
235 | return i2s_frequency; |
235 | #endif /* RCC_CFGR2_I2S2SRC */ |
236 | } |
236 | |
237 | #endif /* RCC_CFGR2_I2S2SRC */ |
237 | #if defined(USB) || defined(USB_OTG_FS) |
238 | 238 | /** |
|
239 | #if defined(USB) || defined(USB_OTG_FS) |
239 | * @brief Return USBx clock frequency |
240 | /** |
240 | * @param USBxSource This parameter can be one of the following values: |
241 | * @brief Return USBx clock frequency |
241 | * @arg @ref LL_RCC_USB_CLKSOURCE |
242 | * @param USBxSource This parameter can be one of the following values: |
242 | * @retval USB clock frequency (in Hz) |
243 | * @arg @ref LL_RCC_USB_CLKSOURCE |
243 | * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI), HSE or PLL is not ready |
244 | * @retval USB clock frequency (in Hz) |
244 | */ |
245 | * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI), HSE or PLL is not ready |
245 | uint32_t LL_RCC_GetUSBClockFreq(uint32_t USBxSource) |
246 | */ |
246 | { |
247 | uint32_t LL_RCC_GetUSBClockFreq(uint32_t USBxSource) |
247 | uint32_t usb_frequency = LL_RCC_PERIPH_FREQUENCY_NO; |
248 | { |
248 | |
249 | uint32_t usb_frequency = LL_RCC_PERIPH_FREQUENCY_NO; |
249 | /* Check parameter */ |
250 | 250 | assert_param(IS_LL_RCC_USB_CLKSOURCE(USBxSource)); |
|
251 | /* Check parameter */ |
251 | |
252 | assert_param(IS_LL_RCC_USB_CLKSOURCE(USBxSource)); |
252 | /* USBCLK clock frequency */ |
253 | 253 | switch (LL_RCC_GetUSBClockSource(USBxSource)) |
|
254 | /* USBCLK clock frequency */ |
254 | { |
255 | switch (LL_RCC_GetUSBClockSource(USBxSource)) |
255 | #if defined(RCC_CFGR_USBPRE) |
256 | { |
256 | case LL_RCC_USB_CLKSOURCE_PLL: /* PLL clock used as USB clock source */ |
257 | #if defined(RCC_CFGR_USBPRE) |
257 | if (LL_RCC_PLL_IsReady()) |
258 | case LL_RCC_USB_CLKSOURCE_PLL: /* PLL clock used as USB clock source */ |
258 | { |
259 | if (LL_RCC_PLL_IsReady()) |
259 | usb_frequency = RCC_PLL_GetFreqDomain_SYS(); |
260 | { |
260 | } |
261 | usb_frequency = RCC_PLL_GetFreqDomain_SYS(); |
261 | break; |
262 | } |
262 | |
263 | break; |
263 | case LL_RCC_USB_CLKSOURCE_PLL_DIV_1_5: /* PLL clock divided by 1.5 used as USB clock source */ |
264 | 264 | default: |
|
265 | case LL_RCC_USB_CLKSOURCE_PLL_DIV_1_5: /* PLL clock divided by 1.5 used as USB clock source */ |
265 | if (LL_RCC_PLL_IsReady()) |
266 | default: |
266 | { |
267 | if (LL_RCC_PLL_IsReady()) |
267 | usb_frequency = (RCC_PLL_GetFreqDomain_SYS() * 3U) / 2U; |
268 | { |
268 | } |
269 | usb_frequency = (RCC_PLL_GetFreqDomain_SYS() * 3U) / 2U; |
269 | break; |
270 | } |
270 | #endif /* RCC_CFGR_USBPRE */ |
271 | break; |
271 | #if defined(RCC_CFGR_OTGFSPRE) |
272 | #endif /* RCC_CFGR_USBPRE */ |
272 | /* USBCLK = PLLVCO/2 |
273 | #if defined(RCC_CFGR_OTGFSPRE) |
273 | = (2 x PLLCLK) / 2 |
274 | /* USBCLK = PLLVCO/2 |
274 | = PLLCLK */ |
275 | = (2 x PLLCLK) / 2 |
275 | case LL_RCC_USB_CLKSOURCE_PLL_DIV_2: /* PLL clock used as USB clock source */ |
276 | = PLLCLK */ |
276 | if (LL_RCC_PLL_IsReady()) |
277 | case LL_RCC_USB_CLKSOURCE_PLL_DIV_2: /* PLL clock used as USB clock source */ |
277 | { |
278 | if (LL_RCC_PLL_IsReady()) |
278 | usb_frequency = RCC_PLL_GetFreqDomain_SYS(); |
279 | { |
279 | } |
280 | usb_frequency = RCC_PLL_GetFreqDomain_SYS(); |
280 | break; |
281 | } |
281 | |
282 | break; |
282 | /* USBCLK = PLLVCO/3 |
283 | 283 | = (2 x PLLCLK) / 3 */ |
|
284 | /* USBCLK = PLLVCO/3 |
284 | case LL_RCC_USB_CLKSOURCE_PLL_DIV_3: /* PLL clock divided by 3 used as USB clock source */ |
285 | = (2 x PLLCLK) / 3 */ |
285 | default: |
286 | case LL_RCC_USB_CLKSOURCE_PLL_DIV_3: /* PLL clock divided by 3 used as USB clock source */ |
286 | if (LL_RCC_PLL_IsReady()) |
287 | default: |
287 | { |
288 | if (LL_RCC_PLL_IsReady()) |
288 | usb_frequency = (RCC_PLL_GetFreqDomain_SYS() * 2U) / 3U; |
289 | { |
289 | } |
290 | usb_frequency = (RCC_PLL_GetFreqDomain_SYS() * 2U) / 3U; |
290 | break; |
291 | } |
291 | #endif /* RCC_CFGR_OTGFSPRE */ |
292 | break; |
292 | } |
293 | #endif /* RCC_CFGR_OTGFSPRE */ |
293 | |
294 | } |
294 | return usb_frequency; |
295 | 295 | } |
|
296 | return usb_frequency; |
296 | #endif /* USB */ |
297 | } |
297 | |
298 | #endif /* USB */ |
298 | /** |
299 | 299 | * @brief Return ADCx clock frequency |
|
300 | /** |
300 | * @param ADCxSource This parameter can be one of the following values: |
301 | * @brief Return ADCx clock frequency |
301 | * @arg @ref LL_RCC_ADC_CLKSOURCE |
302 | * @param ADCxSource This parameter can be one of the following values: |
302 | * @retval ADC clock frequency (in Hz) |
303 | * @arg @ref LL_RCC_ADC_CLKSOURCE |
303 | */ |
304 | * @retval ADC clock frequency (in Hz) |
304 | uint32_t LL_RCC_GetADCClockFreq(uint32_t ADCxSource) |
305 | */ |
305 | { |
306 | uint32_t LL_RCC_GetADCClockFreq(uint32_t ADCxSource) |
306 | uint32_t adc_prescaler = 0U; |
307 | { |
307 | uint32_t adc_frequency = 0U; |
308 | uint32_t adc_prescaler = 0U; |
308 | |
309 | uint32_t adc_frequency = 0U; |
309 | /* Check parameter */ |
310 | 310 | assert_param(IS_LL_RCC_ADC_CLKSOURCE(ADCxSource)); |
|
311 | /* Check parameter */ |
311 | |
312 | assert_param(IS_LL_RCC_ADC_CLKSOURCE(ADCxSource)); |
312 | /* Get ADC prescaler */ |
313 | 313 | adc_prescaler = LL_RCC_GetADCClockSource(ADCxSource); |
|
314 | /* Get ADC prescaler */ |
314 | |
315 | adc_prescaler = LL_RCC_GetADCClockSource(ADCxSource); |
315 | /* ADC frequency = PCLK2 frequency / ADC prescaler (2, 4, 6 or 8) */ |
316 | 316 | adc_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())) |
|
317 | /* ADC frequency = PCLK2 frequency / ADC prescaler (2, 4, 6 or 8) */ |
317 | / (((adc_prescaler >> POSITION_VAL(ADCxSource)) + 1U) * 2U); |
318 | adc_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())) |
318 | |
319 | / (((adc_prescaler >> POSITION_VAL(ADCxSource)) + 1U) * 2U); |
319 | return adc_frequency; |
320 | 320 | } |
|
321 | return adc_frequency; |
321 | |
322 | } |
322 | /** |
323 | 323 | * @} |
|
324 | /** |
324 | */ |
325 | * @} |
325 | |
326 | */ |
326 | /** |
327 | 327 | * @} |
|
328 | /** |
328 | */ |
329 | * @} |
329 | |
330 | */ |
330 | /** @addtogroup RCC_LL_Private_Functions |
331 | 331 | * @{ |
|
332 | /** @addtogroup RCC_LL_Private_Functions |
332 | */ |
333 | * @{ |
333 | |
334 | */ |
334 | /** |
335 | 335 | * @brief Return SYSTEM clock frequency |
|
336 | /** |
336 | * @retval SYSTEM clock frequency (in Hz) |
337 | * @brief Return SYSTEM clock frequency |
337 | */ |
338 | * @retval SYSTEM clock frequency (in Hz) |
338 | uint32_t RCC_GetSystemClockFreq(void) |
339 | */ |
339 | { |
340 | uint32_t RCC_GetSystemClockFreq(void) |
340 | uint32_t frequency = 0U; |
341 | { |
341 | |
342 | uint32_t frequency = 0U; |
342 | /* Get SYSCLK source -------------------------------------------------------*/ |
343 | 343 | switch (LL_RCC_GetSysClkSource()) |
|
344 | /* Get SYSCLK source -------------------------------------------------------*/ |
344 | { |
345 | switch (LL_RCC_GetSysClkSource()) |
345 | case LL_RCC_SYS_CLKSOURCE_STATUS_HSI: /* HSI used as system clock source */ |
346 | { |
346 | frequency = HSI_VALUE; |
347 | case LL_RCC_SYS_CLKSOURCE_STATUS_HSI: /* HSI used as system clock source */ |
347 | break; |
348 | frequency = HSI_VALUE; |
348 | |
349 | break; |
349 | case LL_RCC_SYS_CLKSOURCE_STATUS_HSE: /* HSE used as system clock source */ |
350 | 350 | frequency = HSE_VALUE; |
|
351 | case LL_RCC_SYS_CLKSOURCE_STATUS_HSE: /* HSE used as system clock source */ |
351 | break; |
352 | frequency = HSE_VALUE; |
352 | |
353 | break; |
353 | case LL_RCC_SYS_CLKSOURCE_STATUS_PLL: /* PLL used as system clock source */ |
354 | 354 | frequency = RCC_PLL_GetFreqDomain_SYS(); |
|
355 | case LL_RCC_SYS_CLKSOURCE_STATUS_PLL: /* PLL used as system clock source */ |
355 | break; |
356 | frequency = RCC_PLL_GetFreqDomain_SYS(); |
356 | |
357 | break; |
357 | default: |
358 | 358 | frequency = HSI_VALUE; |
|
359 | default: |
359 | break; |
360 | frequency = HSI_VALUE; |
360 | } |
361 | break; |
361 | |
362 | } |
362 | return frequency; |
363 | 363 | } |
|
364 | return frequency; |
364 | |
365 | } |
365 | /** |
366 | 366 | * @brief Return HCLK clock frequency |
|
367 | /** |
367 | * @param SYSCLK_Frequency SYSCLK clock frequency |
368 | * @brief Return HCLK clock frequency |
368 | * @retval HCLK clock frequency (in Hz) |
369 | * @param SYSCLK_Frequency SYSCLK clock frequency |
369 | */ |
370 | * @retval HCLK clock frequency (in Hz) |
370 | uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency) |
371 | */ |
371 | { |
372 | uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency) |
372 | /* HCLK clock frequency */ |
373 | { |
373 | return __LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, LL_RCC_GetAHBPrescaler()); |
374 | /* HCLK clock frequency */ |
374 | } |
375 | return __LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, LL_RCC_GetAHBPrescaler()); |
375 | |
376 | } |
376 | /** |
377 | 377 | * @brief Return PCLK1 clock frequency |
|
378 | /** |
378 | * @param HCLK_Frequency HCLK clock frequency |
379 | * @brief Return PCLK1 clock frequency |
379 | * @retval PCLK1 clock frequency (in Hz) |
380 | * @param HCLK_Frequency HCLK clock frequency |
380 | */ |
381 | * @retval PCLK1 clock frequency (in Hz) |
381 | uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency) |
382 | */ |
382 | { |
383 | uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency) |
383 | /* PCLK1 clock frequency */ |
384 | { |
384 | return __LL_RCC_CALC_PCLK1_FREQ(HCLK_Frequency, LL_RCC_GetAPB1Prescaler()); |
385 | /* PCLK1 clock frequency */ |
385 | } |
386 | return __LL_RCC_CALC_PCLK1_FREQ(HCLK_Frequency, LL_RCC_GetAPB1Prescaler()); |
386 | |
387 | } |
387 | /** |
388 | 388 | * @brief Return PCLK2 clock frequency |
|
389 | /** |
389 | * @param HCLK_Frequency HCLK clock frequency |
390 | * @brief Return PCLK2 clock frequency |
390 | * @retval PCLK2 clock frequency (in Hz) |
391 | * @param HCLK_Frequency HCLK clock frequency |
391 | */ |
392 | * @retval PCLK2 clock frequency (in Hz) |
392 | uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency) |
393 | */ |
393 | { |
394 | uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency) |
394 | /* PCLK2 clock frequency */ |
395 | { |
395 | return __LL_RCC_CALC_PCLK2_FREQ(HCLK_Frequency, LL_RCC_GetAPB2Prescaler()); |
396 | /* PCLK2 clock frequency */ |
396 | } |
397 | return __LL_RCC_CALC_PCLK2_FREQ(HCLK_Frequency, LL_RCC_GetAPB2Prescaler()); |
397 | |
398 | } |
398 | /** |
399 | 399 | * @brief Return PLL clock frequency used for system domain |
|
400 | /** |
400 | * @retval PLL clock frequency (in Hz) |
401 | * @brief Return PLL clock frequency used for system domain |
401 | */ |
402 | * @retval PLL clock frequency (in Hz) |
402 | uint32_t RCC_PLL_GetFreqDomain_SYS(void) |
403 | */ |
403 | { |
404 | uint32_t RCC_PLL_GetFreqDomain_SYS(void) |
404 | uint32_t pllinputfreq = 0U, pllsource = 0U; |
405 | { |
405 | |
406 | uint32_t pllinputfreq = 0U, pllsource = 0U; |
406 | /* PLL_VCO = (HSE_VALUE, HSI_VALUE or PLL2 / PLL Predivider) * PLL Multiplicator */ |
407 | 407 | ||
408 | /* PLL_VCO = (HSE_VALUE, HSI_VALUE or PLL2 / PLL Predivider) * PLL Multiplicator */ |
408 | /* Get PLL source */ |
409 | 409 | pllsource = LL_RCC_PLL_GetMainSource(); |
|
410 | /* Get PLL source */ |
410 | |
411 | pllsource = LL_RCC_PLL_GetMainSource(); |
411 | switch (pllsource) |
412 | 412 | { |
|
413 | switch (pllsource) |
413 | case LL_RCC_PLLSOURCE_HSI_DIV_2: /* HSI used as PLL clock source */ |
414 | { |
414 | pllinputfreq = HSI_VALUE / 2U; |
415 | case LL_RCC_PLLSOURCE_HSI_DIV_2: /* HSI used as PLL clock source */ |
415 | break; |
416 | pllinputfreq = HSI_VALUE / 2U; |
416 | |
417 | break; |
417 | case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */ |
418 | 418 | pllinputfreq = HSE_VALUE / (LL_RCC_PLL_GetPrediv() + 1U); |
|
419 | case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */ |
419 | break; |
420 | pllinputfreq = HSE_VALUE / (LL_RCC_PLL_GetPrediv() + 1U); |
420 | |
421 | break; |
421 | #if defined(RCC_PLL2_SUPPORT) |
422 | 422 | case LL_RCC_PLLSOURCE_PLL2: /* PLL2 used as PLL clock source */ |
|
423 | #if defined(RCC_PLL2_SUPPORT) |
423 | pllinputfreq = RCC_PLL2_GetFreqClockFreq() / (LL_RCC_PLL_GetPrediv() + 1U); |
424 | case LL_RCC_PLLSOURCE_PLL2: /* PLL2 used as PLL clock source */ |
424 | break; |
425 | pllinputfreq = RCC_PLL2_GetFreqClockFreq() / (LL_RCC_PLL_GetPrediv() + 1U); |
425 | #endif /* RCC_PLL2_SUPPORT */ |
426 | break; |
426 | |
427 | #endif /* RCC_PLL2_SUPPORT */ |
427 | default: |
428 | 428 | pllinputfreq = HSI_VALUE / 2U; |
|
429 | default: |
429 | break; |
430 | pllinputfreq = HSI_VALUE / 2U; |
430 | } |
431 | break; |
431 | return __LL_RCC_CALC_PLLCLK_FREQ(pllinputfreq, LL_RCC_PLL_GetMultiplicator()); |
432 | } |
432 | } |
433 | return __LL_RCC_CALC_PLLCLK_FREQ(pllinputfreq, LL_RCC_PLL_GetMultiplicator()); |
433 | |
434 | } |
434 | #if defined(RCC_PLL2_SUPPORT) |
435 | 435 | /** |
|
436 | #if defined(RCC_PLL2_SUPPORT) |
436 | * @brief Return PLL clock frequency used for system domain |
437 | /** |
437 | * @retval PLL clock frequency (in Hz) |
438 | * @brief Return PLL clock frequency used for system domain |
438 | */ |
439 | * @retval PLL clock frequency (in Hz) |
439 | uint32_t RCC_PLL2_GetFreqClockFreq(void) |
440 | */ |
440 | { |
441 | uint32_t RCC_PLL2_GetFreqClockFreq(void) |
441 | return __LL_RCC_CALC_PLL2CLK_FREQ(HSE_VALUE, LL_RCC_PLL2_GetMultiplicator(), LL_RCC_HSE_GetPrediv2()); |
442 | { |
442 | } |
443 | return __LL_RCC_CALC_PLL2CLK_FREQ(HSE_VALUE, LL_RCC_PLL2_GetMultiplicator(), LL_RCC_HSE_GetPrediv2()); |
443 | #endif /* RCC_PLL2_SUPPORT */ |
444 | } |
444 | |
445 | #endif /* RCC_PLL2_SUPPORT */ |
445 | #if defined(RCC_PLLI2S_SUPPORT) |
446 | 446 | /** |
|
447 | #if defined(RCC_PLLI2S_SUPPORT) |
447 | * @brief Return PLL clock frequency used for system domain |
448 | /** |
448 | * @retval PLL clock frequency (in Hz) |
449 | * @brief Return PLL clock frequency used for system domain |
449 | */ |
450 | * @retval PLL clock frequency (in Hz) |
450 | uint32_t RCC_PLLI2S_GetFreqDomain_I2S(void) |
451 | */ |
451 | { |
452 | uint32_t RCC_PLLI2S_GetFreqDomain_I2S(void) |
452 | return __LL_RCC_CALC_PLLI2SCLK_FREQ(HSE_VALUE, LL_RCC_PLLI2S_GetMultiplicator(), LL_RCC_HSE_GetPrediv2()); |
453 | { |
453 | } |
454 | return __LL_RCC_CALC_PLLI2SCLK_FREQ(HSE_VALUE, LL_RCC_PLLI2S_GetMultiplicator(), LL_RCC_HSE_GetPrediv2()); |
454 | #endif /* RCC_PLLI2S_SUPPORT */ |
455 | } |
455 | |
456 | #endif /* RCC_PLLI2S_SUPPORT */ |
456 | /** |
457 | 457 | * @} |
|
458 | /** |
458 | */ |
459 | * @} |
459 | |
460 | */ |
460 | /** |
461 | 461 | * @} |
|
462 | /** |
462 | */ |
463 | * @} |
463 | |
464 | */ |
464 | #endif /* defined(RCC) */ |
465 | 465 | ||
466 | #endif /* defined(RCC) */ |
466 | /** |
467 | 467 | * @} |
|
468 | /** |
468 | */ |
469 | * @} |
469 | |
470 | */ |
470 | #endif /* USE_FULL_LL_DRIVER */ |
471 | 471 | ||
472 | #endif /* USE_FULL_LL_DRIVER */ |
- | |
473 | - | ||
474 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
- |