提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
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>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
|
10 |
* |
|
11 |
* Redistribution and use in source and binary forms, with or without modification, |
|
12 |
* are permitted provided that the following conditions are met: |
|
13 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
14 |
* this list of conditions and the following disclaimer. |
|
15 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
16 |
* this list of conditions and the following disclaimer in the documentation |
|
17 |
* and/or other materials provided with the distribution. |
|
18 |
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
|
19 |
* may be used to endorse or promote products derived from this software |
|
20 |
* without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
23 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
24 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
25 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
|
26 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
27 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
28 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
29 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
30 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
31 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
* |
|
33 |
****************************************************************************** |
|
34 |
*/ |
|
35 |
#if defined(USE_FULL_LL_DRIVER) |
|
36 |
|
|
37 |
/* Includes ------------------------------------------------------------------*/ |
|
38 |
#include "stm32f0xx_ll_rcc.h" |
|
39 |
#ifdef USE_FULL_ASSERT |
|
40 |
#include "stm32_assert.h" |
|
41 |
#else |
|
42 |
#define assert_param(expr) ((void)0U) |
|
43 |
#endif /* USE_FULL_ASSERT */ |
|
44 |
/** @addtogroup STM32F0xx_LL_Driver |
|
45 |
* @{ |
|
46 |
*/ |
|
47 |
|
|
48 |
#if defined(RCC) |
|
49 |
|
|
50 |
/** @defgroup RCC_LL RCC |
|
51 |
* @{ |
|
52 |
*/ |
|
53 |
|
|
54 |
/* Private types -------------------------------------------------------------*/ |
|
55 |
/* Private variables ---------------------------------------------------------*/ |
|
56 |
|
|
57 |
/* Private constants ---------------------------------------------------------*/ |
|
58 |
/* Private macros ------------------------------------------------------------*/ |
|
59 |
/** @addtogroup RCC_LL_Private_Macros |
|
60 |
* @{ |
|
61 |
*/ |
|
62 |
#if defined(RCC_CFGR3_USART2SW) && defined(RCC_CFGR3_USART3SW) |
|
63 |
#define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \ |
|
64 |
|| ((__VALUE__) == LL_RCC_USART2_CLKSOURCE) \ |
|
65 |
|| ((__VALUE__) == LL_RCC_USART3_CLKSOURCE)) |
|
66 |
#elif defined(RCC_CFGR3_USART2SW) && !defined(RCC_CFGR3_USART3SW) |
|
67 |
#define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \ |
|
68 |
|| ((__VALUE__) == LL_RCC_USART2_CLKSOURCE)) |
|
69 |
#elif defined(RCC_CFGR3_USART3SW) && !defined(RCC_CFGR3_USART2SW) |
|
70 |
#define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \ |
|
71 |
|| ((__VALUE__) == LL_RCC_USART3_CLKSOURCE)) |
|
72 |
#else |
|
73 |
#define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE)) |
|
74 |
#endif /* RCC_CFGR3_USART2SW && RCC_CFGR3_USART3SW */ |
|
75 |
|
|
76 |
#define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_I2C1_CLKSOURCE) |
|
77 |
|
|
78 |
#if defined(USB) |
|
79 |
#define IS_LL_RCC_USB_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USB_CLKSOURCE)) |
|
80 |
#endif /* USB */ |
|
81 |
|
|
82 |
#if defined(CEC) |
|
83 |
#define IS_LL_RCC_CEC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_CEC_CLKSOURCE)) |
|
84 |
#endif /* CEC */ |
|
85 |
|
|
86 |
/** |
|
87 |
* @} |
|
88 |
*/ |
|
89 |
|
|
90 |
/* Private function prototypes -----------------------------------------------*/ |
|
91 |
/** @defgroup RCC_LL_Private_Functions RCC Private functions |
|
92 |
* @{ |
|
93 |
*/ |
|
94 |
uint32_t RCC_GetSystemClockFreq(void); |
|
95 |
uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency); |
|
96 |
uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency); |
|
97 |
uint32_t RCC_PLL_GetFreqDomain_SYS(void); |
|
98 |
/** |
|
99 |
* @} |
|
100 |
*/ |
|
101 |
|
|
102 |
|
|
103 |
/* Exported functions --------------------------------------------------------*/ |
|
104 |
/** @addtogroup RCC_LL_Exported_Functions |
|
105 |
* @{ |
|
106 |
*/ |
|
107 |
|
|
108 |
/** @addtogroup RCC_LL_EF_Init |
|
109 |
* @{ |
|
110 |
*/ |
|
111 |
|
|
112 |
/** |
|
113 |
* @brief Reset the RCC clock configuration to the default reset state. |
|
114 |
* @note The default reset state of the clock configuration is given below: |
|
115 |
* - HSI ON and used as system clock source |
|
116 |
* - HSE and PLL OFF |
|
117 |
* - AHB and APB1 prescaler set to 1. |
|
118 |
* - CSS, MCO OFF |
|
119 |
* - All interrupts disabled |
|
120 |
* @note This function doesn't modify the configuration of the |
|
121 |
* - Peripheral clocks |
|
122 |
* - LSI, LSE and RTC clocks |
|
123 |
* @retval An ErrorStatus enumeration value: |
|
124 |
* - SUCCESS: RCC registers are de-initialized |
|
125 |
* - ERROR: not applicable |
|
126 |
*/ |
|
127 |
ErrorStatus LL_RCC_DeInit(void) |
|
128 |
{ |
|
129 |
uint32_t vl_mask = 0U; |
|
130 |
|
|
131 |
/* Set HSION bit */ |
|
132 |
LL_RCC_HSI_Enable(); |
|
133 |
|
|
134 |
/* Set HSITRIM bits to the reset value*/ |
|
135 |
LL_RCC_HSI_SetCalibTrimming(0x10U); |
|
136 |
|
|
137 |
/* Reset SW, HPRE, PPRE and MCOSEL bits */ |
|
138 |
vl_mask = 0xFFFFFFFFU; |
|
139 |
CLEAR_BIT(vl_mask, (RCC_CFGR_SW | RCC_CFGR_HPRE | RCC_CFGR_PPRE | RCC_CFGR_MCOSEL)); |
|
140 |
LL_RCC_WriteReg(CFGR, vl_mask); |
|
141 |
|
|
142 |
/* Reset HSEON, CSSON, PLLON bits */ |
|
143 |
vl_mask = 0xFFFFFFFFU; |
|
144 |
CLEAR_BIT(vl_mask, (RCC_CR_PLLON | RCC_CR_CSSON | RCC_CR_HSEON)); |
|
145 |
LL_RCC_WriteReg(CR, vl_mask); |
|
146 |
|
|
147 |
/* Reset HSEBYP bit */ |
|
148 |
LL_RCC_HSE_DisableBypass(); |
|
149 |
|
|
150 |
/* Reset CFGR register */ |
|
151 |
LL_RCC_WriteReg(CFGR, 0x00000000U); |
|
152 |
|
|
153 |
#if defined(RCC_HSI48_SUPPORT) |
|
154 |
/* Reset CR2 register */ |
|
155 |
LL_RCC_WriteReg(CR2, 0x00000000U); |
|
156 |
|
|
157 |
/* Disable HSI48 */ |
|
158 |
LL_RCC_HSI48_Disable(); |
|
159 |
|
|
160 |
#endif /*RCC_HSI48_SUPPORT*/ |
|
161 |
/* Set HSI14TRIM/HSI14ON/HSI14DIS bits to the reset value*/ |
|
162 |
LL_RCC_HSI14_SetCalibTrimming(0x10U); |
|
163 |
LL_RCC_HSI14_Disable(); |
|
164 |
LL_RCC_HSI14_EnableADCControl(); |
|
165 |
|
|
166 |
/* Reset CFGR2 register */ |
|
167 |
LL_RCC_WriteReg(CFGR2, 0x00000000U); |
|
168 |
|
|
169 |
/* Reset CFGR3 register */ |
|
170 |
LL_RCC_WriteReg(CFGR3, 0x00000000U); |
|
171 |
|
|
172 |
/* Clear pending flags */ |
|
173 |
#if defined(RCC_HSI48_SUPPORT) |
|
174 |
vl_mask = (LL_RCC_CIR_LSIRDYC | LL_RCC_CIR_LSERDYC | LL_RCC_CIR_HSIRDYC | LL_RCC_CIR_HSERDYC | LL_RCC_CIR_PLLRDYC | LL_RCC_CIR_HSI14RDYC | LL_RCC_CIR_HSI48RDYC | LL_RCC_CIR_CSSC); |
|
175 |
#else |
|
176 |
vl_mask = (LL_RCC_CIR_LSIRDYC | LL_RCC_CIR_LSERDYC | LL_RCC_CIR_HSIRDYC | LL_RCC_CIR_HSERDYC | LL_RCC_CIR_PLLRDYC | LL_RCC_CIR_HSI14RDYC | LL_RCC_CIR_CSSC); |
|
177 |
#endif /* RCC_HSI48_SUPPORT */ |
|
178 |
SET_BIT(RCC->CIR, vl_mask); |
|
179 |
|
|
180 |
/* Disable all interrupts */ |
|
181 |
LL_RCC_WriteReg(CIR, 0x00000000U); |
|
182 |
|
|
183 |
return SUCCESS; |
|
184 |
} |
|
185 |
|
|
186 |
/** |
|
187 |
* @} |
|
188 |
*/ |
|
189 |
|
|
190 |
/** @addtogroup RCC_LL_EF_Get_Freq |
|
191 |
* @brief Return the frequencies of different on chip clocks; System, AHB and APB1 buses clocks |
|
192 |
* and different peripheral clocks available on the device. |
|
193 |
* @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(**) |
|
194 |
* @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(***) |
|
195 |
* @note If SYSCLK source is PLL, function returns values based on |
|
196 |
* HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors. |
|
197 |
* @note (**) HSI_VALUE is a defined constant but the real value may vary |
|
198 |
* depending on the variations in voltage and temperature. |
|
199 |
* @note (***) HSE_VALUE is a defined constant, user has to ensure that |
|
200 |
* HSE_VALUE is same as the real frequency of the crystal used. |
|
201 |
* Otherwise, this function may have wrong result. |
|
202 |
* @note The result of this function could be incorrect when using fractional |
|
203 |
* value for HSE crystal. |
|
204 |
* @note This function can be used by the user application to compute the |
|
205 |
* baud-rate for the communication peripherals or configure other parameters. |
|
206 |
* @{ |
|
207 |
*/ |
|
208 |
|
|
209 |
/** |
|
210 |
* @brief Return the frequencies of different on chip clocks; System, AHB and APB1 buses clocks |
|
211 |
* @note Each time SYSCLK, HCLK and/or PCLK1 clock changes, this function |
|
212 |
* must be called to update structure fields. Otherwise, any |
|
213 |
* configuration based on this function will be incorrect. |
|
214 |
* @param RCC_Clocks pointer to a @ref LL_RCC_ClocksTypeDef structure which will hold the clocks frequencies |
|
215 |
* @retval None |
|
216 |
*/ |
|
217 |
void LL_RCC_GetSystemClocksFreq(LL_RCC_ClocksTypeDef *RCC_Clocks) |
|
218 |
{ |
|
219 |
/* Get SYSCLK frequency */ |
|
220 |
RCC_Clocks->SYSCLK_Frequency = RCC_GetSystemClockFreq(); |
|
221 |
|
|
222 |
/* HCLK clock frequency */ |
|
223 |
RCC_Clocks->HCLK_Frequency = RCC_GetHCLKClockFreq(RCC_Clocks->SYSCLK_Frequency); |
|
224 |
|
|
225 |
/* PCLK1 clock frequency */ |
|
226 |
RCC_Clocks->PCLK1_Frequency = RCC_GetPCLK1ClockFreq(RCC_Clocks->HCLK_Frequency); |
|
227 |
} |
|
228 |
|
|
229 |
/** |
|
230 |
* @brief Return USARTx clock frequency |
|
231 |
* @param USARTxSource This parameter can be one of the following values: |
|
232 |
* @arg @ref LL_RCC_USART1_CLKSOURCE |
|
233 |
* @arg @ref LL_RCC_USART2_CLKSOURCE (*) |
|
234 |
* @arg @ref LL_RCC_USART3_CLKSOURCE (*) |
|
235 |
* |
|
236 |
* (*) value not defined in all devices. |
|
237 |
* @retval USART clock frequency (in Hz) |
|
238 |
* @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready |
|
239 |
*/ |
|
240 |
uint32_t LL_RCC_GetUSARTClockFreq(uint32_t USARTxSource) |
|
241 |
{ |
|
242 |
uint32_t usart_frequency = LL_RCC_PERIPH_FREQUENCY_NO; |
|
243 |
|
|
244 |
/* Check parameter */ |
|
245 |
assert_param(IS_LL_RCC_USART_CLKSOURCE(USARTxSource)); |
|
246 |
#if defined(RCC_CFGR3_USART1SW) |
|
247 |
if (USARTxSource == LL_RCC_USART1_CLKSOURCE) |
|
248 |
{ |
|
249 |
/* USART1CLK clock frequency */ |
|
250 |
switch (LL_RCC_GetUSARTClockSource(USARTxSource)) |
|
251 |
{ |
|
252 |
case LL_RCC_USART1_CLKSOURCE_SYSCLK: /* USART1 Clock is System Clock */ |
|
253 |
usart_frequency = RCC_GetSystemClockFreq(); |
|
254 |
break; |
|
255 |
|
|
256 |
case LL_RCC_USART1_CLKSOURCE_HSI: /* USART1 Clock is HSI Osc. */ |
|
257 |
if (LL_RCC_HSI_IsReady()) |
|
258 |
{ |
|
259 |
usart_frequency = HSI_VALUE; |
|
260 |
} |
|
261 |
break; |
|
262 |
|
|
263 |
case LL_RCC_USART1_CLKSOURCE_LSE: /* USART1 Clock is LSE Osc. */ |
|
264 |
if (LL_RCC_LSE_IsReady()) |
|
265 |
{ |
|
266 |
usart_frequency = LSE_VALUE; |
|
267 |
} |
|
268 |
break; |
|
269 |
|
|
270 |
case LL_RCC_USART1_CLKSOURCE_PCLK1: /* USART1 Clock is PCLK1 */ |
|
271 |
default: |
|
272 |
usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); |
|
273 |
break; |
|
274 |
} |
|
275 |
} |
|
276 |
#endif /* RCC_CFGR3_USART1SW */ |
|
277 |
|
|
278 |
#if defined(RCC_CFGR3_USART2SW) |
|
279 |
if (USARTxSource == LL_RCC_USART2_CLKSOURCE) |
|
280 |
{ |
|
281 |
/* USART2CLK clock frequency */ |
|
282 |
switch (LL_RCC_GetUSARTClockSource(USARTxSource)) |
|
283 |
{ |
|
284 |
case LL_RCC_USART2_CLKSOURCE_SYSCLK: /* USART2 Clock is System Clock */ |
|
285 |
usart_frequency = RCC_GetSystemClockFreq(); |
|
286 |
break; |
|
287 |
|
|
288 |
case LL_RCC_USART2_CLKSOURCE_HSI: /* USART2 Clock is HSI Osc. */ |
|
289 |
if (LL_RCC_HSI_IsReady()) |
|
290 |
{ |
|
291 |
usart_frequency = HSI_VALUE; |
|
292 |
} |
|
293 |
break; |
|
294 |
|
|
295 |
case LL_RCC_USART2_CLKSOURCE_LSE: /* USART2 Clock is LSE Osc. */ |
|
296 |
if (LL_RCC_LSE_IsReady()) |
|
297 |
{ |
|
298 |
usart_frequency = LSE_VALUE; |
|
299 |
} |
|
300 |
break; |
|
301 |
|
|
302 |
case LL_RCC_USART2_CLKSOURCE_PCLK1: /* USART2 Clock is PCLK1 */ |
|
303 |
default: |
|
304 |
usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); |
|
305 |
break; |
|
306 |
} |
|
307 |
} |
|
308 |
#endif /* RCC_CFGR3_USART2SW */ |
|
309 |
|
|
310 |
#if defined(RCC_CFGR3_USART3SW) |
|
311 |
if (USARTxSource == LL_RCC_USART3_CLKSOURCE) |
|
312 |
{ |
|
313 |
/* USART3CLK clock frequency */ |
|
314 |
switch (LL_RCC_GetUSARTClockSource(USARTxSource)) |
|
315 |
{ |
|
316 |
case LL_RCC_USART3_CLKSOURCE_SYSCLK: /* USART3 Clock is System Clock */ |
|
317 |
usart_frequency = RCC_GetSystemClockFreq(); |
|
318 |
break; |
|
319 |
|
|
320 |
case LL_RCC_USART3_CLKSOURCE_HSI: /* USART3 Clock is HSI Osc. */ |
|
321 |
if (LL_RCC_HSI_IsReady()) |
|
322 |
{ |
|
323 |
usart_frequency = HSI_VALUE; |
|
324 |
} |
|
325 |
break; |
|
326 |
|
|
327 |
case LL_RCC_USART3_CLKSOURCE_LSE: /* USART3 Clock is LSE Osc. */ |
|
328 |
if (LL_RCC_LSE_IsReady()) |
|
329 |
{ |
|
330 |
usart_frequency = LSE_VALUE; |
|
331 |
} |
|
332 |
break; |
|
333 |
|
|
334 |
case LL_RCC_USART3_CLKSOURCE_PCLK1: /* USART3 Clock is PCLK1 */ |
|
335 |
default: |
|
336 |
usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); |
|
337 |
break; |
|
338 |
} |
|
339 |
} |
|
340 |
|
|
341 |
#endif /* RCC_CFGR3_USART3SW */ |
|
342 |
return usart_frequency; |
|
343 |
} |
|
344 |
|
|
345 |
/** |
|
346 |
* @brief Return I2Cx clock frequency |
|
347 |
* @param I2CxSource This parameter can be one of the following values: |
|
348 |
* @arg @ref LL_RCC_I2C1_CLKSOURCE |
|
349 |
* @retval I2C clock frequency (in Hz) |
|
350 |
* @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that HSI oscillator is not ready |
|
351 |
*/ |
|
352 |
uint32_t LL_RCC_GetI2CClockFreq(uint32_t I2CxSource) |
|
353 |
{ |
|
354 |
uint32_t i2c_frequency = LL_RCC_PERIPH_FREQUENCY_NO; |
|
355 |
|
|
356 |
/* Check parameter */ |
|
357 |
assert_param(IS_LL_RCC_I2C_CLKSOURCE(I2CxSource)); |
|
358 |
|
|
359 |
/* I2C1 CLK clock frequency */ |
|
360 |
if (I2CxSource == LL_RCC_I2C1_CLKSOURCE) |
|
361 |
{ |
|
362 |
switch (LL_RCC_GetI2CClockSource(I2CxSource)) |
|
363 |
{ |
|
364 |
case LL_RCC_I2C1_CLKSOURCE_SYSCLK: /* I2C1 Clock is System Clock */ |
|
365 |
i2c_frequency = RCC_GetSystemClockFreq(); |
|
366 |
break; |
|
367 |
|
|
368 |
case LL_RCC_I2C1_CLKSOURCE_HSI: /* I2C1 Clock is HSI Osc. */ |
|
369 |
default: |
|
370 |
if (LL_RCC_HSI_IsReady()) |
|
371 |
{ |
|
372 |
i2c_frequency = HSI_VALUE; |
|
373 |
} |
|
374 |
break; |
|
375 |
} |
|
376 |
} |
|
377 |
|
|
378 |
return i2c_frequency; |
|
379 |
} |
|
380 |
|
|
381 |
#if defined(USB) |
|
382 |
/** |
|
383 |
* @brief Return USBx clock frequency |
|
384 |
* @param USBxSource This parameter can be one of the following values: |
|
385 |
* @arg @ref LL_RCC_USB_CLKSOURCE |
|
386 |
* @retval USB clock frequency (in Hz) |
|
387 |
* @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI48) or PLL is not ready |
|
388 |
* @arg @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected |
|
389 |
*/ |
|
390 |
uint32_t LL_RCC_GetUSBClockFreq(uint32_t USBxSource) |
|
391 |
{ |
|
392 |
uint32_t usb_frequency = LL_RCC_PERIPH_FREQUENCY_NO; |
|
393 |
|
|
394 |
/* Check parameter */ |
|
395 |
assert_param(IS_LL_RCC_USB_CLKSOURCE(USBxSource)); |
|
396 |
|
|
397 |
/* USBCLK clock frequency */ |
|
398 |
switch (LL_RCC_GetUSBClockSource(USBxSource)) |
|
399 |
{ |
|
400 |
case LL_RCC_USB_CLKSOURCE_PLL: /* PLL clock used as USB clock source */ |
|
401 |
if (LL_RCC_PLL_IsReady()) |
|
402 |
{ |
|
403 |
usb_frequency = RCC_PLL_GetFreqDomain_SYS(); |
|
404 |
} |
|
405 |
break; |
|
406 |
|
|
407 |
#if defined(RCC_CFGR3_USBSW_HSI48) |
|
408 |
case LL_RCC_USB_CLKSOURCE_HSI48: /* HSI48 clock used as USB clock source */ |
|
409 |
default: |
|
410 |
if (LL_RCC_HSI48_IsReady()) |
|
411 |
{ |
|
412 |
usb_frequency = HSI48_VALUE; |
|
413 |
} |
|
414 |
break; |
|
415 |
#else |
|
416 |
case LL_RCC_USB_CLKSOURCE_NONE: /* No clock used as USB clock source */ |
|
417 |
default: |
|
418 |
usb_frequency = LL_RCC_PERIPH_FREQUENCY_NA; |
|
419 |
break; |
|
420 |
#endif /* RCC_CFGR3_USBSW_HSI48 */ |
|
421 |
} |
|
422 |
|
|
423 |
return usb_frequency; |
|
424 |
} |
|
425 |
#endif /* USB */ |
|
426 |
|
|
427 |
#if defined(CEC) |
|
428 |
/** |
|
429 |
* @brief Return CECx clock frequency |
|
430 |
* @param CECxSource This parameter can be one of the following values: |
|
431 |
* @arg @ref LL_RCC_CEC_CLKSOURCE |
|
432 |
* @retval CEC clock frequency (in Hz) |
|
433 |
* @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillators (HSI or LSE) are not ready |
|
434 |
*/ |
|
435 |
uint32_t LL_RCC_GetCECClockFreq(uint32_t CECxSource) |
|
436 |
{ |
|
437 |
uint32_t cec_frequency = LL_RCC_PERIPH_FREQUENCY_NO; |
|
438 |
|
|
439 |
/* Check parameter */ |
|
440 |
assert_param(IS_LL_RCC_CEC_CLKSOURCE(CECxSource)); |
|
441 |
|
|
442 |
/* CECCLK clock frequency */ |
|
443 |
switch (LL_RCC_GetCECClockSource(CECxSource)) |
|
444 |
{ |
|
445 |
case LL_RCC_CEC_CLKSOURCE_HSI_DIV244: /* HSI / 244 clock used as CEC clock source */ |
|
446 |
if (LL_RCC_HSI_IsReady()) |
|
447 |
{ |
|
448 |
cec_frequency = HSI_VALUE / 244U; |
|
449 |
} |
|
450 |
break; |
|
451 |
|
|
452 |
case LL_RCC_CEC_CLKSOURCE_LSE: /* LSE clock used as CEC clock source */ |
|
453 |
default: |
|
454 |
if (LL_RCC_LSE_IsReady()) |
|
455 |
{ |
|
456 |
cec_frequency = LSE_VALUE; |
|
457 |
} |
|
458 |
break; |
|
459 |
} |
|
460 |
|
|
461 |
return cec_frequency; |
|
462 |
} |
|
463 |
#endif /* CEC */ |
|
464 |
|
|
465 |
/** |
|
466 |
* @} |
|
467 |
*/ |
|
468 |
|
|
469 |
/** |
|
470 |
* @} |
|
471 |
*/ |
|
472 |
|
|
473 |
/** @addtogroup RCC_LL_Private_Functions |
|
474 |
* @{ |
|
475 |
*/ |
|
476 |
|
|
477 |
/** |
|
478 |
* @brief Return SYSTEM clock frequency |
|
479 |
* @retval SYSTEM clock frequency (in Hz) |
|
480 |
*/ |
|
481 |
uint32_t RCC_GetSystemClockFreq(void) |
|
482 |
{ |
|
483 |
uint32_t frequency = 0U; |
|
484 |
|
|
485 |
/* Get SYSCLK source -------------------------------------------------------*/ |
|
486 |
switch (LL_RCC_GetSysClkSource()) |
|
487 |
{ |
|
488 |
case LL_RCC_SYS_CLKSOURCE_STATUS_HSI: /* HSI used as system clock source */ |
|
489 |
frequency = HSI_VALUE; |
|
490 |
break; |
|
491 |
|
|
492 |
case LL_RCC_SYS_CLKSOURCE_STATUS_HSE: /* HSE used as system clock source */ |
|
493 |
frequency = HSE_VALUE; |
|
494 |
break; |
|
495 |
|
|
496 |
case LL_RCC_SYS_CLKSOURCE_STATUS_PLL: /* PLL used as system clock source */ |
|
497 |
frequency = RCC_PLL_GetFreqDomain_SYS(); |
|
498 |
break; |
|
499 |
|
|
500 |
#if defined(RCC_HSI48_SUPPORT) |
|
501 |
case LL_RCC_SYS_CLKSOURCE_STATUS_HSI48:/* HSI48 used as system clock source */ |
|
502 |
frequency = HSI48_VALUE; |
|
503 |
break; |
|
504 |
#endif /* RCC_HSI48_SUPPORT */ |
|
505 |
|
|
506 |
default: |
|
507 |
frequency = HSI_VALUE; |
|
508 |
break; |
|
509 |
} |
|
510 |
|
|
511 |
return frequency; |
|
512 |
} |
|
513 |
|
|
514 |
/** |
|
515 |
* @brief Return HCLK clock frequency |
|
516 |
* @param SYSCLK_Frequency SYSCLK clock frequency |
|
517 |
* @retval HCLK clock frequency (in Hz) |
|
518 |
*/ |
|
519 |
uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency) |
|
520 |
{ |
|
521 |
/* HCLK clock frequency */ |
|
522 |
return __LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, LL_RCC_GetAHBPrescaler()); |
|
523 |
} |
|
524 |
|
|
525 |
/** |
|
526 |
* @brief Return PCLK1 clock frequency |
|
527 |
* @param HCLK_Frequency HCLK clock frequency |
|
528 |
* @retval PCLK1 clock frequency (in Hz) |
|
529 |
*/ |
|
530 |
uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency) |
|
531 |
{ |
|
532 |
/* PCLK1 clock frequency */ |
|
533 |
return __LL_RCC_CALC_PCLK1_FREQ(HCLK_Frequency, LL_RCC_GetAPB1Prescaler()); |
|
534 |
} |
|
535 |
/** |
|
536 |
* @brief Return PLL clock frequency used for system domain |
|
537 |
* @retval PLL clock frequency (in Hz) |
|
538 |
*/ |
|
539 |
uint32_t RCC_PLL_GetFreqDomain_SYS(void) |
|
540 |
{ |
|
541 |
uint32_t pllinputfreq = 0U, pllsource = 0U; |
|
542 |
|
|
543 |
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL divider) * PLL Multiplicator */ |
|
544 |
|
|
545 |
/* Get PLL source */ |
|
546 |
pllsource = LL_RCC_PLL_GetMainSource(); |
|
547 |
|
|
548 |
switch (pllsource) |
|
549 |
{ |
|
550 |
#if defined(RCC_PLLSRC_PREDIV1_SUPPORT) |
|
551 |
case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */ |
|
552 |
pllinputfreq = HSI_VALUE; |
|
553 |
#else |
|
554 |
case LL_RCC_PLLSOURCE_HSI_DIV_2: /* HSI used as PLL clock source */ |
|
555 |
pllinputfreq = HSI_VALUE / 2U; |
|
556 |
#endif /* RCC_PLLSRC_PREDIV1_SUPPORT */ |
|
557 |
break; |
|
558 |
|
|
559 |
#if defined(RCC_HSI48_SUPPORT) |
|
560 |
case LL_RCC_PLLSOURCE_HSI48: /* HSI48 used as PLL clock source */ |
|
561 |
pllinputfreq = HSI48_VALUE; |
|
562 |
break; |
|
563 |
#endif /* RCC_HSI48_SUPPORT */ |
|
564 |
|
|
565 |
case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */ |
|
566 |
pllinputfreq = HSE_VALUE; |
|
567 |
break; |
|
568 |
|
|
569 |
default: |
|
570 |
#if defined(RCC_PLLSRC_PREDIV1_SUPPORT) |
|
571 |
pllinputfreq = HSI_VALUE; |
|
572 |
#else |
|
573 |
pllinputfreq = HSI_VALUE / 2U; |
|
574 |
#endif /* RCC_PLLSRC_PREDIV1_SUPPORT */ |
|
575 |
break; |
|
576 |
} |
|
577 |
#if defined(RCC_PLLSRC_PREDIV1_SUPPORT) |
|
578 |
return __LL_RCC_CALC_PLLCLK_FREQ(pllinputfreq, LL_RCC_PLL_GetMultiplicator(), LL_RCC_PLL_GetPrediv()); |
|
579 |
#else |
|
580 |
return __LL_RCC_CALC_PLLCLK_FREQ((pllinputfreq / (LL_RCC_PLL_GetPrediv() + 1U)), LL_RCC_PLL_GetMultiplicator()); |
|
581 |
#endif /* RCC_PLLSRC_PREDIV1_SUPPORT */ |
|
582 |
} |
|
583 |
/** |
|
584 |
* @} |
|
585 |
*/ |
|
586 |
|
|
587 |
/** |
|
588 |
* @} |
|
589 |
*/ |
|
590 |
|
|
591 |
#endif /* defined(RCC) */ |
|
592 |
|
|
593 |
/** |
|
594 |
* @} |
|
595 |
*/ |
|
596 |
|
|
597 |
#endif /* USE_FULL_LL_DRIVER */ |
|
598 |
|
|
599 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |