]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_STM32F103_Keil/STM32F10xFWLib/src/stm32f10x_rcc.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / CORTEX_STM32F103_Keil / STM32F10xFWLib / src / stm32f10x_rcc.c
1 /******************** (C) COPYRIGHT 2007 STMicroelectronics ********************\r
2 * File Name          : stm32f10x_rcc.c\r
3 * Author             : MCD Application Team\r
4 * Date First Issued  : 09/29/2006\r
5 * Description        : This file provides all the RCC firmware functions.\r
6 ********************************************************************************\r
7 * History:\r
8 * 04/02/2007: V0.2\r
9 * 02/05/2007: V0.1\r
10 * 09/29/2006: V0.01\r
11 ********************************************************************************\r
12 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.\r
14 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,\r
15 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE\r
16 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING\r
17 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
18 *******************************************************************************/\r
19 \r
20 /* Includes ------------------------------------------------------------------*/\r
21 #include "stm32f10x_rcc.h"\r
22 \r
23 /* Private typedef -----------------------------------------------------------*/\r
24 /* Private define ------------------------------------------------------------*/\r
25 /* ------------ RCC registers bit address in the alias region ----------- */\r
26 #define RCC_OFFSET                (RCC_BASE - PERIPH_BASE)\r
27 \r
28 /* --- CR Register ---*/\r
29 /* Alias word address of HSION bit */\r
30 #define CR_OFFSET                 (RCC_OFFSET + 0x00)\r
31 #define HSION_BitNumber           0x00\r
32 #define CR_HSION_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (HSION_BitNumber * 4))\r
33 \r
34 /* Alias word address of PLLON bit */\r
35 #define PLLON_BitNumber           0x18\r
36 #define CR_PLLON_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLON_BitNumber * 4))\r
37 \r
38 /* Alias word address of CSSON bit */\r
39 #define CSSON_BitNumber           0x13\r
40 #define CR_CSSON_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (CSSON_BitNumber * 4))\r
41 \r
42 /* --- CFGR Register ---*/\r
43 /* Alias word address of USBPRE bit */\r
44 #define CFGR_OFFSET               (RCC_OFFSET + 0x04)\r
45 #define USBPRE_BitNumber          0x16\r
46 #define CFGR_USBPRE_BB            (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (USBPRE_BitNumber * 4))\r
47 \r
48 /* --- BDCR Register ---*/\r
49 /* Alias word address of RTCEN bit */\r
50 #define BDCR_OFFSET               (RCC_OFFSET + 0x20)\r
51 #define RTCEN_BitNumber           0x0F\r
52 #define BDCR_RTCEN_BB             (PERIPH_BB_BASE + (BDCR_OFFSET * 32) + (RTCEN_BitNumber * 4))\r
53 \r
54 /* Alias word address of BDRST bit */\r
55 #define BDRST_BitNumber           0x10\r
56 #define BDCR_BDRST_BB             (PERIPH_BB_BASE + (BDCR_OFFSET * 32) + (BDRST_BitNumber * 4))\r
57 \r
58 /* --- CSR Register ---*/\r
59 /* Alias word address of LSION bit */\r
60 #define CSR_OFFSET                (RCC_OFFSET + 0x24)\r
61 #define LSION_BitNumber           0x00\r
62 #define CSR_LSION_BB              (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (LSION_BitNumber * 4))\r
63 \r
64 /* ---------------------- RCC registers bit mask ------------------------ */\r
65 /* CR register bit mask */\r
66 #define CR_HSEBYP_Reset           ((u32)0xFFFBFFFF)\r
67 #define CR_HSEBYP_Set             ((u32)0x00040000)\r
68 #define CR_HSEON_Reset            ((u32)0xFFFEFFFF)\r
69 #define CR_HSEON_Set              ((u32)0x00010000)\r
70 #define CR_HSITRIM_Mask           ((u32)0xFFFFFF07)\r
71 \r
72 /* CFGR register bit mask */\r
73 #define CFGR_PLL_Mask             ((u32)0xFFC0FFFF)\r
74 #define CFGR_PLLMull_Mask         ((u32)0x003C0000)\r
75 #define CFGR_PLLSRC_Mask          ((u32)0x00010000)\r
76 #define CFGR_PLLXTPRE_Mask        ((u32)0x00020000)\r
77 #define CFGR_SWS_Mask             ((u32)0x0000000C)\r
78 #define CFGR_SW_Mask              ((u32)0xFFFFFFFC)\r
79 #define CFGR_HPRE_Reset_Mask      ((u32)0xFFFFFF0F)\r
80 #define CFGR_HPRE_Set_Mask        ((u32)0x000000F0)\r
81 #define CFGR_PPRE1_Reset_Mask     ((u32)0xFFFFF8FF)\r
82 #define CFGR_PPRE1_Set_Mask       ((u32)0x00000700)\r
83 #define CFGR_PPRE2_Reset_Mask     ((u32)0xFFFFC7FF)\r
84 #define CFGR_PPRE2_Set_Mask       ((u32)0x00003800)\r
85 #define CFGR_ADCPRE_Reset_Mask    ((u32)0xFFFF3FFF)\r
86 #define CFGR_ADCPRE_Set_Mask      ((u32)0x0000C000)\r
87 \r
88 /* CSR register bit mask */\r
89 #define CSR_RVMF_Set              ((u32)0x01000000)\r
90 \r
91 /* RCC Flag Mask */\r
92 #define FLAG_Mask                 ((u8)0x1F)\r
93 \r
94 /* Typical Value of the HSI in Hz */\r
95 #define HSI_Value                 ((u32)8000000)\r
96 \r
97 /* BDCR register base address */\r
98 #define BDCR_BASE                 (PERIPH_BASE + BDCR_OFFSET)\r
99 \r
100 /* Private macro -------------------------------------------------------------*/\r
101 /* Private variables ---------------------------------------------------------*/\r
102 static uc8 APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};\r
103 static uc8 ADCPrescTable[4] = {2, 4, 6, 8};\r
104 \r
105 /* Private function prototypes -----------------------------------------------*/\r
106 /* Private functions ---------------------------------------------------------*/\r
107 \r
108 /*******************************************************************************\r
109 * Function Name  : RCC_DeInit\r
110 * Description    : Deinitializes the RCC peripheral registers to their default\r
111 *                  reset values.\r
112 *                   - The HSITRIM[4:0] bits in RCC_CR register are not modified\r
113 *                     by this function.\r
114 *                   - The RCC_BDCR and RCC_CSR registers are not reset by this\r
115 *                     function.\r
116 * Input          : None\r
117 * Output         : None\r
118 * Return         : None\r
119 *******************************************************************************/\r
120 void RCC_DeInit(void)\r
121 {\r
122   /* Disable APB2 Peripheral Reset */\r
123   RCC->APB2RSTR = 0x00000000;\r
124 \r
125   /* Disable APB1 Peripheral Reset */\r
126   RCC->APB1RSTR = 0x00000000;\r
127 \r
128   /* FLITF and SRAM Clock ON */\r
129   RCC->AHBENR = 0x00000014;\r
130 \r
131   /* Disable APB2 Peripheral Clock */\r
132   RCC->APB2ENR = 0x00000000;\r
133 \r
134   /* Disable APB1 Peripheral Clock */\r
135   RCC->APB1ENR = 0x00000000;\r
136 \r
137   /* Set HSION bit */\r
138   RCC->CR |= (u32)0x00000001;\r
139 \r
140   /* Reset SW[1:0], HPRE[3:0], PPRE1[2:0], PPRE2[2:0], ADCPRE[1:0] and MCO[2:0] bits*/\r
141   RCC->CFGR &= 0xF8FF0000;\r
142   \r
143   /* Reset HSEON, CSSON and PLLON bits */\r
144   RCC->CR &= 0xFEF6FFFF;\r
145 \r
146   /* Reset HSEBYP bit */\r
147   RCC->CR &= 0xFFFBFFFF;\r
148 \r
149   /* Reset PLLSRC, PLLXTPRE, PLLMUL[3:0] and USBPRE bits */\r
150   RCC->CFGR &= 0xFF80FFFF;\r
151 \r
152   /* Disable all interrupts */\r
153   RCC->CIR = 0x00000000;\r
154 }\r
155 \r
156 /*******************************************************************************\r
157 * Function Name  : RCC_HSEConfig\r
158 * Description    : Configures the External High Speed oscillator (HSE).\r
159 * Input          : - RCC_HSE: specifies the new state of the HSE.\r
160 *                    This parameter can be one of the following values:\r
161 *                       - RCC_HSE_OFF: HSE oscillator OFF\r
162 *                       - RCC_HSE_ON: HSE oscillator ON\r
163 *                       - RCC_HSE_Bypass: HSE oscillator bypassed with external\r
164 *                         clock\r
165 * Output         : None\r
166 * Return         : None\r
167 *******************************************************************************/\r
168 void RCC_HSEConfig(u32 RCC_HSE)\r
169 {\r
170   /* Check the parameters */\r
171   assert(IS_RCC_HSE(RCC_HSE));\r
172 \r
173   /* Reset HSEON and HSEBYP bits before configuring the HSE ------------------*/\r
174   /* Reset HSEON bit */\r
175   RCC->CR &= CR_HSEON_Reset;\r
176 \r
177   /* Reset HSEBYP bit */\r
178   RCC->CR &= CR_HSEBYP_Reset;\r
179 \r
180   /* Configure HSE (RCC_HSE_OFF is already covered by the code section above) */\r
181   switch(RCC_HSE)\r
182   {\r
183     case RCC_HSE_ON:\r
184       /* Set HSEON bit */\r
185       RCC->CR |= CR_HSEON_Set;\r
186       break;\r
187       \r
188     case RCC_HSE_Bypass:\r
189       /* Set HSEBYP and HSEON bits */\r
190       RCC->CR |= CR_HSEBYP_Set | CR_HSEON_Set;\r
191       break;            \r
192       \r
193     default:\r
194       break;      \r
195   }\r
196 }\r
197 \r
198 /*******************************************************************************\r
199 * Function Name  : RCC_AdjustHSICalibrationValue\r
200 * Description    : Adjusts the Internal High Speed oscillator (HSI) calibration\r
201 *                  value.\r
202 * Input          : - HSICalibrationValue: specifies the calibration trimming value.\r
203 *                    This parameter must be a number between 0 and 0x1F.\r
204 * Output         : None\r
205 * Return         : None\r
206 *******************************************************************************/\r
207 void RCC_AdjustHSICalibrationValue(u8 HSICalibrationValue)\r
208 {\r
209   u32 tmpreg = 0;\r
210 \r
211   /* Check the parameters */\r
212   assert(IS_RCC_CALIBRATION_VALUE(HSICalibrationValue));\r
213 \r
214   tmpreg = RCC->CR;\r
215 \r
216   /* Clear HSITRIM[7:3] bits */\r
217   tmpreg &= CR_HSITRIM_Mask;\r
218 \r
219   /* Set the HSITRIM[7:3] bits according to HSICalibrationValue value */\r
220   tmpreg |= (u32)HSICalibrationValue << 3;\r
221 \r
222   /* Store the new value */\r
223   RCC->CR = tmpreg;\r
224 }\r
225 \r
226 /*******************************************************************************\r
227 * Function Name  : RCC_HSICmd\r
228 * Description    : Enables or disables the Internal High Speed oscillator (HSI).\r
229 *                  HSI can not be stopped if it is used directly or through the \r
230 *                  PLL as system clock, or if a Flash programmation is on going.\r
231 * Input          : - NewState: new state of the HSI.\r
232 *                    This parameter can be: ENABLE or DISABLE.\r
233 * Output         : None\r
234 * Return         : None\r
235 *******************************************************************************/\r
236 void RCC_HSICmd(FunctionalState NewState)\r
237 {\r
238   /* Check the parameters */\r
239   assert(IS_FUNCTIONAL_STATE(NewState));\r
240 \r
241   *(vu32 *) CR_HSION_BB = (u32)NewState;\r
242 }\r
243 \r
244 /*******************************************************************************\r
245 * Function Name  : RCC_PLLConfig\r
246 * Description    : Configures the PLL clock source and multiplication factor.\r
247 *                  This function must be used only when the PLL is disabled.\r
248 * Input          : - RCC_PLLSource: specifies the PLL entry clock source.\r
249 *                    This parameter can be one of the following values:\r
250 *                       - RCC_PLLSource_HSI_Div2: HSI oscillator clock divided\r
251 *                         by 2 selected as PLL clock entry\r
252 *                       - RCC_PLLSource_HSE_Div1: HSE oscillator clock selected\r
253 *                         as PLL clock entry\r
254 *                       - RCC_PLLSource_HSE_Div2: HSE oscillator clock divided\r
255 *                         by 2 selected as PLL clock entry\r
256 *                  - RCC_PLLMul: specifies the PLL multiplication factor.\r
257 *                    This parameter can be RCC_PLLMul_x where x:[2,16]\r
258 * Output         : None\r
259 * Return         : None\r
260 *******************************************************************************/\r
261 void RCC_PLLConfig(u32 RCC_PLLSource, u32 RCC_PLLMul)\r
262 {\r
263   u32 tmpreg = 0;\r
264 \r
265   /* Check the parameters */\r
266   assert(IS_RCC_PLL_SOURCE(RCC_PLLSource));\r
267   assert(IS_RCC_PLL_MUL(RCC_PLLMul));\r
268 \r
269   tmpreg = RCC->CFGR;\r
270 \r
271   /* Clear PLLSRC, PLLXTPRE and PLLMUL[21:18] bits */\r
272   tmpreg &= CFGR_PLL_Mask;\r
273 \r
274   /* Set the PLL configuration bits */\r
275   tmpreg |= RCC_PLLSource | RCC_PLLMul;\r
276 \r
277   /* Store the new value */\r
278   RCC->CFGR = tmpreg;\r
279 }\r
280 \r
281 /*******************************************************************************\r
282 * Function Name  : RCC_PLLCmd\r
283 * Description    : Enables or disables the PLL.\r
284 *                  The PLL can not be disabled if it is used as system clock.\r
285 * Input          : - NewState: new state of the PLL.\r
286 *                    This parameter can be: ENABLE or DISABLE.\r
287 * Output         : None\r
288 * Return         : None\r
289 *******************************************************************************/\r
290 void RCC_PLLCmd(FunctionalState NewState)\r
291 {\r
292   /* Check the parameters */\r
293   assert(IS_FUNCTIONAL_STATE(NewState));\r
294 \r
295   *(vu32 *) CR_PLLON_BB = (u32)NewState;\r
296 }\r
297 \r
298 /*******************************************************************************\r
299 * Function Name  : RCC_SYSCLKConfig\r
300 * Description    : Configures the system clock (SYSCLK).\r
301 * Input          : - RCC_SYSCLKSource: specifies the clock source used as system\r
302 *                    clock. This parameter can be one of the following values:\r
303 *                       - RCC_SYSCLKSource_HSI: HSI selected as system clock\r
304 *                       - RCC_SYSCLKSource_HSE: HSE selected as system clock\r
305 *                       - RCC_SYSCLKSource_PLLCLK: PLL selected as system clock\r
306 * Output         : None\r
307 * Return         : None\r
308 *******************************************************************************/\r
309 void RCC_SYSCLKConfig(u32 RCC_SYSCLKSource)\r
310 {\r
311   u32 tmpreg = 0;\r
312 \r
313   /* Check the parameters */\r
314   assert(IS_RCC_SYSCLK_SOURCE(RCC_SYSCLKSource));\r
315 \r
316   tmpreg = RCC->CFGR;\r
317 \r
318   /* Clear SW[1:0] bits */\r
319   tmpreg &= CFGR_SW_Mask;\r
320 \r
321   /* Set SW[1:0] bits according to RCC_SYSCLKSource value */\r
322   tmpreg |= RCC_SYSCLKSource;\r
323 \r
324   /* Store the new value */\r
325   RCC->CFGR = tmpreg;\r
326 }\r
327 \r
328 /*******************************************************************************\r
329 * Function Name  : RCC_GetSYSCLKSource\r
330 * Description    : Returns the clock source used as system clock.\r
331 * Input          : None\r
332 * Output         : None\r
333 * Return         : The clock source used as system clock. The returned value can\r
334 *                  be one of the following:\r
335 *                       - 0x00: HSI used as system clock\r
336 *                       - 0x04: HSE used as system clock\r
337 *                       - 0x08: PLL used as system clock\r
338 *******************************************************************************/\r
339 u8 RCC_GetSYSCLKSource(void)\r
340 {\r
341   return ((u8)(RCC->CFGR & CFGR_SWS_Mask));\r
342 }\r
343 \r
344 /*******************************************************************************\r
345 * Function Name  : RCC_HCLKConfig\r
346 * Description    : Configures the AHB clock (HCLK).\r
347 * Input          : - RCC_HCLK: defines the AHB clock. This clock is derived\r
348 *                    from the system clock (SYSCLK).\r
349 *                    This parameter can be one of the following values:\r
350 *                       - RCC_SYSCLK_Div1: AHB clock = SYSCLK\r
351 *                       - RCC_SYSCLK_Div2: AHB clock = SYSCLK/2\r
352 *                       - RCC_SYSCLK_Div4: AHB clock = SYSCLK/4\r
353 *                       - RCC_SYSCLK_Div8: AHB clock = SYSCLK/8\r
354 *                       - RCC_SYSCLK_Div16: AHB clock = SYSCLK/16\r
355 *                       - RCC_SYSCLK_Div64: AHB clock = SYSCLK/64\r
356 *                       - RCC_SYSCLK_Div128: AHB clock = SYSCLK/128\r
357 *                       - RCC_SYSCLK_Div256: AHB clock = SYSCLK/256\r
358 *                       - RCC_SYSCLK_Div512: AHB clock = SYSCLK/512\r
359 * Output         : None\r
360 * Return         : None\r
361 *******************************************************************************/\r
362 void RCC_HCLKConfig(u32 RCC_HCLK)\r
363 {\r
364   u32 tmpreg = 0;\r
365 \r
366   /* Check the parameters */\r
367   assert(IS_RCC_HCLK(RCC_HCLK));\r
368 \r
369   tmpreg = RCC->CFGR;\r
370 \r
371   /* Clear HPRE[7:4] bits */\r
372   tmpreg &= CFGR_HPRE_Reset_Mask;\r
373 \r
374   /* Set HPRE[7:4] bits according to RCC_HCLK value */\r
375   tmpreg |= RCC_HCLK;\r
376 \r
377   /* Store the new value */\r
378   RCC->CFGR = tmpreg;\r
379 }\r
380 \r
381 /*******************************************************************************\r
382 * Function Name  : RCC_PCLK1Config\r
383 * Description    : Configures the Low Speed APB clock (PCLK1).\r
384 * Input          : - RCC_PCLK1: defines the APB1 clock. This clock is derived\r
385 *                    from the AHB clock (HCLK).\r
386 *                    This parameter can be one of the following values:\r
387 *                       - RCC_HCLK_Div1: APB1 clock = HCLK\r
388 *                       - RCC_HCLK_Div2: APB1 clock = HCLK/2\r
389 *                       - RCC_HCLK_Div4: APB1 clock = HCLK/4\r
390 *                       - RCC_HCLK_Div8: APB1 clock = HCLK/8\r
391 *                       - RCC_HCLK_Div16: APB1 clock = HCLK/16\r
392 * Output         : None\r
393 * Return         : None\r
394 *******************************************************************************/\r
395 void RCC_PCLK1Config(u32 RCC_PCLK1)\r
396 {\r
397   u32 tmpreg = 0;\r
398 \r
399   /* Check the parameters */\r
400   assert(IS_RCC_PCLK(RCC_PCLK1));\r
401 \r
402   tmpreg = RCC->CFGR;\r
403 \r
404   /* Clear PPRE1[10:8] bits */\r
405   tmpreg &= CFGR_PPRE1_Reset_Mask;\r
406 \r
407   /* Set PPRE1[10:8] bits according to RCC_PCLK1 value */\r
408   tmpreg |= RCC_PCLK1;\r
409 \r
410   /* Store the new value */\r
411   RCC->CFGR = tmpreg;\r
412 }\r
413 \r
414 /*******************************************************************************\r
415 * Function Name  : RCC_PCLK2Config\r
416 * Description    : Configures the High Speed APB clock (PCLK2).\r
417 * Input          : - RCC_PCLK2: defines the APB2 clock. This clock is derived\r
418 *                    from the AHB clock (HCLK).\r
419 *                    This parameter can be one of the following values:\r
420 *                       - RCC_HCLK_Div1: APB2 clock = HCLK\r
421 *                       - RCC_HCLK_Div2: APB2 clock = HCLK/2\r
422 *                       - RCC_HCLK_Div4: APB2 clock = HCLK/4\r
423 *                       - RCC_HCLK_Div8: APB2 clock = HCLK/8\r
424 *                       - RCC_HCLK_Div16: APB2 clock = HCLK/16\r
425 * Output         : None\r
426 * Return         : None\r
427 *******************************************************************************/\r
428 void RCC_PCLK2Config(u32 RCC_PCLK2)\r
429 {\r
430   u32 tmpreg = 0;\r
431 \r
432   /* Check the parameters */\r
433   assert(IS_RCC_PCLK(RCC_PCLK2));\r
434 \r
435   tmpreg = RCC->CFGR;\r
436 \r
437   /* Clear PPRE2[13:11] bits */\r
438   tmpreg &= CFGR_PPRE2_Reset_Mask;\r
439 \r
440   /* Set PPRE2[13:11] bits according to RCC_PCLK2 value */\r
441   tmpreg |= RCC_PCLK2 << 3;\r
442 \r
443   /* Store the new value */\r
444   RCC->CFGR = tmpreg;\r
445 }\r
446 \r
447 /*******************************************************************************\r
448 * Function Name  : RCC_ITConfig\r
449 * Description    : Enables or disables the specified RCC interrupts.\r
450 * Input          : - RCC_IT: specifies the RCC interrupt sources to be enabled\r
451 *                    or disabled.\r
452 *                    This parameter can be any combination of the following values:\r
453 *                       - RCC_IT_LSIRDY: LSI ready interrupt\r
454 *                       - RCC_IT_LSERDY: LSE ready interrupt\r
455 *                       - RCC_IT_HSIRDY: HSI ready interrupt\r
456 *                       - RCC_IT_HSERDY: HSE ready interrupt\r
457 *                       - RCC_IT_PLLRDY: PLL ready interrupt\r
458 *                  - NewState: new state of the specified RCC interrupts.\r
459 *                    This parameter can be: ENABLE or DISABLE.\r
460 * Output         : None\r
461 * Return         : None\r
462 *******************************************************************************/\r
463 void RCC_ITConfig(u8 RCC_IT, FunctionalState NewState)\r
464 {\r
465   /* Check the parameters */\r
466   assert(IS_RCC_IT(RCC_IT));\r
467   assert(IS_FUNCTIONAL_STATE(NewState));\r
468 \r
469   if (NewState != DISABLE)\r
470   {\r
471     /* Perform Byte access to RCC_CIR[12:8] bits to enable the selected interrupts */\r
472     *(vu8 *) 0x40021009 |= RCC_IT;\r
473   }\r
474   else\r
475   {\r
476     /* Perform Byte access to RCC_CIR[12:8] bits to disable the selected interrupts */\r
477     *(vu8 *) 0x40021009 &= ~(u32)RCC_IT;\r
478   }\r
479 }\r
480 \r
481 /*******************************************************************************\r
482 * Function Name  : RCC_USBCLKConfig\r
483 * Description    : Configures the USB clock (USBCLK).\r
484 * Input          : - RCC_USBCLKSource: specifies the USB clock source. This clock\r
485 *                    is derived from the PLL output.\r
486 *                    This parameter can be one of the following values:\r
487 *                       - RCC_USBCLKSource_PLLCLK_1Div5: PLL clock divided by 1,5\r
488 *                         selected as USB clock source\r
489 *                       - RCC_USBCLKSource_PLLCLK_Div1: PLL clock selected as USB\r
490 *                         clock source\r
491 * Output         : None\r
492 * Return         : None\r
493 *******************************************************************************/\r
494 void RCC_USBCLKConfig(u32 RCC_USBCLKSource)\r
495 {\r
496   /* Check the parameters */\r
497   assert(IS_RCC_USBCLK_SOURCE(RCC_USBCLKSource));\r
498 \r
499   *(vu32 *) CFGR_USBPRE_BB = RCC_USBCLKSource;\r
500 }\r
501 \r
502 /*******************************************************************************\r
503 * Function Name  : RCC_ADCCLKConfig\r
504 * Description    : Configures the ADC clock (ADCCLK).\r
505 * Input          : - RCC_ADCCLK: defines the ADC clock. This clock is derived\r
506 *                    from the APB2 clock (PCLK2).\r
507 *                    This parameter can be one of the following values:\r
508 *                       - RCC_PCLK2_Div2: ADC clock = PCLK2/2\r
509 *                       - RCC_PCLK2_Div4: ADC clock = PCLK2/4\r
510 *                       - RCC_PCLK2_Div6: ADC clock = PCLK2/6\r
511 *                       - RCC_PCLK2_Div8: ADC clock = PCLK2/8\r
512 * Output         : None\r
513 * Return         : None\r
514 *******************************************************************************/\r
515 void RCC_ADCCLKConfig(u32 RCC_ADCCLK)\r
516 {\r
517   u32 tmpreg = 0;\r
518 \r
519   /* Check the parameters */\r
520   assert(IS_RCC_ADCCLK(RCC_ADCCLK));\r
521 \r
522   tmpreg = RCC->CFGR;\r
523 \r
524   /* Clear ADCPRE[15:14] bits */\r
525   tmpreg &= CFGR_ADCPRE_Reset_Mask;\r
526 \r
527   /* Set ADCPRE[15:14] bits according to RCC_ADCCLK value */\r
528   tmpreg |= RCC_ADCCLK;\r
529 \r
530   /* Store the new value */\r
531   RCC->CFGR = tmpreg;\r
532 }\r
533 \r
534 /*******************************************************************************\r
535 * Function Name  : RCC_LSEConfig\r
536 * Description    : Configures the External Low Speed oscillator (LSE).\r
537 * Input          : - RCC_LSE: specifies the new state of the LSE.\r
538 *                    This parameter can be one of the following values:\r
539 *                       - RCC_LSE_OFF: LSE oscillator OFF\r
540 *                       - RCC_LSE_ON: LSE oscillator ON\r
541 *                       - RCC_LSE_Bypass: LSE oscillator bypassed with external\r
542 *                         clock\r
543 * Output         : None\r
544 * Return         : None\r
545 *******************************************************************************/\r
546 void RCC_LSEConfig(u32 RCC_LSE)\r
547 {\r
548   /* Check the parameters */\r
549   assert(IS_RCC_LSE(RCC_LSE));\r
550 \r
551   /* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/\r
552   /* Reset LSEON bit */\r
553   *(vu8 *) BDCR_BASE = RCC_LSE_OFF;\r
554 \r
555   /* Reset LSEBYP bit */\r
556   *(vu8 *) BDCR_BASE = RCC_LSE_OFF;\r
557 \r
558   /* Configure LSE (RCC_LSE_OFF is already covered by the code section above) */\r
559   switch(RCC_LSE)\r
560   {\r
561     case RCC_LSE_ON:\r
562       /* Set LSEON bit */\r
563       *(vu8 *) BDCR_BASE = RCC_LSE_ON;\r
564       break;\r
565       \r
566     case RCC_LSE_Bypass:\r
567       /* Set LSEBYP and LSEON bits */\r
568       *(vu8 *) BDCR_BASE = RCC_LSE_Bypass | RCC_LSE_ON;\r
569       break;            \r
570       \r
571     default:\r
572       break;      \r
573   }\r
574 }\r
575 \r
576 /*******************************************************************************\r
577 * Function Name  : RCC_LSICmd\r
578 * Description    : Enables or disables the Internal Low Speed oscillator (LSI).\r
579 *                  LSI can not be disabled if the IWDG is running.\r
580 * Input          : - NewState: new state of the LSI.\r
581 *                    This parameter can be: ENABLE or DISABLE.\r
582 * Output         : None\r
583 * Return         : None\r
584 *******************************************************************************/\r
585 void RCC_LSICmd(FunctionalState NewState)\r
586 {\r
587   /* Check the parameters */\r
588   assert(IS_FUNCTIONAL_STATE(NewState));\r
589 \r
590   *(vu32 *) CSR_LSION_BB = (u32)NewState;\r
591 }\r
592 \r
593 /*******************************************************************************\r
594 * Function Name  : RCC_RTCCLKConfig\r
595 * Description    : Configures the RTC clock (RTCCLK).\r
596 *                  Once the RTC clock is selected it can\92t be changed unless the\r
597 *                  Backup domain is reset.\r
598 * Input          : - RCC_RTCCLKSource: specifies the RTC clock source.\r
599 *                    This parameter can be one of the following values:\r
600 *                       - RCC_RTCCLKSource_LSE: LSE oscillator clock used as RTC\r
601 *                         clock\r
602 *                       - RCC_RTCCLKSource_LSI: LSI oscillator clock used as RTC\r
603 *                         clock\r
604 *                       - RCC_RTCCLKSource_HSE_Div128: HSE oscillator clock divided\r
605 *                         by 128 used as RTC clock\r
606 * Output         : None\r
607 * Return         : None\r
608 *******************************************************************************/\r
609 void RCC_RTCCLKConfig(u32 RCC_RTCCLKSource)\r
610 {\r
611   /* Check the parameters */\r
612   assert(IS_RCC_RTCCLK_SOURCE(RCC_RTCCLKSource));\r
613 \r
614   /* Select the RTC clock source */\r
615   RCC->BDCR |= RCC_RTCCLKSource;\r
616 }\r
617 \r
618 /*******************************************************************************\r
619 * Function Name  : RCC_RTCCLKCmd\r
620 * Description    : Enables or disables the RTC clock.\r
621 *                  This function must be used only after the RTC clock was\r
622 *                  selected using the RCC_RTCCLKConfig function.\r
623 * Input          : - NewState: new state of the RTC clock.\r
624 *                    This parameter can be: ENABLE or DISABLE.\r
625 * Output         : None\r
626 * Return         : None\r
627 *******************************************************************************/\r
628 void RCC_RTCCLKCmd(FunctionalState NewState)\r
629 {\r
630   /* Check the parameters */\r
631   assert(IS_FUNCTIONAL_STATE(NewState));\r
632 \r
633   *(vu32 *) BDCR_RTCEN_BB = (u32)NewState;\r
634 }\r
635 \r
636 /*******************************************************************************\r
637 * Function Name  : RCC_GetClocksFreq\r
638 * Description    : Returns the frequencies of different on chip clocks.\r
639 * Input          : - RCC_Clocks: pointer to a RCC_ClocksTypeDef structure which\r
640 *                    will hold the clocks frequencies.\r
641 * Output         : None\r
642 * Return         : None\r
643 *******************************************************************************/\r
644 void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks)\r
645 {\r
646   u32 tmp = 0, pllmull = 0, pllsource = 0, presc = 0;\r
647 \r
648   /* Get SYSCLK source -------------------------------------------------------*/\r
649   tmp = RCC->CFGR & CFGR_SWS_Mask;\r
650 \r
651   switch (tmp)\r
652   {\r
653     case 0x00:  /* HSI used as system clock */\r
654       RCC_Clocks->SYSCLK_Frequency = HSI_Value;\r
655       break;\r
656 \r
657     case 0x04:  /* HSE used as system clock */\r
658       RCC_Clocks->SYSCLK_Frequency = HSE_Value;\r
659       break;\r
660 \r
661     case 0x08:  /* PLL used as system clock */\r
662       /* Get PLL clock source and multiplication factor ----------------------*/\r
663       pllmull = RCC->CFGR & CFGR_PLLMull_Mask;\r
664       pllmull = ( pllmull >> 18) + 2;\r
665 \r
666       pllsource = RCC->CFGR & CFGR_PLLSRC_Mask;\r
667 \r
668       if (pllsource == 0x00)\r
669       {/* HSI oscillator clock divided by 2 selected as PLL clock entry */\r
670         RCC_Clocks->SYSCLK_Frequency = (HSI_Value >> 1) * pllmull;\r
671       }\r
672       else\r
673       {/* HSE selected as PLL clock entry */\r
674 \r
675         if ((RCC->CFGR & CFGR_PLLXTPRE_Mask) != (u32)RESET)\r
676         {/* HSE oscillator clock divided by 2 */\r
677 \r
678           RCC_Clocks->SYSCLK_Frequency = (HSE_Value >> 1) * pllmull;\r
679         }\r
680         else\r
681         {\r
682           RCC_Clocks->SYSCLK_Frequency = HSE_Value * pllmull;\r
683         }\r
684       }\r
685       break;\r
686 \r
687     default:\r
688       RCC_Clocks->SYSCLK_Frequency = HSI_Value;\r
689       break;\r
690   }\r
691 \r
692   /* Compute HCLK, PCLK1, PCLK2 and ADCCLK clocks frequencies ----------------*/\r
693   /* Get HCLK prescaler */\r
694   tmp = RCC->CFGR & CFGR_HPRE_Set_Mask;\r
695   tmp = tmp >> 4;\r
696   presc = APBAHBPrescTable[tmp];\r
697 \r
698   /* HCLK clock frequency */\r
699   RCC_Clocks->HCLK_Frequency = RCC_Clocks->SYSCLK_Frequency >> presc;\r
700 \r
701   /* Get PCLK1 prescaler */\r
702   tmp = RCC->CFGR & CFGR_PPRE1_Set_Mask;\r
703   tmp = tmp >> 8;\r
704   presc = APBAHBPrescTable[tmp];\r
705 \r
706   /* PCLK1 clock frequency */\r
707   RCC_Clocks->PCLK1_Frequency = RCC_Clocks->HCLK_Frequency >> presc;\r
708 \r
709   /* Get PCLK2 prescaler */\r
710   tmp = RCC->CFGR & CFGR_PPRE2_Set_Mask;\r
711   tmp = tmp >> 11;\r
712   presc = APBAHBPrescTable[tmp];\r
713 \r
714   /* PCLK2 clock frequency */\r
715   RCC_Clocks->PCLK2_Frequency = RCC_Clocks->HCLK_Frequency >> presc;\r
716 \r
717   /* Get ADCCLK prescaler */\r
718   tmp = RCC->CFGR & CFGR_ADCPRE_Set_Mask;\r
719   tmp = tmp >> 14;\r
720   presc = ADCPrescTable[tmp];\r
721 \r
722   /* ADCCLK clock frequency */\r
723   RCC_Clocks->ADCCLK_Frequency = RCC_Clocks->PCLK2_Frequency / presc;\r
724 }\r
725 \r
726 /*******************************************************************************\r
727 * Function Name  : RCC_AHBPeriphClockCmd\r
728 * Description    : Enables or disables the AHB peripheral clock.\r
729 * Input          : - RCC_AHBPeriph: specifies the AHB peripheral to gates its clock.\r
730 *                    This parameter can be any combination of the following values:\r
731 *                       - RCC_AHBPeriph_DMA\r
732 *                       - RCC_AHBPeriph_SRAM\r
733 *                       - RCC_AHBPeriph_FLITF\r
734 *                    SRAM and FLITF clock can be disabled only during sleep mode.\r
735 *                  - NewState: new state of the specified peripheral clock.\r
736 *                    This parameter can be: ENABLE or DISABLE.\r
737 * Output         : None\r
738 * Return         : None\r
739 *******************************************************************************/\r
740 void RCC_AHBPeriphClockCmd(u32 RCC_AHBPeriph, FunctionalState NewState)\r
741 {\r
742   /* Check the parameters */\r
743   assert(IS_RCC_AHB_PERIPH(RCC_AHBPeriph));\r
744   assert(IS_FUNCTIONAL_STATE(NewState));\r
745 \r
746   if (NewState != DISABLE)\r
747   {\r
748     RCC->AHBENR |= RCC_AHBPeriph;\r
749   }\r
750   else\r
751   {\r
752     RCC->AHBENR &= ~RCC_AHBPeriph;\r
753   }\r
754 }\r
755 \r
756 /*******************************************************************************\r
757 * Function Name  : RCC_APB2PeriphClockCmd\r
758 * Description    : Enables or disables the High Speed APB (APB2) peripheral clock.\r
759 * Input          : - RCC_APB2Periph: specifies the APB2 peripheral to gates its\r
760 *                    clock.\r
761 *                    This parameter can be any combination of the following values:\r
762 *                       - RCC_APB2Periph_AFIO, RCC_APB2Periph_GPIOA, RCC_APB2Periph_GPIOB\r
763 *                         RCC_APB2Periph_GPIOC, RCC_APB2Periph_GPIOD, RCC_APB2Periph_GPIOE\r
764 *                         RCC_APB2Periph_ADC1, RCC_APB2Periph_ADC2, RCC_APB2Periph_TIM1\r
765 *                         RCC_APB2Periph_SPI1, RCC_APB2Periph_USART1, RCC_APB2Periph_ALL\r
766 *                  - NewState: new state of the specified peripheral clock.\r
767 *                    This parameter can be: ENABLE or DISABLE.\r
768 * Output         : None\r
769 * Return         : None\r
770 *******************************************************************************/\r
771 void RCC_APB2PeriphClockCmd(u32 RCC_APB2Periph, FunctionalState NewState)\r
772 {\r
773   /* Check the parameters */\r
774   assert(IS_RCC_APB2_PERIPH(RCC_APB2Periph));\r
775   assert(IS_FUNCTIONAL_STATE(NewState));\r
776 \r
777   if (NewState != DISABLE)\r
778   {\r
779     RCC->APB2ENR |= RCC_APB2Periph;\r
780   }\r
781   else\r
782   {\r
783     RCC->APB2ENR &= ~RCC_APB2Periph;\r
784   }\r
785 }\r
786 \r
787 /*******************************************************************************\r
788 * Function Name  : RCC_APB1PeriphClockCmd\r
789 * Description    : Enables or disables the Low Speed APB (APB1) peripheral clock.\r
790 * Input          : - RCC_APB1Periph: specifies the APB1 peripheral to gates its\r
791 *                    clock.\r
792 *                    This parameter can be any combination of the following values:\r
793 *                       - RCC_APB1Periph_TIM2, RCC_APB1Periph_TIM3, RCC_APB1Periph_TIM4\r
794 *                         RCC_APB1Periph_WWDG, RCC_APB1Periph_SPI2, RCC_APB1Periph_USART2\r
795 *                         RCC_APB1Periph_USART3, RCC_APB1Periph_I2C1, RCC_APB1Periph_I2C2\r
796 *                         RCC_APB1Periph_USB, RCC_APB1Periph_CAN, RCC_APB1Periph_BKP\r
797 *                         RCC_APB1Periph_PWR, RCC_APB1Periph_ALL\r
798 *                  - NewState: new state of the specified peripheral clock.\r
799 *                    This parameter can be: ENABLE or DISABLE.\r
800 * Output         : None\r
801 * Return         : None\r
802 *******************************************************************************/\r
803 void RCC_APB1PeriphClockCmd(u32 RCC_APB1Periph, FunctionalState NewState)\r
804 {\r
805   /* Check the parameters */\r
806   assert(IS_RCC_APB1_PERIPH(RCC_APB1Periph));\r
807   assert(IS_FUNCTIONAL_STATE(NewState));\r
808 \r
809   if (NewState != DISABLE)\r
810   {\r
811     RCC->APB1ENR |= RCC_APB1Periph;\r
812   }\r
813   else\r
814   {\r
815     RCC->APB1ENR &= ~RCC_APB1Periph;\r
816   }\r
817 }\r
818 \r
819 /*******************************************************************************\r
820 * Function Name  : RCC_APB2PeriphResetCmd\r
821 * Description    : Forces or releases High Speed APB (APB2) peripheral reset.\r
822 * Input          : - RCC_APB2Periph: specifies the APB2 peripheral to reset.\r
823 *                    This parameter can be any combination of the following values:\r
824 *                       - RCC_APB2Periph_AFIO, RCC_APB2Periph_GPIOA, RCC_APB2Periph_GPIOB\r
825 *                         RCC_APB2Periph_GPIOC, RCC_APB2Periph_GPIOD, RCC_APB2Periph_GPIOE\r
826 *                         RCC_APB2Periph_ADC1, RCC_APB2Periph_ADC2, RCC_APB2Periph_TIM1\r
827 *                         RCC_APB2Periph_SPI1, RCC_APB2Periph_USART1, RCC_APB2Periph_ALL\r
828 *                  - NewState: new state of the specified peripheral reset.\r
829 *                    This parameter can be: ENABLE or DISABLE.\r
830 * Output         : None\r
831 * Return         : None\r
832 *******************************************************************************/\r
833 void RCC_APB2PeriphResetCmd(u32 RCC_APB2Periph, FunctionalState NewState)\r
834 {\r
835   /* Check the parameters */\r
836   assert(IS_RCC_APB2_PERIPH(RCC_APB2Periph));\r
837   assert(IS_FUNCTIONAL_STATE(NewState));\r
838 \r
839   if (NewState != DISABLE)\r
840   {\r
841     RCC->APB2RSTR |= RCC_APB2Periph;\r
842   }\r
843   else\r
844   {\r
845     RCC->APB2RSTR &= ~RCC_APB2Periph;\r
846   }\r
847 }\r
848 \r
849 /*******************************************************************************\r
850 * Function Name  : RCC_APB1PeriphResetCmd\r
851 * Description    : Forces or releases Low Speed APB (APB1) peripheral reset.\r
852 * Input          : - RCC_APB1Periph: specifies the APB1 peripheral to reset.\r
853 *                    This parameter can be any combination of the following values:\r
854 *                       - RCC_APB1Periph_TIM2, RCC_APB1Periph_TIM3, RCC_APB1Periph_TIM4\r
855 *                         RCC_APB1Periph_WWDG, RCC_APB1Periph_SPI2, RCC_APB1Periph_USART2\r
856 *                         RCC_APB1Periph_USART3, RCC_APB1Periph_I2C1, RCC_APB1Periph_I2C2\r
857 *                         RCC_APB1Periph_USB, RCC_APB1Periph_CAN, RCC_APB1Periph_BKP\r
858 *                         RCC_APB1Periph_PWR, RCC_APB1Periph_ALL\r
859 *                  - NewState: new state of the specified peripheral clock.\r
860 *                    This parameter can be: ENABLE or DISABLE.\r
861 * Output         : None\r
862 * Return         : None\r
863 *******************************************************************************/\r
864 void RCC_APB1PeriphResetCmd(u32 RCC_APB1Periph, FunctionalState NewState)\r
865 {\r
866   /* Check the parameters */\r
867   assert(IS_RCC_APB1_PERIPH(RCC_APB1Periph));\r
868   assert(IS_FUNCTIONAL_STATE(NewState));\r
869 \r
870   if (NewState != DISABLE)\r
871   {\r
872     RCC->APB1RSTR |= RCC_APB1Periph;\r
873   }\r
874   else\r
875   {\r
876     RCC->APB1RSTR &= ~RCC_APB1Periph;\r
877   }\r
878 }\r
879 \r
880 /*******************************************************************************\r
881 * Function Name  : RCC_BackupResetCmd\r
882 * Description    : Forces or releases the Backup domain reset.\r
883 * Input          : - NewState: new state of the Backup domain reset.\r
884 *                    This parameter can be: ENABLE or DISABLE.\r
885 * Output         : None\r
886 * Return         : None\r
887 *******************************************************************************/\r
888 void RCC_BackupResetCmd(FunctionalState NewState)\r
889 {\r
890   /* Check the parameters */\r
891   assert(IS_FUNCTIONAL_STATE(NewState));\r
892 \r
893   *(vu32 *) BDCR_BDRST_BB = (u32)NewState;\r
894 }\r
895 \r
896 /*******************************************************************************\r
897 * Function Name  : RCC_ClockSecuritySystemCmd\r
898 * Description    : Enables or disables the Clock Security System.\r
899 * Input          : - NewState: new state of the Clock Security System..\r
900 *                    This parameter can be: ENABLE or DISABLE.\r
901 * Output         : None\r
902 * Return         : None\r
903 *******************************************************************************/\r
904 void RCC_ClockSecuritySystemCmd(FunctionalState NewState)\r
905 {\r
906   /* Check the parameters */\r
907   assert(IS_FUNCTIONAL_STATE(NewState));\r
908 \r
909   *(vu32 *) CR_CSSON_BB = (u32)NewState;\r
910 }\r
911 \r
912 /*******************************************************************************\r
913 * Function Name  : RCC_MCOConfig\r
914 * Description    : Selects the clock source to output on MCO pin.\r
915 * Input          : - RCC_MCO: specifies the clock source to output.\r
916 *                    This parameter can be one of the following values:\r
917 *                       - RCC_MCO_NoClock: No clock selected\r
918 *                       - RCC_MCO_SYSCLK: System clock selected\r
919 *                       - RCC_MCO_HSI: HSI oscillator clock selected\r
920 *                       - RCC_MCO_HSE: HSE oscillator clock selected\r
921 *                       - RCC_MCO_PLLCLK_Div2: PLL clock divided by 2 selected\r
922 * Output         : None\r
923 * Return         : None\r
924 *******************************************************************************/\r
925 void RCC_MCOConfig(u8 RCC_MCO)\r
926 {\r
927   /* Check the parameters */\r
928   assert(IS_RCC_MCO(RCC_MCO));\r
929 \r
930   /* Perform Byte access to MCO[26:24] bits to select the MCO source */\r
931   *(vu8 *) 0x40021007 = RCC_MCO;\r
932 }\r
933 \r
934 /*******************************************************************************\r
935 * Function Name  : RCC_GetFlagStatus\r
936 * Description    : Checks whether the specified RCC flag is set or not.\r
937 * Input          : - RCC_FLAG: specifies the flag to check.\r
938 *                    This parameter can be one of the following values:\r
939 *                       - RCC_FLAG_HSIRDY: HSI oscillator clock ready\r
940 *                       - RCC_FLAG_HSERDY: HSE oscillator clock ready\r
941 *                       - RCC_FLAG_PLLRDY: PLL clock ready\r
942 *                       - RCC_FLAG_LSERDY: LSE oscillator clock ready\r
943 *                       - RCC_FLAG_LSIRDY: LSI oscillator clock ready\r
944 *                       - RCC_FLAG_PINRST: Pin reset\r
945 *                       - RCC_FLAG_PORRST: POR/PDR reset\r
946 *                       - RCC_FLAG_SFTRST: Software reset\r
947 *                       - RCC_FLAG_IWDGRST: Independent Watchdog reset\r
948 *                       - RCC_FLAG_WWDGRST: Window Watchdog reset\r
949 *                       - RCC_FLAG_LPWRRST: Low Power reset\r
950 * Output         : None\r
951 * Return         : The new state of RCC_FLAG (SET or RESET).\r
952 *******************************************************************************/\r
953 FlagStatus RCC_GetFlagStatus(u8 RCC_FLAG)\r
954 {\r
955   u32 tmp = 0;\r
956   u32 statusreg = 0;\r
957   FlagStatus bitstatus = RESET;\r
958 \r
959   /* Check the parameters */\r
960   assert(IS_RCC_FLAG(RCC_FLAG));\r
961 \r
962   /* Get the RCC register index */\r
963   tmp = RCC_FLAG >> 5;\r
964 \r
965   if (tmp == 1)               /* The flag to check is in CR register */\r
966   {\r
967     statusreg = RCC->CR;\r
968   }\r
969   else if (tmp == 2)          /* The flag to check is in BDCR register */\r
970   {\r
971     statusreg = RCC->BDCR;\r
972   }\r
973   else                       /* The flag to check is in CSR register */\r
974   {\r
975     statusreg = RCC->CSR;\r
976   }\r
977 \r
978   /* Get the flag position */\r
979   tmp = RCC_FLAG & FLAG_Mask;\r
980 \r
981   if ((statusreg & ((u32)1 << tmp)) != (u32)RESET)\r
982   {\r
983     bitstatus = SET;\r
984   }\r
985   else\r
986   {\r
987     bitstatus = RESET;\r
988   }\r
989 \r
990   /* Return the flag status */\r
991   return bitstatus;\r
992 }\r
993 \r
994 /*******************************************************************************\r
995 * Function Name  : RCC_ClearFlag\r
996 * Description    : Clears the RCC reset flags.\r
997 *                  The reset flags are: RCC_FLAG_PINRST, RCC_FLAG_PORRST,\r
998 *                  RCC_FLAG_SFTRST, RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST,\r
999 *                  RCC_FLAG_LPWRRST\r
1000 * Input          : None\r
1001 * Output         : None\r
1002 * Return         : None\r
1003 *******************************************************************************/\r
1004 void RCC_ClearFlag(void)\r
1005 {\r
1006   /* Set RVMF bit to clear the reset flags */\r
1007   RCC->CSR |= CSR_RVMF_Set;\r
1008 }\r
1009 \r
1010 /*******************************************************************************\r
1011 * Function Name  : RCC_GetITStatus\r
1012 * Description    : Checks whether the specified RCC interrupt has occurred or not.\r
1013 * Input          : - RCC_IT: specifies the RCC interrupt source to check.\r
1014 *                    This parameter can be one of the following values:\r
1015 *                       - RCC_IT_LSIRDY: LSI ready interrupt\r
1016 *                       - RCC_IT_LSERDY: LSE ready interrupt\r
1017 *                       - RCC_IT_HSIRDY: HSI ready interrupt\r
1018 *                       - RCC_IT_HSERDY: HSE ready interrupt\r
1019 *                       - RCC_IT_PLLRDY: PLL ready interrupt\r
1020 *                       - RCC_IT_CSS: Clock Security System interrupt\r
1021 * Output         : None\r
1022 * Return         : The new state of RCC_IT (SET or RESET).\r
1023 *******************************************************************************/\r
1024 ITStatus RCC_GetITStatus(u8 RCC_IT)\r
1025 {\r
1026   ITStatus bitstatus = RESET;\r
1027 \r
1028   /* Check the parameters */\r
1029   assert(IS_RCC_GET_IT(RCC_IT));\r
1030 \r
1031   /* Check the status of the specified RCC interrupt */\r
1032   if ((RCC->CIR & RCC_IT) != (u32)RESET)\r
1033   {\r
1034     bitstatus = SET;\r
1035   }\r
1036   else\r
1037   {\r
1038     bitstatus = RESET;\r
1039   }\r
1040 \r
1041   /* Return the RCC_IT status */\r
1042   return  bitstatus;\r
1043 }\r
1044 \r
1045 /*******************************************************************************\r
1046 * Function Name  : RCC_ClearITPendingBit\r
1047 * Description    : Clears the RCC\92s interrupt pending bits.\r
1048 * Input          : - RCC_IT: specifies the interrupt pending bit to clear.\r
1049 *                    This parameter can be any combination of the following values:\r
1050 *                       - RCC_IT_LSIRDY: LSI ready interrupt\r
1051 *                       - RCC_IT_LSERDY: LSE ready interrupt\r
1052 *                       - RCC_IT_HSIRDY: HSI ready interrupt\r
1053 *                       - RCC_IT_HSERDY: HSE ready interrupt\r
1054 *                       - RCC_IT_PLLRDY: PLL ready interrupt\r
1055 *                       - RCC_IT_CSS: Clock Security System interrupt\r
1056 * Output         : None\r
1057 * Return         : None\r
1058 *******************************************************************************/\r
1059 void RCC_ClearITPendingBit(u8 RCC_IT)\r
1060 {\r
1061   /* Check the parameters */\r
1062   assert(IS_RCC_CLEAR_IT(RCC_IT));\r
1063 \r
1064   /* Perform Byte access to RCC_CIR[23:16] bits to clear the selected interrupt\r
1065      pending bits */\r
1066   *(vu8 *) 0x4002100A = RCC_IT;\r
1067 }\r
1068 \r
1069 /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/\r