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