Merge pull request #93 from zyp/master
[fw/stlink] / example / libs_stm / src / stm32f10x / stm32f10x_rcc.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32f10x_rcc.c\r
4   * @author  MCD Application Team\r
5   * @version V3.3.0\r
6   * @date    04/16/2010\r
7   * @brief   This file provides all the RCC firmware functions.\r
8   ******************************************************************************\r
9   * @copy\r
10   *\r
11   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
12   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
13   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
14   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
15   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
16   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
17   *\r
18   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>\r
19   */ \r
20 \r
21 /* Includes ------------------------------------------------------------------*/\r
22 #include "stm32f10x_rcc.h"\r
23 \r
24 /** @addtogroup STM32F10x_StdPeriph_Driver\r
25   * @{\r
26   */\r
27 \r
28 /** @defgroup RCC \r
29   * @brief RCC driver modules\r
30   * @{\r
31   */ \r
32 \r
33 /** @defgroup RCC_Private_TypesDefinitions\r
34   * @{\r
35   */\r
36 \r
37 /**\r
38   * @}\r
39   */\r
40 \r
41 /** @defgroup RCC_Private_Defines\r
42   * @{\r
43   */\r
44 \r
45 /* ------------ RCC registers bit address in the alias region ----------- */\r
46 #define RCC_OFFSET                (RCC_BASE - PERIPH_BASE)\r
47 \r
48 /* --- CR Register ---*/\r
49 \r
50 /* Alias word address of HSION bit */\r
51 #define CR_OFFSET                 (RCC_OFFSET + 0x00)\r
52 #define HSION_BitNumber           0x00\r
53 #define CR_HSION_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (HSION_BitNumber * 4))\r
54 \r
55 /* Alias word address of PLLON bit */\r
56 #define PLLON_BitNumber           0x18\r
57 #define CR_PLLON_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLON_BitNumber * 4))\r
58 \r
59 #ifdef STM32F10X_CL\r
60  /* Alias word address of PLL2ON bit */\r
61  #define PLL2ON_BitNumber          0x1A\r
62  #define CR_PLL2ON_BB              (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLL2ON_BitNumber * 4))\r
63 \r
64  /* Alias word address of PLL3ON bit */\r
65  #define PLL3ON_BitNumber          0x1C\r
66  #define CR_PLL3ON_BB              (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLL3ON_BitNumber * 4))\r
67 #endif /* STM32F10X_CL */ \r
68 \r
69 /* Alias word address of CSSON bit */\r
70 #define CSSON_BitNumber           0x13\r
71 #define CR_CSSON_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (CSSON_BitNumber * 4))\r
72 \r
73 /* --- CFGR Register ---*/\r
74 \r
75 /* Alias word address of USBPRE bit */\r
76 #define CFGR_OFFSET               (RCC_OFFSET + 0x04)\r
77 \r
78 #ifndef STM32F10X_CL\r
79  #define USBPRE_BitNumber          0x16\r
80  #define CFGR_USBPRE_BB            (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (USBPRE_BitNumber * 4))\r
81 #else\r
82  #define OTGFSPRE_BitNumber        0x16\r
83  #define CFGR_OTGFSPRE_BB          (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (OTGFSPRE_BitNumber * 4))\r
84 #endif /* STM32F10X_CL */ \r
85 \r
86 /* --- BDCR Register ---*/\r
87 \r
88 /* Alias word address of RTCEN bit */\r
89 #define BDCR_OFFSET               (RCC_OFFSET + 0x20)\r
90 #define RTCEN_BitNumber           0x0F\r
91 #define BDCR_RTCEN_BB             (PERIPH_BB_BASE + (BDCR_OFFSET * 32) + (RTCEN_BitNumber * 4))\r
92 \r
93 /* Alias word address of BDRST bit */\r
94 #define BDRST_BitNumber           0x10\r
95 #define BDCR_BDRST_BB             (PERIPH_BB_BASE + (BDCR_OFFSET * 32) + (BDRST_BitNumber * 4))\r
96 \r
97 /* --- CSR Register ---*/\r
98 \r
99 /* Alias word address of LSION bit */\r
100 #define CSR_OFFSET                (RCC_OFFSET + 0x24)\r
101 #define LSION_BitNumber           0x00\r
102 #define CSR_LSION_BB              (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (LSION_BitNumber * 4))\r
103 \r
104 #ifdef STM32F10X_CL\r
105 /* --- CFGR2 Register ---*/\r
106 \r
107  /* Alias word address of I2S2SRC bit */\r
108  #define CFGR2_OFFSET              (RCC_OFFSET + 0x2C)\r
109  #define I2S2SRC_BitNumber         0x11\r
110  #define CFGR2_I2S2SRC_BB          (PERIPH_BB_BASE + (CFGR2_OFFSET * 32) + (I2S2SRC_BitNumber * 4))\r
111 \r
112  /* Alias word address of I2S3SRC bit */\r
113  #define I2S3SRC_BitNumber         0x12\r
114  #define CFGR2_I2S3SRC_BB          (PERIPH_BB_BASE + (CFGR2_OFFSET * 32) + (I2S3SRC_BitNumber * 4))\r
115 #endif /* STM32F10X_CL */\r
116 \r
117 /* ---------------------- RCC registers bit mask ------------------------ */\r
118 \r
119 /* CR register bit mask */\r
120 #define CR_HSEBYP_Reset           ((uint32_t)0xFFFBFFFF)\r
121 #define CR_HSEBYP_Set             ((uint32_t)0x00040000)\r
122 #define CR_HSEON_Reset            ((uint32_t)0xFFFEFFFF)\r
123 #define CR_HSEON_Set              ((uint32_t)0x00010000)\r
124 #define CR_HSITRIM_Mask           ((uint32_t)0xFFFFFF07)\r
125 \r
126 /* CFGR register bit mask */\r
127 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_CL) \r
128  #define CFGR_PLL_Mask            ((uint32_t)0xFFC2FFFF)\r
129 #else\r
130  #define CFGR_PLL_Mask            ((uint32_t)0xFFC0FFFF)\r
131 #endif /* STM32F10X_CL */ \r
132 \r
133 #define CFGR_PLLMull_Mask         ((uint32_t)0x003C0000)\r
134 #define CFGR_PLLSRC_Mask          ((uint32_t)0x00010000)\r
135 #define CFGR_PLLXTPRE_Mask        ((uint32_t)0x00020000)\r
136 #define CFGR_SWS_Mask             ((uint32_t)0x0000000C)\r
137 #define CFGR_SW_Mask              ((uint32_t)0xFFFFFFFC)\r
138 #define CFGR_HPRE_Reset_Mask      ((uint32_t)0xFFFFFF0F)\r
139 #define CFGR_HPRE_Set_Mask        ((uint32_t)0x000000F0)\r
140 #define CFGR_PPRE1_Reset_Mask     ((uint32_t)0xFFFFF8FF)\r
141 #define CFGR_PPRE1_Set_Mask       ((uint32_t)0x00000700)\r
142 #define CFGR_PPRE2_Reset_Mask     ((uint32_t)0xFFFFC7FF)\r
143 #define CFGR_PPRE2_Set_Mask       ((uint32_t)0x00003800)\r
144 #define CFGR_ADCPRE_Reset_Mask    ((uint32_t)0xFFFF3FFF)\r
145 #define CFGR_ADCPRE_Set_Mask      ((uint32_t)0x0000C000)\r
146 \r
147 /* CSR register bit mask */\r
148 #define CSR_RMVF_Set              ((uint32_t)0x01000000)\r
149 \r
150 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_CL) \r
151 /* CFGR2 register bit mask */\r
152  #define CFGR2_PREDIV1SRC         ((uint32_t)0x00010000)\r
153  #define CFGR2_PREDIV1            ((uint32_t)0x0000000F)\r
154 #endif\r
155 #ifdef STM32F10X_CL\r
156  #define CFGR2_PREDIV2            ((uint32_t)0x000000F0)\r
157  #define CFGR2_PLL2MUL            ((uint32_t)0x00000F00)\r
158  #define CFGR2_PLL3MUL            ((uint32_t)0x0000F000)\r
159 #endif /* STM32F10X_CL */ \r
160 \r
161 /* RCC Flag Mask */\r
162 #define FLAG_Mask                 ((uint8_t)0x1F)\r
163 \r
164 #ifndef HSI_Value\r
165 /* Typical Value of the HSI in Hz */\r
166  #define HSI_Value                 ((uint32_t)8000000)\r
167 #endif /* HSI_Value */\r
168 \r
169 /* CIR register byte 2 (Bits[15:8]) base address */\r
170 #define CIR_BYTE2_ADDRESS         ((uint32_t)0x40021009)\r
171 \r
172 /* CIR register byte 3 (Bits[23:16]) base address */\r
173 #define CIR_BYTE3_ADDRESS         ((uint32_t)0x4002100A)\r
174 \r
175 /* CFGR register byte 4 (Bits[31:24]) base address */\r
176 #define CFGR_BYTE4_ADDRESS        ((uint32_t)0x40021007)\r
177 \r
178 /* BDCR register base address */\r
179 #define BDCR_ADDRESS              (PERIPH_BASE + BDCR_OFFSET)\r
180 \r
181 #ifndef HSEStartUp_TimeOut\r
182 /* Time out for HSE start up */\r
183  #define HSEStartUp_TimeOut        ((uint16_t)0x0500)\r
184 #endif /* HSEStartUp_TimeOut */\r
185 \r
186 /**\r
187   * @}\r
188   */ \r
189 \r
190 /** @defgroup RCC_Private_Macros\r
191   * @{\r
192   */ \r
193 \r
194 /**\r
195   * @}\r
196   */ \r
197 \r
198 /** @defgroup RCC_Private_Variables\r
199   * @{\r
200   */ \r
201 \r
202 static __I uint8_t APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};\r
203 static __I uint8_t ADCPrescTable[4] = {2, 4, 6, 8};\r
204 \r
205 /**\r
206   * @}\r
207   */\r
208 \r
209 /** @defgroup RCC_Private_FunctionPrototypes\r
210   * @{\r
211   */\r
212 \r
213 /**\r
214   * @}\r
215   */\r
216 \r
217 /** @defgroup RCC_Private_Functions\r
218   * @{\r
219   */\r
220 \r
221 /**\r
222   * @brief  Resets the RCC clock configuration to the default reset state.\r
223   * @param  None\r
224   * @retval None\r
225   */\r
226 void RCC_DeInit(void)\r
227 {\r
228   /* Set HSION bit */\r
229   RCC->CR |= (uint32_t)0x00000001;\r
230 \r
231   /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */\r
232 #ifndef STM32F10X_CL\r
233   RCC->CFGR &= (uint32_t)0xF8FF0000;\r
234 #else\r
235   RCC->CFGR &= (uint32_t)0xF0FF0000;\r
236 #endif /* STM32F10X_CL */   \r
237   \r
238   /* Reset HSEON, CSSON and PLLON bits */\r
239   RCC->CR &= (uint32_t)0xFEF6FFFF;\r
240 \r
241   /* Reset HSEBYP bit */\r
242   RCC->CR &= (uint32_t)0xFFFBFFFF;\r
243 \r
244   /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */\r
245   RCC->CFGR &= (uint32_t)0xFF80FFFF;\r
246 \r
247 #ifdef STM32F10X_CL\r
248   /* Reset PLL2ON and PLL3ON bits */\r
249   RCC->CR &= (uint32_t)0xEBFFFFFF;\r
250 \r
251   /* Disable all interrupts and clear pending bits  */\r
252   RCC->CIR = 0x00FF0000;\r
253 \r
254   /* Reset CFGR2 register */\r
255   RCC->CFGR2 = 0x00000000;\r
256 #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) \r
257   /* Disable all interrupts and clear pending bits  */\r
258   RCC->CIR = 0x009F0000;\r
259 \r
260   /* Reset CFGR2 register */\r
261   RCC->CFGR2 = 0x00000000;      \r
262 #else\r
263   /* Disable all interrupts and clear pending bits  */\r
264   RCC->CIR = 0x009F0000;\r
265 #endif /* STM32F10X_CL */\r
266 \r
267 }\r
268 \r
269 /**\r
270   * @brief  Configures the External High Speed oscillator (HSE).\r
271   * @note   HSE can not be stopped if it is used directly or through the PLL as system clock.\r
272   * @param  RCC_HSE: specifies the new state of the HSE.\r
273   *   This parameter can be one of the following values:\r
274   *     @arg RCC_HSE_OFF: HSE oscillator OFF\r
275   *     @arg RCC_HSE_ON: HSE oscillator ON\r
276   *     @arg RCC_HSE_Bypass: HSE oscillator bypassed with external clock\r
277   * @retval None\r
278   */\r
279 void RCC_HSEConfig(uint32_t RCC_HSE)\r
280 {\r
281   /* Check the parameters */\r
282   assert_param(IS_RCC_HSE(RCC_HSE));\r
283   /* Reset HSEON and HSEBYP bits before configuring the HSE ------------------*/\r
284   /* Reset HSEON bit */\r
285   RCC->CR &= CR_HSEON_Reset;\r
286   /* Reset HSEBYP bit */\r
287   RCC->CR &= CR_HSEBYP_Reset;\r
288   /* Configure HSE (RCC_HSE_OFF is already covered by the code section above) */\r
289   switch(RCC_HSE)\r
290   {\r
291     case RCC_HSE_ON:\r
292       /* Set HSEON bit */\r
293       RCC->CR |= CR_HSEON_Set;\r
294       break;\r
295       \r
296     case RCC_HSE_Bypass:\r
297       /* Set HSEBYP and HSEON bits */\r
298       RCC->CR |= CR_HSEBYP_Set | CR_HSEON_Set;\r
299       break;\r
300       \r
301     default:\r
302       break;\r
303   }\r
304 }\r
305 \r
306 /**\r
307   * @brief  Waits for HSE start-up.\r
308   * @param  None\r
309   * @retval An ErrorStatus enumuration value:\r
310   * - SUCCESS: HSE oscillator is stable and ready to use\r
311   * - ERROR: HSE oscillator not yet ready\r
312   */\r
313 ErrorStatus RCC_WaitForHSEStartUp(void)\r
314 {\r
315   __IO uint32_t StartUpCounter = 0;\r
316   ErrorStatus status = ERROR;\r
317   FlagStatus HSEStatus = RESET;\r
318   \r
319   /* Wait till HSE is ready and if Time out is reached exit */\r
320   do\r
321   {\r
322     HSEStatus = RCC_GetFlagStatus(RCC_FLAG_HSERDY);\r
323     StartUpCounter++;  \r
324   } while((StartUpCounter != HSEStartUp_TimeOut) && (HSEStatus == RESET));\r
325   \r
326   if (RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET)\r
327   {\r
328     status = SUCCESS;\r
329   }\r
330   else\r
331   {\r
332     status = ERROR;\r
333   }  \r
334   return (status);\r
335 }\r
336 \r
337 /**\r
338   * @brief  Adjusts the Internal High Speed oscillator (HSI) calibration value.\r
339   * @param  HSICalibrationValue: specifies the calibration trimming value.\r
340   *   This parameter must be a number between 0 and 0x1F.\r
341   * @retval None\r
342   */\r
343 void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue)\r
344 {\r
345   uint32_t tmpreg = 0;\r
346   /* Check the parameters */\r
347   assert_param(IS_RCC_CALIBRATION_VALUE(HSICalibrationValue));\r
348   tmpreg = RCC->CR;\r
349   /* Clear HSITRIM[4:0] bits */\r
350   tmpreg &= CR_HSITRIM_Mask;\r
351   /* Set the HSITRIM[4:0] bits according to HSICalibrationValue value */\r
352   tmpreg |= (uint32_t)HSICalibrationValue << 3;\r
353   /* Store the new value */\r
354   RCC->CR = tmpreg;\r
355 }\r
356 \r
357 /**\r
358   * @brief  Enables or disables the Internal High Speed oscillator (HSI).\r
359   * @note   HSI can not be stopped if it is used directly or through the PLL as system clock.\r
360   * @param  NewState: new state of the HSI. This parameter can be: ENABLE or DISABLE.\r
361   * @retval None\r
362   */\r
363 void RCC_HSICmd(FunctionalState NewState)\r
364 {\r
365   /* Check the parameters */\r
366   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
367   *(__IO uint32_t *) CR_HSION_BB = (uint32_t)NewState;\r
368 }\r
369 \r
370 /**\r
371   * @brief  Configures the PLL clock source and multiplication factor.\r
372   * @note   This function must be used only when the PLL is disabled.\r
373   * @param  RCC_PLLSource: specifies the PLL entry clock source.\r
374   *   For @b STM32_Connectivity_line_devices or @b STM32_Value_line_devices, \r
375   *   this parameter can be one of the following values:\r
376   *     @arg RCC_PLLSource_HSI_Div2: HSI oscillator clock divided by 2 selected as PLL clock entry\r
377   *     @arg RCC_PLLSource_PREDIV1: PREDIV1 clock selected as PLL clock entry\r
378   *   For @b other_STM32_devices, this parameter can be one of the following values:\r
379   *     @arg RCC_PLLSource_HSI_Div2: HSI oscillator clock divided by 2 selected as PLL clock entry\r
380   *     @arg RCC_PLLSource_HSE_Div1: HSE oscillator clock selected as PLL clock entry\r
381   *     @arg RCC_PLLSource_HSE_Div2: HSE oscillator clock divided by 2 selected as PLL clock entry \r
382   * @param  RCC_PLLMul: specifies the PLL multiplication factor.\r
383   *   For @b STM32_Connectivity_line_devices, this parameter can be RCC_PLLMul_x where x:{[4,9], 6_5}\r
384   *   For @b other_STM32_devices, this parameter can be RCC_PLLMul_x where x:[2,16]  \r
385   * @retval None\r
386   */\r
387 void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t RCC_PLLMul)\r
388 {\r
389   uint32_t tmpreg = 0;\r
390 \r
391   /* Check the parameters */\r
392   assert_param(IS_RCC_PLL_SOURCE(RCC_PLLSource));\r
393   assert_param(IS_RCC_PLL_MUL(RCC_PLLMul));\r
394 \r
395   tmpreg = RCC->CFGR;\r
396   /* Clear PLLSRC, PLLXTPRE and PLLMUL[3:0] bits */\r
397   tmpreg &= CFGR_PLL_Mask;\r
398   /* Set the PLL configuration bits */\r
399   tmpreg |= RCC_PLLSource | RCC_PLLMul;\r
400   /* Store the new value */\r
401   RCC->CFGR = tmpreg;\r
402 }\r
403 \r
404 /**\r
405   * @brief  Enables or disables the PLL.\r
406   * @note   The PLL can not be disabled if it is used as system clock.\r
407   * @param  NewState: new state of the PLL. This parameter can be: ENABLE or DISABLE.\r
408   * @retval None\r
409   */\r
410 void RCC_PLLCmd(FunctionalState NewState)\r
411 {\r
412   /* Check the parameters */\r
413   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
414 \r
415   *(__IO uint32_t *) CR_PLLON_BB = (uint32_t)NewState;\r
416 }\r
417 \r
418 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_CL)\r
419 /**\r
420   * @brief  Configures the PREDIV1 division factor.\r
421   * @note \r
422   *   - This function must be used only when the PLL is disabled.\r
423   *   - This function applies only to STM32 Connectivity line and Value line \r
424   *     devices.\r
425   * @param  RCC_PREDIV1_Source: specifies the PREDIV1 clock source.\r
426   *   This parameter can be one of the following values:\r
427   *     @arg RCC_PREDIV1_Source_HSE: HSE selected as PREDIV1 clock\r
428   *     @arg RCC_PREDIV1_Source_PLL2: PLL2 selected as PREDIV1 clock\r
429   * @note \r
430   *   For @b STM32_Value_line_devices this parameter is always RCC_PREDIV1_Source_HSE  \r
431   * @param  RCC_PREDIV1_Div: specifies the PREDIV1 clock division factor.\r
432   *   This parameter can be RCC_PREDIV1_Divx where x:[1,16]\r
433   * @retval None\r
434   */\r
435 void RCC_PREDIV1Config(uint32_t RCC_PREDIV1_Source, uint32_t RCC_PREDIV1_Div)\r
436 {\r
437   uint32_t tmpreg = 0;\r
438   \r
439   /* Check the parameters */\r
440   assert_param(IS_RCC_PREDIV1_SOURCE(RCC_PREDIV1_Source));\r
441   assert_param(IS_RCC_PREDIV1(RCC_PREDIV1_Div));\r
442 \r
443   tmpreg = RCC->CFGR2;\r
444   /* Clear PREDIV1[3:0] and PREDIV1SRC bits */\r
445   tmpreg &= ~(CFGR2_PREDIV1 | CFGR2_PREDIV1SRC);\r
446   /* Set the PREDIV1 clock source and division factor */\r
447   tmpreg |= RCC_PREDIV1_Source | RCC_PREDIV1_Div ;\r
448   /* Store the new value */\r
449   RCC->CFGR2 = tmpreg;\r
450 }\r
451 #endif\r
452 \r
453 #ifdef STM32F10X_CL\r
454 /**\r
455   * @brief  Configures the PREDIV2 division factor.\r
456   * @note \r
457   *   - This function must be used only when both PLL2 and PLL3 are disabled.\r
458   *   - This function applies only to STM32 Connectivity line devices.\r
459   * @param  RCC_PREDIV2_Div: specifies the PREDIV2 clock division factor.\r
460   *   This parameter can be RCC_PREDIV2_Divx where x:[1,16]\r
461   * @retval None\r
462   */\r
463 void RCC_PREDIV2Config(uint32_t RCC_PREDIV2_Div)\r
464 {\r
465   uint32_t tmpreg = 0;\r
466 \r
467   /* Check the parameters */\r
468   assert_param(IS_RCC_PREDIV2(RCC_PREDIV2_Div));\r
469 \r
470   tmpreg = RCC->CFGR2;\r
471   /* Clear PREDIV2[3:0] bits */\r
472   tmpreg &= ~CFGR2_PREDIV2;\r
473   /* Set the PREDIV2 division factor */\r
474   tmpreg |= RCC_PREDIV2_Div;\r
475   /* Store the new value */\r
476   RCC->CFGR2 = tmpreg;\r
477 }\r
478 \r
479 /**\r
480   * @brief  Configures the PLL2 multiplication factor.\r
481   * @note\r
482   *   - This function must be used only when the PLL2 is disabled.\r
483   *   - This function applies only to STM32 Connectivity line devices.\r
484   * @param  RCC_PLL2Mul: specifies the PLL2 multiplication factor.\r
485   *   This parameter can be RCC_PLL2Mul_x where x:{[8,14], 16, 20}\r
486   * @retval None\r
487   */\r
488 void RCC_PLL2Config(uint32_t RCC_PLL2Mul)\r
489 {\r
490   uint32_t tmpreg = 0;\r
491 \r
492   /* Check the parameters */\r
493   assert_param(IS_RCC_PLL2_MUL(RCC_PLL2Mul));\r
494 \r
495   tmpreg = RCC->CFGR2;\r
496   /* Clear PLL2Mul[3:0] bits */\r
497   tmpreg &= ~CFGR2_PLL2MUL;\r
498   /* Set the PLL2 configuration bits */\r
499   tmpreg |= RCC_PLL2Mul;\r
500   /* Store the new value */\r
501   RCC->CFGR2 = tmpreg;\r
502 }\r
503 \r
504 \r
505 /**\r
506   * @brief  Enables or disables the PLL2.\r
507   * @note \r
508   *   - The PLL2 can not be disabled if it is used indirectly as system clock\r
509   *     (i.e. it is used as PLL clock entry that is used as System clock).\r
510   *   - This function applies only to STM32 Connectivity line devices.\r
511   * @param  NewState: new state of the PLL2. This parameter can be: ENABLE or DISABLE.\r
512   * @retval None\r
513   */\r
514 void RCC_PLL2Cmd(FunctionalState NewState)\r
515 {\r
516   /* Check the parameters */\r
517   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
518 \r
519   *(__IO uint32_t *) CR_PLL2ON_BB = (uint32_t)NewState;\r
520 }\r
521 \r
522 \r
523 /**\r
524   * @brief  Configures the PLL3 multiplication factor.\r
525   * @note \r
526   *   - This function must be used only when the PLL3 is disabled.\r
527   *   - This function applies only to STM32 Connectivity line devices.\r
528   * @param  RCC_PLL3Mul: specifies the PLL3 multiplication factor.\r
529   *   This parameter can be RCC_PLL3Mul_x where x:{[8,14], 16, 20}\r
530   * @retval None\r
531   */\r
532 void RCC_PLL3Config(uint32_t RCC_PLL3Mul)\r
533 {\r
534   uint32_t tmpreg = 0;\r
535 \r
536   /* Check the parameters */\r
537   assert_param(IS_RCC_PLL3_MUL(RCC_PLL3Mul));\r
538 \r
539   tmpreg = RCC->CFGR2;\r
540   /* Clear PLL3Mul[3:0] bits */\r
541   tmpreg &= ~CFGR2_PLL3MUL;\r
542   /* Set the PLL3 configuration bits */\r
543   tmpreg |= RCC_PLL3Mul;\r
544   /* Store the new value */\r
545   RCC->CFGR2 = tmpreg;\r
546 }\r
547 \r
548 \r
549 /**\r
550   * @brief  Enables or disables the PLL3.\r
551   * @note   This function applies only to STM32 Connectivity line devices.\r
552   * @param  NewState: new state of the PLL3. This parameter can be: ENABLE or DISABLE.\r
553   * @retval None\r
554   */\r
555 void RCC_PLL3Cmd(FunctionalState NewState)\r
556 {\r
557   /* Check the parameters */\r
558 \r
559   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
560   *(__IO uint32_t *) CR_PLL3ON_BB = (uint32_t)NewState;\r
561 }\r
562 #endif /* STM32F10X_CL */\r
563 \r
564 /**\r
565   * @brief  Configures the system clock (SYSCLK).\r
566   * @param  RCC_SYSCLKSource: specifies the clock source used as system clock.\r
567   *   This parameter can be one of the following values:\r
568   *     @arg RCC_SYSCLKSource_HSI: HSI selected as system clock\r
569   *     @arg RCC_SYSCLKSource_HSE: HSE selected as system clock\r
570   *     @arg RCC_SYSCLKSource_PLLCLK: PLL selected as system clock\r
571   * @retval None\r
572   */\r
573 void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource)\r
574 {\r
575   uint32_t tmpreg = 0;\r
576   /* Check the parameters */\r
577   assert_param(IS_RCC_SYSCLK_SOURCE(RCC_SYSCLKSource));\r
578   tmpreg = RCC->CFGR;\r
579   /* Clear SW[1:0] bits */\r
580   tmpreg &= CFGR_SW_Mask;\r
581   /* Set SW[1:0] bits according to RCC_SYSCLKSource value */\r
582   tmpreg |= RCC_SYSCLKSource;\r
583   /* Store the new value */\r
584   RCC->CFGR = tmpreg;\r
585 }\r
586 \r
587 /**\r
588   * @brief  Returns the clock source used as system clock.\r
589   * @param  None\r
590   * @retval The clock source used as system clock. The returned value can\r
591   *   be one of the following:\r
592   *     - 0x00: HSI used as system clock\r
593   *     - 0x04: HSE used as system clock\r
594   *     - 0x08: PLL used as system clock\r
595   */\r
596 uint8_t RCC_GetSYSCLKSource(void)\r
597 {\r
598   return ((uint8_t)(RCC->CFGR & CFGR_SWS_Mask));\r
599 }\r
600 \r
601 /**\r
602   * @brief  Configures the AHB clock (HCLK).\r
603   * @param  RCC_SYSCLK: defines the AHB clock divider. This clock is derived from \r
604   *   the system clock (SYSCLK).\r
605   *   This parameter can be one of the following values:\r
606   *     @arg RCC_SYSCLK_Div1: AHB clock = SYSCLK\r
607   *     @arg RCC_SYSCLK_Div2: AHB clock = SYSCLK/2\r
608   *     @arg RCC_SYSCLK_Div4: AHB clock = SYSCLK/4\r
609   *     @arg RCC_SYSCLK_Div8: AHB clock = SYSCLK/8\r
610   *     @arg RCC_SYSCLK_Div16: AHB clock = SYSCLK/16\r
611   *     @arg RCC_SYSCLK_Div64: AHB clock = SYSCLK/64\r
612   *     @arg RCC_SYSCLK_Div128: AHB clock = SYSCLK/128\r
613   *     @arg RCC_SYSCLK_Div256: AHB clock = SYSCLK/256\r
614   *     @arg RCC_SYSCLK_Div512: AHB clock = SYSCLK/512\r
615   * @retval None\r
616   */\r
617 void RCC_HCLKConfig(uint32_t RCC_SYSCLK)\r
618 {\r
619   uint32_t tmpreg = 0;\r
620   /* Check the parameters */\r
621   assert_param(IS_RCC_HCLK(RCC_SYSCLK));\r
622   tmpreg = RCC->CFGR;\r
623   /* Clear HPRE[3:0] bits */\r
624   tmpreg &= CFGR_HPRE_Reset_Mask;\r
625   /* Set HPRE[3:0] bits according to RCC_SYSCLK value */\r
626   tmpreg |= RCC_SYSCLK;\r
627   /* Store the new value */\r
628   RCC->CFGR = tmpreg;\r
629 }\r
630 \r
631 /**\r
632   * @brief  Configures the Low Speed APB clock (PCLK1).\r
633   * @param  RCC_HCLK: defines the APB1 clock divider. This clock is derived from \r
634   *   the AHB clock (HCLK).\r
635   *   This parameter can be one of the following values:\r
636   *     @arg RCC_HCLK_Div1: APB1 clock = HCLK\r
637   *     @arg RCC_HCLK_Div2: APB1 clock = HCLK/2\r
638   *     @arg RCC_HCLK_Div4: APB1 clock = HCLK/4\r
639   *     @arg RCC_HCLK_Div8: APB1 clock = HCLK/8\r
640   *     @arg RCC_HCLK_Div16: APB1 clock = HCLK/16\r
641   * @retval None\r
642   */\r
643 void RCC_PCLK1Config(uint32_t RCC_HCLK)\r
644 {\r
645   uint32_t tmpreg = 0;\r
646   /* Check the parameters */\r
647   assert_param(IS_RCC_PCLK(RCC_HCLK));\r
648   tmpreg = RCC->CFGR;\r
649   /* Clear PPRE1[2:0] bits */\r
650   tmpreg &= CFGR_PPRE1_Reset_Mask;\r
651   /* Set PPRE1[2:0] bits according to RCC_HCLK value */\r
652   tmpreg |= RCC_HCLK;\r
653   /* Store the new value */\r
654   RCC->CFGR = tmpreg;\r
655 }\r
656 \r
657 /**\r
658   * @brief  Configures the High Speed APB clock (PCLK2).\r
659   * @param  RCC_HCLK: defines the APB2 clock divider. This clock is derived from \r
660   *   the AHB clock (HCLK).\r
661   *   This parameter can be one of the following values:\r
662   *     @arg RCC_HCLK_Div1: APB2 clock = HCLK\r
663   *     @arg RCC_HCLK_Div2: APB2 clock = HCLK/2\r
664   *     @arg RCC_HCLK_Div4: APB2 clock = HCLK/4\r
665   *     @arg RCC_HCLK_Div8: APB2 clock = HCLK/8\r
666   *     @arg RCC_HCLK_Div16: APB2 clock = HCLK/16\r
667   * @retval None\r
668   */\r
669 void RCC_PCLK2Config(uint32_t RCC_HCLK)\r
670 {\r
671   uint32_t tmpreg = 0;\r
672   /* Check the parameters */\r
673   assert_param(IS_RCC_PCLK(RCC_HCLK));\r
674   tmpreg = RCC->CFGR;\r
675   /* Clear PPRE2[2:0] bits */\r
676   tmpreg &= CFGR_PPRE2_Reset_Mask;\r
677   /* Set PPRE2[2:0] bits according to RCC_HCLK value */\r
678   tmpreg |= RCC_HCLK << 3;\r
679   /* Store the new value */\r
680   RCC->CFGR = tmpreg;\r
681 }\r
682 \r
683 /**\r
684   * @brief  Enables or disables the specified RCC interrupts.\r
685   * @param  RCC_IT: specifies the RCC interrupt sources to be enabled or disabled.\r
686   * \r
687   *   For @b STM32_Connectivity_line_devices, this parameter can be any combination\r
688   *   of the following values        \r
689   *     @arg RCC_IT_LSIRDY: LSI ready interrupt\r
690   *     @arg RCC_IT_LSERDY: LSE ready interrupt\r
691   *     @arg RCC_IT_HSIRDY: HSI ready interrupt\r
692   *     @arg RCC_IT_HSERDY: HSE ready interrupt\r
693   *     @arg RCC_IT_PLLRDY: PLL ready interrupt\r
694   *     @arg RCC_IT_PLL2RDY: PLL2 ready interrupt\r
695   *     @arg RCC_IT_PLL3RDY: PLL3 ready interrupt\r
696   * \r
697   *   For @b other_STM32_devices, this parameter can be any combination of the \r
698   *   following values        \r
699   *     @arg RCC_IT_LSIRDY: LSI ready interrupt\r
700   *     @arg RCC_IT_LSERDY: LSE ready interrupt\r
701   *     @arg RCC_IT_HSIRDY: HSI ready interrupt\r
702   *     @arg RCC_IT_HSERDY: HSE ready interrupt\r
703   *     @arg RCC_IT_PLLRDY: PLL ready interrupt\r
704   *       \r
705   * @param  NewState: new state of the specified RCC interrupts.\r
706   *   This parameter can be: ENABLE or DISABLE.\r
707   * @retval None\r
708   */\r
709 void RCC_ITConfig(uint8_t RCC_IT, FunctionalState NewState)\r
710 {\r
711   /* Check the parameters */\r
712   assert_param(IS_RCC_IT(RCC_IT));\r
713   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
714   if (NewState != DISABLE)\r
715   {\r
716     /* Perform Byte access to RCC_CIR bits to enable the selected interrupts */\r
717     *(__IO uint8_t *) CIR_BYTE2_ADDRESS |= RCC_IT;\r
718   }\r
719   else\r
720   {\r
721     /* Perform Byte access to RCC_CIR bits to disable the selected interrupts */\r
722     *(__IO uint8_t *) CIR_BYTE2_ADDRESS &= (uint8_t)~RCC_IT;\r
723   }\r
724 }\r
725 \r
726 #ifndef STM32F10X_CL\r
727 /**\r
728   * @brief  Configures the USB clock (USBCLK).\r
729   * @param  RCC_USBCLKSource: specifies the USB clock source. This clock is \r
730   *   derived from the PLL output.\r
731   *   This parameter can be one of the following values:\r
732   *     @arg RCC_USBCLKSource_PLLCLK_1Div5: PLL clock divided by 1,5 selected as USB \r
733   *                                     clock source\r
734   *     @arg RCC_USBCLKSource_PLLCLK_Div1: PLL clock selected as USB clock source\r
735   * @retval None\r
736   */\r
737 void RCC_USBCLKConfig(uint32_t RCC_USBCLKSource)\r
738 {\r
739   /* Check the parameters */\r
740   assert_param(IS_RCC_USBCLK_SOURCE(RCC_USBCLKSource));\r
741 \r
742   *(__IO uint32_t *) CFGR_USBPRE_BB = RCC_USBCLKSource;\r
743 }\r
744 #else\r
745 /**\r
746   * @brief  Configures the USB OTG FS clock (OTGFSCLK).\r
747   *   This function applies only to STM32 Connectivity line devices.\r
748   * @param  RCC_OTGFSCLKSource: specifies the USB OTG FS clock source.\r
749   *   This clock is derived from the PLL output.\r
750   *   This parameter can be one of the following values:\r
751   *     @arg  RCC_OTGFSCLKSource_PLLVCO_Div3: PLL VCO clock divided by 2 selected as USB OTG FS clock source\r
752   *     @arg  RCC_OTGFSCLKSource_PLLVCO_Div2: PLL VCO clock divided by 2 selected as USB OTG FS clock source\r
753   * @retval None\r
754   */\r
755 void RCC_OTGFSCLKConfig(uint32_t RCC_OTGFSCLKSource)\r
756 {\r
757   /* Check the parameters */\r
758   assert_param(IS_RCC_OTGFSCLK_SOURCE(RCC_OTGFSCLKSource));\r
759 \r
760   *(__IO uint32_t *) CFGR_OTGFSPRE_BB = RCC_OTGFSCLKSource;\r
761 }\r
762 #endif /* STM32F10X_CL */ \r
763 \r
764 /**\r
765   * @brief  Configures the ADC clock (ADCCLK).\r
766   * @param  RCC_PCLK2: defines the ADC clock divider. This clock is derived from \r
767   *   the APB2 clock (PCLK2).\r
768   *   This parameter can be one of the following values:\r
769   *     @arg RCC_PCLK2_Div2: ADC clock = PCLK2/2\r
770   *     @arg RCC_PCLK2_Div4: ADC clock = PCLK2/4\r
771   *     @arg RCC_PCLK2_Div6: ADC clock = PCLK2/6\r
772   *     @arg RCC_PCLK2_Div8: ADC clock = PCLK2/8\r
773   * @retval None\r
774   */\r
775 void RCC_ADCCLKConfig(uint32_t RCC_PCLK2)\r
776 {\r
777   uint32_t tmpreg = 0;\r
778   /* Check the parameters */\r
779   assert_param(IS_RCC_ADCCLK(RCC_PCLK2));\r
780   tmpreg = RCC->CFGR;\r
781   /* Clear ADCPRE[1:0] bits */\r
782   tmpreg &= CFGR_ADCPRE_Reset_Mask;\r
783   /* Set ADCPRE[1:0] bits according to RCC_PCLK2 value */\r
784   tmpreg |= RCC_PCLK2;\r
785   /* Store the new value */\r
786   RCC->CFGR = tmpreg;\r
787 }\r
788 \r
789 #ifdef STM32F10X_CL\r
790 /**\r
791   * @brief  Configures the I2S2 clock source(I2S2CLK).\r
792   * @note\r
793   *   - This function must be called before enabling I2S2 APB clock.\r
794   *   - This function applies only to STM32 Connectivity line devices.\r
795   * @param  RCC_I2S2CLKSource: specifies the I2S2 clock source.\r
796   *   This parameter can be one of the following values:\r
797   *     @arg RCC_I2S2CLKSource_SYSCLK: system clock selected as I2S2 clock entry\r
798   *     @arg RCC_I2S2CLKSource_PLL3_VCO: PLL3 VCO clock selected as I2S2 clock entry\r
799   * @retval None\r
800   */\r
801 void RCC_I2S2CLKConfig(uint32_t RCC_I2S2CLKSource)\r
802 {\r
803   /* Check the parameters */\r
804   assert_param(IS_RCC_I2S2CLK_SOURCE(RCC_I2S2CLKSource));\r
805 \r
806   *(__IO uint32_t *) CFGR2_I2S2SRC_BB = RCC_I2S2CLKSource;\r
807 }\r
808 \r
809 /**\r
810   * @brief  Configures the I2S3 clock source(I2S2CLK).\r
811   * @note\r
812   *   - This function must be called before enabling I2S3 APB clock.\r
813   *   - This function applies only to STM32 Connectivity line devices.\r
814   * @param  RCC_I2S3CLKSource: specifies the I2S3 clock source.\r
815   *   This parameter can be one of the following values:\r
816   *     @arg RCC_I2S3CLKSource_SYSCLK: system clock selected as I2S3 clock entry\r
817   *     @arg RCC_I2S3CLKSource_PLL3_VCO: PLL3 VCO clock selected as I2S3 clock entry\r
818   * @retval None\r
819   */\r
820 void RCC_I2S3CLKConfig(uint32_t RCC_I2S3CLKSource)\r
821 {\r
822   /* Check the parameters */\r
823   assert_param(IS_RCC_I2S3CLK_SOURCE(RCC_I2S3CLKSource));\r
824 \r
825   *(__IO uint32_t *) CFGR2_I2S3SRC_BB = RCC_I2S3CLKSource;\r
826 }\r
827 #endif /* STM32F10X_CL */\r
828 \r
829 /**\r
830   * @brief  Configures the External Low Speed oscillator (LSE).\r
831   * @param  RCC_LSE: specifies the new state of the LSE.\r
832   *   This parameter can be one of the following values:\r
833   *     @arg RCC_LSE_OFF: LSE oscillator OFF\r
834   *     @arg RCC_LSE_ON: LSE oscillator ON\r
835   *     @arg RCC_LSE_Bypass: LSE oscillator bypassed with external clock\r
836   * @retval None\r
837   */\r
838 void RCC_LSEConfig(uint8_t RCC_LSE)\r
839 {\r
840   /* Check the parameters */\r
841   assert_param(IS_RCC_LSE(RCC_LSE));\r
842   /* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/\r
843   /* Reset LSEON bit */\r
844   *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_OFF;\r
845   /* Reset LSEBYP bit */\r
846   *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_OFF;\r
847   /* Configure LSE (RCC_LSE_OFF is already covered by the code section above) */\r
848   switch(RCC_LSE)\r
849   {\r
850     case RCC_LSE_ON:\r
851       /* Set LSEON bit */\r
852       *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_ON;\r
853       break;\r
854       \r
855     case RCC_LSE_Bypass:\r
856       /* Set LSEBYP and LSEON bits */\r
857       *(__IO uint8_t *) BDCR_ADDRESS = RCC_LSE_Bypass | RCC_LSE_ON;\r
858       break;            \r
859       \r
860     default:\r
861       break;      \r
862   }\r
863 }\r
864 \r
865 /**\r
866   * @brief  Enables or disables the Internal Low Speed oscillator (LSI).\r
867   * @note   LSI can not be disabled if the IWDG is running.\r
868   * @param  NewState: new state of the LSI. This parameter can be: ENABLE or DISABLE.\r
869   * @retval None\r
870   */\r
871 void RCC_LSICmd(FunctionalState NewState)\r
872 {\r
873   /* Check the parameters */\r
874   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
875   *(__IO uint32_t *) CSR_LSION_BB = (uint32_t)NewState;\r
876 }\r
877 \r
878 /**\r
879   * @brief  Configures the RTC clock (RTCCLK).\r
880   * @note   Once the RTC clock is selected it can\92t be changed unless the Backup domain is reset.\r
881   * @param  RCC_RTCCLKSource: specifies the RTC clock source.\r
882   *   This parameter can be one of the following values:\r
883   *     @arg RCC_RTCCLKSource_LSE: LSE selected as RTC clock\r
884   *     @arg RCC_RTCCLKSource_LSI: LSI selected as RTC clock\r
885   *     @arg RCC_RTCCLKSource_HSE_Div128: HSE clock divided by 128 selected as RTC clock\r
886   * @retval None\r
887   */\r
888 void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource)\r
889 {\r
890   /* Check the parameters */\r
891   assert_param(IS_RCC_RTCCLK_SOURCE(RCC_RTCCLKSource));\r
892   /* Select the RTC clock source */\r
893   RCC->BDCR |= RCC_RTCCLKSource;\r
894 }\r
895 \r
896 /**\r
897   * @brief  Enables or disables the RTC clock.\r
898   * @note   This function must be used only after the RTC clock was selected using the RCC_RTCCLKConfig function.\r
899   * @param  NewState: new state of the RTC clock. This parameter can be: ENABLE or DISABLE.\r
900   * @retval None\r
901   */\r
902 void RCC_RTCCLKCmd(FunctionalState NewState)\r
903 {\r
904   /* Check the parameters */\r
905   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
906   *(__IO uint32_t *) BDCR_RTCEN_BB = (uint32_t)NewState;\r
907 }\r
908 \r
909 /**\r
910   * @brief  Returns the frequencies of different on chip clocks.\r
911   * @param  RCC_Clocks: pointer to a RCC_ClocksTypeDef structure which will hold\r
912   *   the clocks frequencies.\r
913   * @retval None\r
914   */\r
915 void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks)\r
916 {\r
917   uint32_t tmp = 0, pllmull = 0, pllsource = 0, presc = 0;\r
918 \r
919 #ifdef  STM32F10X_CL\r
920   uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = 0, pll2mull = 0;\r
921 #endif /* STM32F10X_CL */\r
922 \r
923 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL)\r
924   uint32_t prediv1factor = 0;\r
925 #endif\r
926     \r
927   /* Get SYSCLK source -------------------------------------------------------*/\r
928   tmp = RCC->CFGR & CFGR_SWS_Mask;\r
929   \r
930   switch (tmp)\r
931   {\r
932     case 0x00:  /* HSI used as system clock */\r
933       RCC_Clocks->SYSCLK_Frequency = HSI_Value;\r
934       break;\r
935     case 0x04:  /* HSE used as system clock */\r
936       RCC_Clocks->SYSCLK_Frequency = HSE_Value;\r
937       break;\r
938     case 0x08:  /* PLL used as system clock */\r
939 \r
940       /* Get PLL clock source and multiplication factor ----------------------*/\r
941       pllmull = RCC->CFGR & CFGR_PLLMull_Mask;\r
942       pllsource = RCC->CFGR & CFGR_PLLSRC_Mask;\r
943       \r
944 #ifndef STM32F10X_CL      \r
945       pllmull = ( pllmull >> 18) + 2;\r
946       \r
947       if (pllsource == 0x00)\r
948       {/* HSI oscillator clock divided by 2 selected as PLL clock entry */\r
949         RCC_Clocks->SYSCLK_Frequency = (HSI_Value >> 1) * pllmull;\r
950       }\r
951       else\r
952       {\r
953  #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL)\r
954        prediv1factor = (RCC->CFGR2 & CFGR2_PREDIV1) + 1;\r
955        /* HSE oscillator clock selected as PREDIV1 clock entry */\r
956        RCC_Clocks->SYSCLK_Frequency = (HSE_Value / prediv1factor) * pllmull; \r
957  #else\r
958         /* HSE selected as PLL clock entry */\r
959         if ((RCC->CFGR & CFGR_PLLXTPRE_Mask) != (uint32_t)RESET)\r
960         {/* HSE oscillator clock divided by 2 */\r
961           RCC_Clocks->SYSCLK_Frequency = (HSE_Value >> 1) * pllmull;\r
962         }\r
963         else\r
964         {\r
965           RCC_Clocks->SYSCLK_Frequency = HSE_Value * pllmull;\r
966         }\r
967  #endif\r
968       }\r
969 #else\r
970       pllmull = pllmull >> 18;\r
971       \r
972       if (pllmull != 0x0D)\r
973       {\r
974          pllmull += 2;\r
975       }\r
976       else\r
977       { /* PLL multiplication factor = PLL input clock * 6.5 */\r
978         pllmull = 13 / 2; \r
979       }\r
980             \r
981       if (pllsource == 0x00)\r
982       {/* HSI oscillator clock divided by 2 selected as PLL clock entry */\r
983         RCC_Clocks->SYSCLK_Frequency = (HSI_Value >> 1) * pllmull;\r
984       }\r
985       else\r
986       {/* PREDIV1 selected as PLL clock entry */\r
987         \r
988         /* Get PREDIV1 clock source and division factor */\r
989         prediv1source = RCC->CFGR2 & CFGR2_PREDIV1SRC;\r
990         prediv1factor = (RCC->CFGR2 & CFGR2_PREDIV1) + 1;\r
991         \r
992         if (prediv1source == 0)\r
993         { /* HSE oscillator clock selected as PREDIV1 clock entry */\r
994           RCC_Clocks->SYSCLK_Frequency = (HSE_Value / prediv1factor) * pllmull;          \r
995         }\r
996         else\r
997         {/* PLL2 clock selected as PREDIV1 clock entry */\r
998           \r
999           /* Get PREDIV2 division factor and PLL2 multiplication factor */\r
1000           prediv2factor = ((RCC->CFGR2 & CFGR2_PREDIV2) >> 4) + 1;\r
1001           pll2mull = ((RCC->CFGR2 & CFGR2_PLL2MUL) >> 8 ) + 2; \r
1002           RCC_Clocks->SYSCLK_Frequency = (((HSE_Value / prediv2factor) * pll2mull) / prediv1factor) * pllmull;                         \r
1003         }\r
1004       }\r
1005 #endif /* STM32F10X_CL */ \r
1006       break;\r
1007 \r
1008     default:\r
1009       RCC_Clocks->SYSCLK_Frequency = HSI_Value;\r
1010       break;\r
1011   }\r
1012 \r
1013   /* Compute HCLK, PCLK1, PCLK2 and ADCCLK clocks frequencies ----------------*/\r
1014   /* Get HCLK prescaler */\r
1015   tmp = RCC->CFGR & CFGR_HPRE_Set_Mask;\r
1016   tmp = tmp >> 4;\r
1017   presc = APBAHBPrescTable[tmp];\r
1018   /* HCLK clock frequency */\r
1019   RCC_Clocks->HCLK_Frequency = RCC_Clocks->SYSCLK_Frequency >> presc;\r
1020   /* Get PCLK1 prescaler */\r
1021   tmp = RCC->CFGR & CFGR_PPRE1_Set_Mask;\r
1022   tmp = tmp >> 8;\r
1023   presc = APBAHBPrescTable[tmp];\r
1024   /* PCLK1 clock frequency */\r
1025   RCC_Clocks->PCLK1_Frequency = RCC_Clocks->HCLK_Frequency >> presc;\r
1026   /* Get PCLK2 prescaler */\r
1027   tmp = RCC->CFGR & CFGR_PPRE2_Set_Mask;\r
1028   tmp = tmp >> 11;\r
1029   presc = APBAHBPrescTable[tmp];\r
1030   /* PCLK2 clock frequency */\r
1031   RCC_Clocks->PCLK2_Frequency = RCC_Clocks->HCLK_Frequency >> presc;\r
1032   /* Get ADCCLK prescaler */\r
1033   tmp = RCC->CFGR & CFGR_ADCPRE_Set_Mask;\r
1034   tmp = tmp >> 14;\r
1035   presc = ADCPrescTable[tmp];\r
1036   /* ADCCLK clock frequency */\r
1037   RCC_Clocks->ADCCLK_Frequency = RCC_Clocks->PCLK2_Frequency / presc;\r
1038 }\r
1039 \r
1040 /**\r
1041   * @brief  Enables or disables the AHB peripheral clock.\r
1042   * @param  RCC_AHBPeriph: specifies the AHB peripheral to gates its clock.\r
1043   *   \r
1044   *   For @b STM32_Connectivity_line_devices, this parameter can be any combination\r
1045   *   of the following values:        \r
1046   *     @arg RCC_AHBPeriph_DMA1\r
1047   *     @arg RCC_AHBPeriph_DMA2\r
1048   *     @arg RCC_AHBPeriph_SRAM\r
1049   *     @arg RCC_AHBPeriph_FLITF\r
1050   *     @arg RCC_AHBPeriph_CRC\r
1051   *     @arg RCC_AHBPeriph_OTG_FS    \r
1052   *     @arg RCC_AHBPeriph_ETH_MAC   \r
1053   *     @arg RCC_AHBPeriph_ETH_MAC_Tx\r
1054   *     @arg RCC_AHBPeriph_ETH_MAC_Rx\r
1055   * \r
1056   *   For @b other_STM32_devices, this parameter can be any combination of the \r
1057   *   following values:        \r
1058   *     @arg RCC_AHBPeriph_DMA1\r
1059   *     @arg RCC_AHBPeriph_DMA2\r
1060   *     @arg RCC_AHBPeriph_SRAM\r
1061   *     @arg RCC_AHBPeriph_FLITF\r
1062   *     @arg RCC_AHBPeriph_CRC\r
1063   *     @arg RCC_AHBPeriph_FSMC\r
1064   *     @arg RCC_AHBPeriph_SDIO\r
1065   *   \r
1066   * @note SRAM and FLITF clock can be disabled only during sleep mode.\r
1067   * @param  NewState: new state of the specified peripheral clock.\r
1068   *   This parameter can be: ENABLE or DISABLE.\r
1069   * @retval None\r
1070   */\r
1071 void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)\r
1072 {\r
1073   /* Check the parameters */\r
1074   assert_param(IS_RCC_AHB_PERIPH(RCC_AHBPeriph));\r
1075   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1076 \r
1077   if (NewState != DISABLE)\r
1078   {\r
1079     RCC->AHBENR |= RCC_AHBPeriph;\r
1080   }\r
1081   else\r
1082   {\r
1083     RCC->AHBENR &= ~RCC_AHBPeriph;\r
1084   }\r
1085 }\r
1086 \r
1087 /**\r
1088   * @brief  Enables or disables the High Speed APB (APB2) peripheral clock.\r
1089   * @param  RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.\r
1090   *   This parameter can be any combination of the following values:\r
1091   *     @arg RCC_APB2Periph_AFIO, RCC_APB2Periph_GPIOA, RCC_APB2Periph_GPIOB,\r
1092   *          RCC_APB2Periph_GPIOC, RCC_APB2Periph_GPIOD, RCC_APB2Periph_GPIOE,\r
1093   *          RCC_APB2Periph_GPIOF, RCC_APB2Periph_GPIOG, RCC_APB2Periph_ADC1,\r
1094   *          RCC_APB2Periph_ADC2, RCC_APB2Periph_TIM1, RCC_APB2Periph_SPI1,\r
1095   *          RCC_APB2Periph_TIM8, RCC_APB2Periph_USART1, RCC_APB2Periph_ADC3,\r
1096   *          RCC_APB2Periph_TIM15, RCC_APB2Periph_TIM16, RCC_APB2Periph_TIM17,\r
1097   *          RCC_APB2Periph_TIM9, RCC_APB2Periph_TIM10, RCC_APB2Periph_TIM11     \r
1098   * @param  NewState: new state of the specified peripheral clock.\r
1099   *   This parameter can be: ENABLE or DISABLE.\r
1100   * @retval None\r
1101   */\r
1102 void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)\r
1103 {\r
1104   /* Check the parameters */\r
1105   assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));\r
1106   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1107   if (NewState != DISABLE)\r
1108   {\r
1109     RCC->APB2ENR |= RCC_APB2Periph;\r
1110   }\r
1111   else\r
1112   {\r
1113     RCC->APB2ENR &= ~RCC_APB2Periph;\r
1114   }\r
1115 }\r
1116 \r
1117 /**\r
1118   * @brief  Enables or disables the Low Speed APB (APB1) peripheral clock.\r
1119   * @param  RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.\r
1120   *   This parameter can be any combination of the following values:\r
1121   *     @arg RCC_APB1Periph_TIM2, RCC_APB1Periph_TIM3, RCC_APB1Periph_TIM4,\r
1122   *          RCC_APB1Periph_TIM5, RCC_APB1Periph_TIM6, RCC_APB1Periph_TIM7,\r
1123   *          RCC_APB1Periph_WWDG, RCC_APB1Periph_SPI2, RCC_APB1Periph_SPI3,\r
1124   *          RCC_APB1Periph_USART2, RCC_APB1Periph_USART3, RCC_APB1Periph_USART4, \r
1125   *          RCC_APB1Periph_USART5, RCC_APB1Periph_I2C1, RCC_APB1Periph_I2C2,\r
1126   *          RCC_APB1Periph_USB, RCC_APB1Periph_CAN1, RCC_APB1Periph_BKP,\r
1127   *          RCC_APB1Periph_PWR, RCC_APB1Periph_DAC, RCC_APB1Periph_CEC,\r
1128   *          RCC_APB1Periph_TIM12, RCC_APB1Periph_TIM13, RCC_APB1Periph_TIM14\r
1129   * @param  NewState: new state of the specified peripheral clock.\r
1130   *   This parameter can be: ENABLE or DISABLE.\r
1131   * @retval None\r
1132   */\r
1133 void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)\r
1134 {\r
1135   /* Check the parameters */\r
1136   assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));\r
1137   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1138   if (NewState != DISABLE)\r
1139   {\r
1140     RCC->APB1ENR |= RCC_APB1Periph;\r
1141   }\r
1142   else\r
1143   {\r
1144     RCC->APB1ENR &= ~RCC_APB1Periph;\r
1145   }\r
1146 }\r
1147 \r
1148 #ifdef STM32F10X_CL\r
1149 /**\r
1150   * @brief  Forces or releases AHB peripheral reset.\r
1151   * @note   This function applies only to STM32 Connectivity line devices.\r
1152   * @param  RCC_AHBPeriph: specifies the AHB peripheral to reset.\r
1153   *   This parameter can be any combination of the following values:\r
1154   *     @arg RCC_AHBPeriph_OTG_FS \r
1155   *     @arg RCC_AHBPeriph_ETH_MAC\r
1156   * @param  NewState: new state of the specified peripheral reset.\r
1157   *   This parameter can be: ENABLE or DISABLE.\r
1158   * @retval None\r
1159   */\r
1160 void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)\r
1161 {\r
1162   /* Check the parameters */\r
1163   assert_param(IS_RCC_AHB_PERIPH_RESET(RCC_AHBPeriph));\r
1164   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1165 \r
1166   if (NewState != DISABLE)\r
1167   {\r
1168     RCC->AHBRSTR |= RCC_AHBPeriph;\r
1169   }\r
1170   else\r
1171   {\r
1172     RCC->AHBRSTR &= ~RCC_AHBPeriph;\r
1173   }\r
1174 }\r
1175 #endif /* STM32F10X_CL */ \r
1176 \r
1177 /**\r
1178   * @brief  Forces or releases High Speed APB (APB2) peripheral reset.\r
1179   * @param  RCC_APB2Periph: specifies the APB2 peripheral to reset.\r
1180   *   This parameter can be any combination of the following values:\r
1181   *     @arg RCC_APB2Periph_AFIO, RCC_APB2Periph_GPIOA, RCC_APB2Periph_GPIOB,\r
1182   *          RCC_APB2Periph_GPIOC, RCC_APB2Periph_GPIOD, RCC_APB2Periph_GPIOE,\r
1183   *          RCC_APB2Periph_GPIOF, RCC_APB2Periph_GPIOG, RCC_APB2Periph_ADC1,\r
1184   *          RCC_APB2Periph_ADC2, RCC_APB2Periph_TIM1, RCC_APB2Periph_SPI1,\r
1185   *          RCC_APB2Periph_TIM8, RCC_APB2Periph_USART1, RCC_APB2Periph_ADC3,\r
1186   *          RCC_APB2Periph_TIM15, RCC_APB2Periph_TIM16, RCC_APB2Periph_TIM17,\r
1187   *          RCC_APB2Periph_TIM9, RCC_APB2Periph_TIM10, RCC_APB2Periph_TIM11  \r
1188   * @param  NewState: new state of the specified peripheral reset.\r
1189   *   This parameter can be: ENABLE or DISABLE.\r
1190   * @retval None\r
1191   */\r
1192 void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)\r
1193 {\r
1194   /* Check the parameters */\r
1195   assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));\r
1196   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1197   if (NewState != DISABLE)\r
1198   {\r
1199     RCC->APB2RSTR |= RCC_APB2Periph;\r
1200   }\r
1201   else\r
1202   {\r
1203     RCC->APB2RSTR &= ~RCC_APB2Periph;\r
1204   }\r
1205 }\r
1206 \r
1207 /**\r
1208   * @brief  Forces or releases Low Speed APB (APB1) peripheral reset.\r
1209   * @param  RCC_APB1Periph: specifies the APB1 peripheral to reset.\r
1210   *   This parameter can be any combination of the following values:\r
1211   *     @arg RCC_APB1Periph_TIM2, RCC_APB1Periph_TIM3, RCC_APB1Periph_TIM4,\r
1212   *          RCC_APB1Periph_TIM5, RCC_APB1Periph_TIM6, RCC_APB1Periph_TIM7,\r
1213   *          RCC_APB1Periph_WWDG, RCC_APB1Periph_SPI2, RCC_APB1Periph_SPI3,\r
1214   *          RCC_APB1Periph_USART2, RCC_APB1Periph_USART3, RCC_APB1Periph_USART4, \r
1215   *          RCC_APB1Periph_USART5, RCC_APB1Periph_I2C1, RCC_APB1Periph_I2C2,\r
1216   *          RCC_APB1Periph_USB, RCC_APB1Periph_CAN1, RCC_APB1Periph_BKP,\r
1217   *          RCC_APB1Periph_PWR, RCC_APB1Periph_DAC, RCC_APB1Periph_CEC,\r
1218   *          RCC_APB1Periph_TIM12, RCC_APB1Periph_TIM13, RCC_APB1Periph_TIM14  \r
1219   * @param  NewState: new state of the specified peripheral clock.\r
1220   *   This parameter can be: ENABLE or DISABLE.\r
1221   * @retval None\r
1222   */\r
1223 void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)\r
1224 {\r
1225   /* Check the parameters */\r
1226   assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));\r
1227   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1228   if (NewState != DISABLE)\r
1229   {\r
1230     RCC->APB1RSTR |= RCC_APB1Periph;\r
1231   }\r
1232   else\r
1233   {\r
1234     RCC->APB1RSTR &= ~RCC_APB1Periph;\r
1235   }\r
1236 }\r
1237 \r
1238 /**\r
1239   * @brief  Forces or releases the Backup domain reset.\r
1240   * @param  NewState: new state of the Backup domain reset.\r
1241   *   This parameter can be: ENABLE or DISABLE.\r
1242   * @retval None\r
1243   */\r
1244 void RCC_BackupResetCmd(FunctionalState NewState)\r
1245 {\r
1246   /* Check the parameters */\r
1247   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1248   *(__IO uint32_t *) BDCR_BDRST_BB = (uint32_t)NewState;\r
1249 }\r
1250 \r
1251 /**\r
1252   * @brief  Enables or disables the Clock Security System.\r
1253   * @param  NewState: new state of the Clock Security System..\r
1254   *   This parameter can be: ENABLE or DISABLE.\r
1255   * @retval None\r
1256   */\r
1257 void RCC_ClockSecuritySystemCmd(FunctionalState NewState)\r
1258 {\r
1259   /* Check the parameters */\r
1260   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1261   *(__IO uint32_t *) CR_CSSON_BB = (uint32_t)NewState;\r
1262 }\r
1263 \r
1264 /**\r
1265   * @brief  Selects the clock source to output on MCO pin.\r
1266   * @param  RCC_MCO: specifies the clock source to output.\r
1267   *   \r
1268   *   For @b STM32_Connectivity_line_devices, this parameter can be one of the\r
1269   *   following values:       \r
1270   *     @arg RCC_MCO_NoClock: No clock selected\r
1271   *     @arg RCC_MCO_SYSCLK: System clock selected\r
1272   *     @arg RCC_MCO_HSI: HSI oscillator clock selected\r
1273   *     @arg RCC_MCO_HSE: HSE oscillator clock selected\r
1274   *     @arg RCC_MCO_PLLCLK_Div2: PLL clock divided by 2 selected\r
1275   *     @arg RCC_MCO_PLL2CLK: PLL2 clock selected                     \r
1276   *     @arg RCC_MCO_PLL3CLK_Div2: PLL3 clock divided by 2 selected   \r
1277   *     @arg RCC_MCO_XT1: External 3-25 MHz oscillator clock selected  \r
1278   *     @arg RCC_MCO_PLL3CLK: PLL3 clock selected \r
1279   * \r
1280   *   For  @b other_STM32_devices, this parameter can be one of the following values:        \r
1281   *     @arg RCC_MCO_NoClock: No clock selected\r
1282   *     @arg RCC_MCO_SYSCLK: System clock selected\r
1283   *     @arg RCC_MCO_HSI: HSI oscillator clock selected\r
1284   *     @arg RCC_MCO_HSE: HSE oscillator clock selected\r
1285   *     @arg RCC_MCO_PLLCLK_Div2: PLL clock divided by 2 selected\r
1286   *   \r
1287   * @retval None\r
1288   */\r
1289 void RCC_MCOConfig(uint8_t RCC_MCO)\r
1290 {\r
1291   /* Check the parameters */\r
1292   assert_param(IS_RCC_MCO(RCC_MCO));\r
1293 \r
1294   /* Perform Byte access to MCO bits to select the MCO source */\r
1295   *(__IO uint8_t *) CFGR_BYTE4_ADDRESS = RCC_MCO;\r
1296 }\r
1297 \r
1298 /**\r
1299   * @brief  Checks whether the specified RCC flag is set or not.\r
1300   * @param  RCC_FLAG: specifies the flag to check.\r
1301   *   \r
1302   *   For @b STM32_Connectivity_line_devices, this parameter can be one of the\r
1303   *   following values:\r
1304   *     @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready\r
1305   *     @arg RCC_FLAG_HSERDY: HSE oscillator clock ready\r
1306   *     @arg RCC_FLAG_PLLRDY: PLL clock ready\r
1307   *     @arg RCC_FLAG_PLL2RDY: PLL2 clock ready      \r
1308   *     @arg RCC_FLAG_PLL3RDY: PLL3 clock ready                           \r
1309   *     @arg RCC_FLAG_LSERDY: LSE oscillator clock ready\r
1310   *     @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready\r
1311   *     @arg RCC_FLAG_PINRST: Pin reset\r
1312   *     @arg RCC_FLAG_PORRST: POR/PDR reset\r
1313   *     @arg RCC_FLAG_SFTRST: Software reset\r
1314   *     @arg RCC_FLAG_IWDGRST: Independent Watchdog reset\r
1315   *     @arg RCC_FLAG_WWDGRST: Window Watchdog reset\r
1316   *     @arg RCC_FLAG_LPWRRST: Low Power reset\r
1317   * \r
1318   *   For @b other_STM32_devices, this parameter can be one of the following values:        \r
1319   *     @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready\r
1320   *     @arg RCC_FLAG_HSERDY: HSE oscillator clock ready\r
1321   *     @arg RCC_FLAG_PLLRDY: PLL clock ready\r
1322   *     @arg RCC_FLAG_LSERDY: LSE oscillator clock ready\r
1323   *     @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready\r
1324   *     @arg RCC_FLAG_PINRST: Pin reset\r
1325   *     @arg RCC_FLAG_PORRST: POR/PDR reset\r
1326   *     @arg RCC_FLAG_SFTRST: Software reset\r
1327   *     @arg RCC_FLAG_IWDGRST: Independent Watchdog reset\r
1328   *     @arg RCC_FLAG_WWDGRST: Window Watchdog reset\r
1329   *     @arg RCC_FLAG_LPWRRST: Low Power reset\r
1330   *   \r
1331   * @retval The new state of RCC_FLAG (SET or RESET).\r
1332   */\r
1333 FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG)\r
1334 {\r
1335   uint32_t tmp = 0;\r
1336   uint32_t statusreg = 0;\r
1337   FlagStatus bitstatus = RESET;\r
1338   /* Check the parameters */\r
1339   assert_param(IS_RCC_FLAG(RCC_FLAG));\r
1340 \r
1341   /* Get the RCC register index */\r
1342   tmp = RCC_FLAG >> 5;\r
1343   if (tmp == 1)               /* The flag to check is in CR register */\r
1344   {\r
1345     statusreg = RCC->CR;\r
1346   }\r
1347   else if (tmp == 2)          /* The flag to check is in BDCR register */\r
1348   {\r
1349     statusreg = RCC->BDCR;\r
1350   }\r
1351   else                       /* The flag to check is in CSR register */\r
1352   {\r
1353     statusreg = RCC->CSR;\r
1354   }\r
1355 \r
1356   /* Get the flag position */\r
1357   tmp = RCC_FLAG & FLAG_Mask;\r
1358   if ((statusreg & ((uint32_t)1 << tmp)) != (uint32_t)RESET)\r
1359   {\r
1360     bitstatus = SET;\r
1361   }\r
1362   else\r
1363   {\r
1364     bitstatus = RESET;\r
1365   }\r
1366 \r
1367   /* Return the flag status */\r
1368   return bitstatus;\r
1369 }\r
1370 \r
1371 /**\r
1372   * @brief  Clears the RCC reset flags.\r
1373   * @note   The reset flags are: RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST,\r
1374   *   RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST\r
1375   * @param  None\r
1376   * @retval None\r
1377   */\r
1378 void RCC_ClearFlag(void)\r
1379 {\r
1380   /* Set RMVF bit to clear the reset flags */\r
1381   RCC->CSR |= CSR_RMVF_Set;\r
1382 }\r
1383 \r
1384 /**\r
1385   * @brief  Checks whether the specified RCC interrupt has occurred or not.\r
1386   * @param  RCC_IT: specifies the RCC interrupt source to check.\r
1387   *   \r
1388   *   For @b STM32_Connectivity_line_devices, this parameter can be one of the\r
1389   *   following values:\r
1390   *     @arg RCC_IT_LSIRDY: LSI ready interrupt\r
1391   *     @arg RCC_IT_LSERDY: LSE ready interrupt\r
1392   *     @arg RCC_IT_HSIRDY: HSI ready interrupt\r
1393   *     @arg RCC_IT_HSERDY: HSE ready interrupt\r
1394   *     @arg RCC_IT_PLLRDY: PLL ready interrupt\r
1395   *     @arg RCC_IT_PLL2RDY: PLL2 ready interrupt \r
1396   *     @arg RCC_IT_PLL3RDY: PLL3 ready interrupt                      \r
1397   *     @arg RCC_IT_CSS: Clock Security System interrupt\r
1398   * \r
1399   *   For @b other_STM32_devices, this parameter can be one of the following values:        \r
1400   *     @arg RCC_IT_LSIRDY: LSI ready interrupt\r
1401   *     @arg RCC_IT_LSERDY: LSE ready interrupt\r
1402   *     @arg RCC_IT_HSIRDY: HSI ready interrupt\r
1403   *     @arg RCC_IT_HSERDY: HSE ready interrupt\r
1404   *     @arg RCC_IT_PLLRDY: PLL ready interrupt\r
1405   *     @arg RCC_IT_CSS: Clock Security System interrupt\r
1406   *   \r
1407   * @retval The new state of RCC_IT (SET or RESET).\r
1408   */\r
1409 ITStatus RCC_GetITStatus(uint8_t RCC_IT)\r
1410 {\r
1411   ITStatus bitstatus = RESET;\r
1412   /* Check the parameters */\r
1413   assert_param(IS_RCC_GET_IT(RCC_IT));\r
1414 \r
1415   /* Check the status of the specified RCC interrupt */\r
1416   if ((RCC->CIR & RCC_IT) != (uint32_t)RESET)\r
1417   {\r
1418     bitstatus = SET;\r
1419   }\r
1420   else\r
1421   {\r
1422     bitstatus = RESET;\r
1423   }\r
1424 \r
1425   /* Return the RCC_IT status */\r
1426   return  bitstatus;\r
1427 }\r
1428 \r
1429 /**\r
1430   * @brief  Clears the RCC\92s interrupt pending bits.\r
1431   * @param  RCC_IT: specifies the interrupt pending bit to clear.\r
1432   *   \r
1433   *   For @b STM32_Connectivity_line_devices, this parameter can be any combination\r
1434   *   of the following values:\r
1435   *     @arg RCC_IT_LSIRDY: LSI ready interrupt\r
1436   *     @arg RCC_IT_LSERDY: LSE ready interrupt\r
1437   *     @arg RCC_IT_HSIRDY: HSI ready interrupt\r
1438   *     @arg RCC_IT_HSERDY: HSE ready interrupt\r
1439   *     @arg RCC_IT_PLLRDY: PLL ready interrupt\r
1440   *     @arg RCC_IT_PLL2RDY: PLL2 ready interrupt \r
1441   *     @arg RCC_IT_PLL3RDY: PLL3 ready interrupt                      \r
1442   *     @arg RCC_IT_CSS: Clock Security System interrupt\r
1443   * \r
1444   *   For @b other_STM32_devices, this parameter can be any combination of the\r
1445   *   following values:        \r
1446   *     @arg RCC_IT_LSIRDY: LSI ready interrupt\r
1447   *     @arg RCC_IT_LSERDY: LSE ready interrupt\r
1448   *     @arg RCC_IT_HSIRDY: HSI ready interrupt\r
1449   *     @arg RCC_IT_HSERDY: HSE ready interrupt\r
1450   *     @arg RCC_IT_PLLRDY: PLL ready interrupt\r
1451   *   \r
1452   *     @arg RCC_IT_CSS: Clock Security System interrupt\r
1453   * @retval None\r
1454   */\r
1455 void RCC_ClearITPendingBit(uint8_t RCC_IT)\r
1456 {\r
1457   /* Check the parameters */\r
1458   assert_param(IS_RCC_CLEAR_IT(RCC_IT));\r
1459 \r
1460   /* Perform Byte access to RCC_CIR[23:16] bits to clear the selected interrupt\r
1461      pending bits */\r
1462   *(__IO uint8_t *) CIR_BYTE3_ADDRESS = RCC_IT;\r
1463 }\r
1464 \r
1465 /**\r
1466   * @}\r
1467   */\r
1468 \r
1469 /**\r
1470   * @}\r
1471   */\r
1472 \r
1473 /**\r
1474   * @}\r
1475   */\r
1476 \r
1477 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r