]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_STM32L152_IAR/system_and_ST_code/STM32L1xx_StdPeriph_Driver/src/stm32l1xx_rcc.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / CORTEX_STM32L152_IAR / system_and_ST_code / STM32L1xx_StdPeriph_Driver / src / stm32l1xx_rcc.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32l1xx_rcc.c\r
4   * @author  MCD Application Team\r
5   * @version V1.0.0RC1\r
6   * @date    07/02/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 "stm32l1xx_rcc.h"\r
23 \r
24 /** @addtogroup STM32L1xx_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 MSION bit */\r
56 #define MSION_BitNumber           0x08\r
57 #define CR_MSION_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (MSION_BitNumber * 4))\r
58 \r
59 /* Alias word address of PLLON bit */\r
60 #define PLLON_BitNumber           0x18\r
61 #define CR_PLLON_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLON_BitNumber * 4))\r
62 \r
63 /* Alias word address of CSSON bit */\r
64 #define CSSON_BitNumber           0x1C\r
65 #define CR_CSSON_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (CSSON_BitNumber * 4))\r
66 \r
67 /* --- CSR Register ---*/\r
68 \r
69 /* Alias word address of LSION bit */\r
70 #define CSR_OFFSET                (RCC_OFFSET + 0x34)\r
71 #define LSION_BitNumber           0x00\r
72 #define CSR_LSION_BB              (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (LSION_BitNumber * 4))\r
73 \r
74 /* Alias word address of RTCEN bit */\r
75 #define RTCEN_BitNumber           0x16\r
76 #define CSR_RTCEN_BB              (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (RTCEN_BitNumber * 4))\r
77 \r
78 /* Alias word address of RTCRST bit */\r
79 #define RTCRST_BitNumber          0x17\r
80 #define CSR_RTCRST_BB             (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (RTCRST_BitNumber * 4))\r
81 \r
82 \r
83 /* ---------------------- RCC registers mask -------------------------------- */\r
84 /* RCC Flag Mask */\r
85 #define FLAG_MASK                 ((uint8_t)0x1F)\r
86 \r
87 /* CR register byte 3 (Bits[23:16]) base address */\r
88 #define CR_BYTE3_ADDRESS          ((uint32_t)0x40023802)\r
89 \r
90 /* ICSCR register byte 4 (Bits[31:24]) base address */\r
91 #define ICSCR_BYTE4_ADDRESS       ((uint32_t)0x40023807)\r
92 \r
93 /* CFGR register byte 3 (Bits[23:16]) base address */\r
94 #define CFGR_BYTE3_ADDRESS        ((uint32_t)0x4002380A)\r
95 \r
96 /* CFGR register byte 4 (Bits[31:24]) base address */\r
97 #define CFGR_BYTE4_ADDRESS        ((uint32_t)0x4002380B)\r
98 \r
99 /* CIR register byte 2 (Bits[15:8]) base address */\r
100 #define CIR_BYTE2_ADDRESS         ((uint32_t)0x4002380D)\r
101 \r
102 /* CIR register byte 3 (Bits[23:16]) base address */\r
103 #define CIR_BYTE3_ADDRESS         ((uint32_t)0x4002380E)\r
104 \r
105 /* CSR register byte 2 (Bits[15:8]) base address */\r
106 #define CSR_BYTE2_ADDRESS         ((uint32_t)0x40023835)\r
107 \r
108 /**\r
109   * @}\r
110   */ \r
111 \r
112 /** @defgroup RCC_Private_Macros\r
113   * @{\r
114   */ \r
115 \r
116 /**\r
117   * @}\r
118   */ \r
119 \r
120 /** @defgroup RCC_Private_Variables\r
121   * @{\r
122   */ \r
123 \r
124 static __I uint8_t PLLMulTable[9] = {3, 4, 6, 8, 12, 16, 24, 32, 48};\r
125 static __I uint8_t APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};\r
126 static __I uint8_t MSITable[7] = {0, 0, 0, 0, 1, 2, 4};\r
127 \r
128 /**\r
129   * @}\r
130   */\r
131 \r
132 /** @defgroup RCC_Private_FunctionPrototypes\r
133   * @{\r
134   */\r
135 \r
136 /**\r
137   * @}\r
138   */\r
139 \r
140 /** @defgroup RCC_Private_Functions\r
141   * @{\r
142   */\r
143 \r
144 /**\r
145   * @brief  Resets the RCC clock configuration to the default reset state.\r
146   * @param  None\r
147   * @retval None\r
148   */\r
149 void RCC_DeInit(void)\r
150 {\r
151   \r
152   /* Set MSION bit */\r
153   RCC->CR |= (uint32_t)0x00000100;\r
154 \r
155   /* Reset SW[1:0], HPRE[3:0], PPRE1[2:0], PPRE2[2:0], MCOSEL[2:0] and MCOPRE[2:0] bits */\r
156   RCC->CFGR &= (uint32_t)0x88FFC00C;\r
157   \r
158   /* Reset HSION, HSEON, CSSON and PLLON bits */\r
159   RCC->CR &= (uint32_t)0xEEFEFFFE;\r
160 \r
161   /* Reset HSEBYP bit */\r
162   RCC->CR &= (uint32_t)0xFFFBFFFF;\r
163 \r
164   /* Reset PLLSRC, PLLMUL[3:0] and PLLDIV[1:0] bits */\r
165   RCC->CFGR &= (uint32_t)0xFF02FFFF;\r
166 \r
167   /* Disable all interrupts */\r
168   RCC->CIR = 0x00000000;\r
169 }\r
170 \r
171 /**\r
172   * @brief  Configures the External High Speed oscillator (HSE).\r
173   * @note   HSE can not be stopped if it is used directly or through the PLL as system clock.\r
174   * @param RCC_HSE: specifies the new state of the HSE.\r
175   *   This parameter can be one of the following values:\r
176   *     @arg RCC_HSE_OFF: HSE oscillator OFF\r
177   *     @arg RCC_HSE_ON: HSE oscillator ON\r
178   *     @arg RCC_HSE_Bypass: HSE oscillator bypassed with external clock\r
179   * @retval None\r
180   */\r
181 void RCC_HSEConfig(uint8_t RCC_HSE)\r
182 {\r
183   /* Check the parameters */\r
184   assert_param(IS_RCC_HSE(RCC_HSE));\r
185 \r
186   /* Reset HSEON and HSEBYP bits before configuring the HSE ------------------*/\r
187   *(__IO uint8_t *) CR_BYTE3_ADDRESS = RCC_HSE_OFF;\r
188 \r
189   /* Set the new HSE configuration -------------------------------------------*/\r
190   *(__IO uint8_t *) CR_BYTE3_ADDRESS = RCC_HSE;\r
191 \r
192 }\r
193 \r
194 /**\r
195   * @brief  Waits for HSE start-up.\r
196   * @param  None\r
197   * @retval An ErrorStatus enumuration value:\r
198   *          - SUCCESS: HSE oscillator is stable and ready to use\r
199   *          - ERROR: HSE oscillator not yet ready\r
200   */\r
201 ErrorStatus RCC_WaitForHSEStartUp(void)\r
202 {\r
203   __IO uint32_t StartUpCounter = 0;\r
204   ErrorStatus status = ERROR;\r
205   FlagStatus HSEStatus = RESET;\r
206   \r
207   /* Wait till HSE is ready and if Time out is reached exit */\r
208   do\r
209   {\r
210     HSEStatus = RCC_GetFlagStatus(RCC_FLAG_HSERDY);\r
211     StartUpCounter++;  \r
212   } while((StartUpCounter != HSE_STARTUP_TIMEOUT) && (HSEStatus == RESET));\r
213   \r
214   if (RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET)\r
215   {\r
216     status = SUCCESS;\r
217   }\r
218   else\r
219   {\r
220     status = ERROR;\r
221   }  \r
222   return (status);\r
223 }\r
224 \r
225 /**\r
226   * @brief  Adjusts the Internal High Speed oscillator (HSI) calibration value.\r
227   * @param  HSICalibrationValue: specifies the HSI calibration trimming value.\r
228   *   This parameter must be a number between 0 and 0x1F.\r
229   * @retval None\r
230   */\r
231 void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue)\r
232 {\r
233   uint32_t tmpreg = 0;\r
234   \r
235   /* Check the parameters */\r
236   assert_param(IS_RCC_HSI_CALIBRATION_VALUE(HSICalibrationValue));\r
237   \r
238   tmpreg = RCC->ICSCR;\r
239   \r
240   /* Clear HSITRIM[4:0] bits */\r
241   tmpreg &= ~RCC_ICSCR_HSITRIM;\r
242   \r
243   /* Set the HSITRIM[4:0] bits according to HSICalibrationValue value */\r
244   tmpreg |= (uint32_t)HSICalibrationValue << 8;\r
245 \r
246   /* Store the new value */\r
247   RCC->ICSCR = tmpreg;\r
248 }\r
249 \r
250 /**\r
251   * @brief  Adjusts the Internal Multi Speed oscillator (MSI) calibration value.\r
252   * @param  MSICalibrationValue: specifies the MSI calibration trimming value.\r
253   *   This parameter must be a number between 0 and 0xFF.\r
254   * @retval None\r
255   */\r
256 void RCC_AdjustMSICalibrationValue(uint8_t MSICalibrationValue)\r
257 {\r
258   \r
259   /* Check the parameters */\r
260   assert_param(IS_RCC_MSI_CALIBRATION_VALUE(MSICalibrationValue));\r
261 \r
262   *(__IO uint8_t *) ICSCR_BYTE4_ADDRESS = MSICalibrationValue;  \r
263 }\r
264 \r
265 /**\r
266   * @brief  Configures the Internal Multi Speed oscillator (MSI) clock range.\r
267   * @param  RCC_MSIRange: specifies the MSI Clcok range.\r
268   *   This parameter must be one of the following values:\r
269   *     @arg RCC_MSIRange_64KHz:  MSI clock is around 64 KHz\r
270   *     @arg RCC_MSIRange_128KHz: MSI clock is around 128 KHz\r
271   *     @arg RCC_MSIRange_256KHz: MSI clock is around 256 KHz\r
272   *     @arg RCC_MSIRange_512KHz: MSI clock is around 512 KHz\r
273   *     @arg RCC_MSIRange_1MHz:   MSI clock is around 1 MHz\r
274   *     @arg RCC_MSIRange_2MHz:   MSI clock is around 2 MHz\r
275   *     @arg RCC_MSIRange_4MHz:   MSI clock is around 4 MHz             \r
276   * @retval None\r
277   */\r
278 void RCC_MSIRangeConfig(uint32_t RCC_MSIRange)\r
279 {\r
280   uint32_t tmpreg = 0;\r
281   \r
282   /* Check the parameters */\r
283   assert_param(IS_RCC_MSI_CLOCK_RANGE(RCC_MSIRange));\r
284   \r
285   tmpreg = RCC->ICSCR;\r
286   \r
287   /* Clear MSIRANGE[2:0] bits */\r
288   tmpreg &= ~RCC_ICSCR_MSIRANGE;\r
289   \r
290   /* Set the MSIRANGE[2:0] bits according to RCC_MSIRange value */\r
291   tmpreg |= (uint32_t)RCC_MSIRange;\r
292 \r
293   /* Store the new value */\r
294   RCC->ICSCR = tmpreg;\r
295 }\r
296 \r
297 /**\r
298   * @brief  Enables or disables the Internal Multi Speed oscillator (MSI).\r
299   * @note   MSI can not be stopped if it is used directly as system clock.\r
300   * @param  NewState: new state of the MSI.\r
301   *   This parameter can be: ENABLE or DISABLE.\r
302   * @retval None\r
303   */\r
304 void RCC_MSICmd(FunctionalState NewState)\r
305 {\r
306   /* Check the parameters */\r
307   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
308   \r
309   *(__IO uint32_t *) CR_MSION_BB = (uint32_t)NewState;\r
310 }\r
311 \r
312 /**\r
313   * @brief  Enables or disables the Internal High Speed oscillator (HSI).\r
314   * @note   HSI can not be stopped if it is used directly or through the PLL as system clock.\r
315   * @param  NewState: new state of the HSI.\r
316   *   This parameter can be: ENABLE or DISABLE.\r
317   * @retval None\r
318   */\r
319 void RCC_HSICmd(FunctionalState NewState)\r
320 {\r
321   /* Check the parameters */\r
322   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
323   \r
324   *(__IO uint32_t *) CR_HSION_BB = (uint32_t)NewState;\r
325 }\r
326 \r
327 /**\r
328   * @brief  Configures the PLL clock source and multiplication factor.\r
329   * @note   This function must be used only when the PLL is disabled.\r
330   * @param  RCC_PLLSource: specifies the PLL entry clock source.\r
331   *   This parameter can be one of the following values:\r
332   *     @arg RCC_PLLSource_HSI: HSI oscillator clock selected as PLL clock entry\r
333   *     @arg RCC_PLLSource_HSE: HSE oscillator clock selected as PLL clock entry\r
334   * @param  RCC_PLLMul: specifies the PLL multiplication factor.\r
335   *   This parameter can be:\r
336   *     @arg RCC_PLLMul_3: PLL Clock entry multiplied by 3\r
337   *     @arg RCC_PLLMul_4: PLL Clock entry multiplied by 4\r
338   *     @arg RCC_PLLMul_6: PLL Clock entry multiplied by 6\r
339   *     @arg RCC_PLLMul_8: PLL Clock entry multiplied by 8\r
340   *     @arg RCC_PLLMul_12: PLL Clock entry multiplied by 12\r
341   *     @arg RCC_PLLMul_16: PLL Clock entry multiplied by 16  \r
342   *     @arg RCC_PLLMul_24: PLL Clock entry multiplied by 24\r
343   *     @arg RCC_PLLMul_32: PLL Clock entry multiplied by 32\r
344   *     @arg RCC_PLLMul_48: PLL Clock entry multiplied by 48             \r
345   * @param  RCC_PLLDiv: specifies the PLL division factor.\r
346   *   This parameter can be:\r
347   *     @arg RCC_PLLDiv_2: PLL Clock output divided by 2  \r
348   *     @arg RCC_PLLDiv_3: PLL Clock output divided by 3         \r
349   *     @arg RCC_PLLDiv_4: PLL Clock output divided by 4   \r
350   * @retval None\r
351   */\r
352 void RCC_PLLConfig(uint8_t RCC_PLLSource, uint8_t RCC_PLLMul, uint8_t RCC_PLLDiv)\r
353 {\r
354   /* Check the parameters */\r
355   assert_param(IS_RCC_PLL_SOURCE(RCC_PLLSource));\r
356   assert_param(IS_RCC_PLL_MUL(RCC_PLLMul));\r
357   assert_param(IS_RCC_PLL_DIV(RCC_PLLDiv));\r
358   \r
359   *(__IO uint8_t *) CFGR_BYTE3_ADDRESS = (uint8_t)(RCC_PLLSource | ((uint8_t)(RCC_PLLMul | (uint8_t)(RCC_PLLDiv))));\r
360 }\r
361 \r
362 /**\r
363   * @brief  Enables or disables the PLL.\r
364   * @note   The PLL can not be disabled if it is used as system clock.\r
365   * @param  NewState: new state of the PLL.\r
366   *   This parameter can be: ENABLE or DISABLE.\r
367   * @retval None\r
368   */\r
369 void RCC_PLLCmd(FunctionalState NewState)\r
370 {\r
371   /* Check the parameters */\r
372   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
373   \r
374   *(__IO uint32_t *) CR_PLLON_BB = (uint32_t)NewState;\r
375 }\r
376 \r
377 /**\r
378   * @brief  Configures the system clock (SYSCLK).\r
379   * @param  RCC_SYSCLKSource: specifies the clock source used as system clock. \r
380   *   This parameter can be one of the following values:\r
381   *     @arg RCC_SYSCLKSource_MSI:    MSI selected as system clock\r
382   *     @arg RCC_SYSCLKSource_HSI:    HSI selected as system clock\r
383   *     @arg RCC_SYSCLKSource_HSE:    HSE selected as system clock\r
384   *     @arg RCC_SYSCLKSource_PLLCLK: PLL selected as system clock\r
385   * @retval None\r
386   */\r
387 void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource)\r
388 {\r
389   uint32_t tmpreg = 0;\r
390   \r
391   /* Check the parameters */\r
392   assert_param(IS_RCC_SYSCLK_SOURCE(RCC_SYSCLKSource));\r
393   \r
394   tmpreg = RCC->CFGR;\r
395   \r
396   /* Clear SW[1:0] bits */\r
397   tmpreg &= ~RCC_CFGR_SW;\r
398   \r
399   /* Set SW[1:0] bits according to RCC_SYSCLKSource value */\r
400   tmpreg |= RCC_SYSCLKSource;\r
401   \r
402   /* Store the new value */\r
403   RCC->CFGR = tmpreg;\r
404 }\r
405 \r
406 /**\r
407   * @brief  Returns the clock source used as system clock.\r
408   * @param  None\r
409   * @retval The clock source used as system clock. The returned value can be one \r
410   *         of the following values:\r
411   *              - 0x00: MSI used as system clock\r
412   *              - 0x04: HSI used as system clock  \r
413   *              - 0x08: HSE used as system clock\r
414   *              - 0x0C: PLL used as system clock\r
415   */\r
416 uint8_t RCC_GetSYSCLKSource(void)\r
417 {\r
418   return ((uint8_t)(RCC->CFGR & RCC_CFGR_SWS));\r
419 }\r
420 \r
421 /**\r
422   * @brief  Configures the AHB clock (HCLK).\r
423   * @param  RCC_SYSCLK: defines the AHB clock divider. This clock is derived from \r
424   *                     the system clock (SYSCLK).\r
425   *   This parameter can be one of the following values:\r
426   *     @arg RCC_SYSCLK_Div1:   AHB clock = SYSCLK\r
427   *     @arg RCC_SYSCLK_Div2:   AHB clock = SYSCLK/2\r
428   *     @arg RCC_SYSCLK_Div4:   AHB clock = SYSCLK/4\r
429   *     @arg RCC_SYSCLK_Div8:   AHB clock = SYSCLK/8\r
430   *     @arg RCC_SYSCLK_Div16:  AHB clock = SYSCLK/16\r
431   *     @arg RCC_SYSCLK_Div64:  AHB clock = SYSCLK/64\r
432   *     @arg RCC_SYSCLK_Div128: AHB clock = SYSCLK/128\r
433   *     @arg RCC_SYSCLK_Div256: AHB clock = SYSCLK/256\r
434   *     @arg RCC_SYSCLK_Div512: AHB clock = SYSCLK/512\r
435   * @retval None\r
436   */\r
437 void RCC_HCLKConfig(uint32_t RCC_SYSCLK)\r
438 {\r
439   uint32_t tmpreg = 0;\r
440   \r
441   /* Check the parameters */\r
442   assert_param(IS_RCC_HCLK(RCC_SYSCLK));\r
443   \r
444   tmpreg = RCC->CFGR;\r
445   \r
446   /* Clear HPRE[3:0] bits */\r
447   tmpreg &= ~RCC_CFGR_HPRE;\r
448   \r
449   /* Set HPRE[3:0] bits according to RCC_SYSCLK value */\r
450   tmpreg |= RCC_SYSCLK;\r
451   \r
452   /* Store the new value */\r
453   RCC->CFGR = tmpreg;\r
454 }\r
455 \r
456 /**\r
457   * @brief  Configures the Low Speed APB clock (PCLK1).\r
458   * @param  RCC_HCLK: defines the APB1 clock divider. This clock is derived from \r
459   *                   the AHB clock (HCLK).\r
460   *   This parameter can be one of the following values:\r
461   *     @arg RCC_HCLK_Div1:  APB1 clock = HCLK\r
462   *     @arg RCC_HCLK_Div2:  APB1 clock = HCLK/2\r
463   *     @arg RCC_HCLK_Div4:  APB1 clock = HCLK/4\r
464   *     @arg RCC_HCLK_Div8:  APB1 clock = HCLK/8\r
465   *     @arg RCC_HCLK_Div16: APB1 clock = HCLK/16\r
466   * @retval None\r
467   */\r
468 void RCC_PCLK1Config(uint32_t RCC_HCLK)\r
469 {\r
470   uint32_t tmpreg = 0;\r
471   \r
472   /* Check the parameters */\r
473   assert_param(IS_RCC_PCLK(RCC_HCLK));\r
474   \r
475   tmpreg = RCC->CFGR;\r
476   \r
477   /* Clear PPRE1[2:0] bits */\r
478   tmpreg &= ~RCC_CFGR_PPRE1;\r
479   \r
480   /* Set PPRE1[2:0] bits according to RCC_HCLK value */\r
481   tmpreg |= RCC_HCLK;\r
482   \r
483   /* Store the new value */\r
484   RCC->CFGR = tmpreg;\r
485 }\r
486 \r
487 /**\r
488   * @brief  Configures the High Speed APB clock (PCLK2).\r
489   * @param  RCC_HCLK: defines the APB2 clock divider. This clock is derived from \r
490   *                   the AHB clock (HCLK).\r
491   *   This parameter can be one of the following values:\r
492   *     @arg RCC_HCLK_Div1:  APB2 clock = HCLK\r
493   *     @arg RCC_HCLK_Div2:  APB2 clock = HCLK/2\r
494   *     @arg RCC_HCLK_Div4:  APB2 clock = HCLK/4\r
495   *     @arg RCC_HCLK_Div8:  APB2 clock = HCLK/8\r
496   *     @arg RCC_HCLK_Div16: APB2 clock = HCLK/16\r
497   * @retval None\r
498   */\r
499 void RCC_PCLK2Config(uint32_t RCC_HCLK)\r
500 {\r
501   uint32_t tmpreg = 0;\r
502   \r
503   /* Check the parameters */\r
504   assert_param(IS_RCC_PCLK(RCC_HCLK));\r
505   \r
506   tmpreg = RCC->CFGR;\r
507   \r
508   /* Clear PPRE2[2:0] bits */\r
509   tmpreg &= ~RCC_CFGR_PPRE2;\r
510   \r
511   /* Set PPRE2[2:0] bits according to RCC_HCLK value */\r
512   tmpreg |= RCC_HCLK << 3;\r
513   \r
514   /* Store the new value */\r
515   RCC->CFGR = tmpreg;\r
516 }\r
517 \r
518 /**\r
519   * @brief  Enables or disables the specified RCC interrupts.\r
520   * @param  RCC_IT: specifies the RCC interrupt sources to be enabled or disabled.\r
521   *   This parameter can be any combination of the following values:\r
522   *     @arg RCC_IT_LSIRDY: LSI ready interrupt\r
523   *     @arg RCC_IT_LSERDY: LSE ready interrupt\r
524   *     @arg RCC_IT_HSIRDY: HSI ready interrupt\r
525   *     @arg RCC_IT_HSERDY: HSE ready interrupt\r
526   *     @arg RCC_IT_PLLRDY: PLL ready interrupt\r
527   *     @arg RCC_IT_MSIRDY: MSI ready interrupt\r
528   * @param  NewState: new state of the specified RCC interrupts.\r
529   *   This parameter can be: ENABLE or DISABLE.\r
530   * @retval None\r
531   */\r
532 void RCC_ITConfig(uint8_t RCC_IT, FunctionalState NewState)\r
533 {\r
534   /* Check the parameters */\r
535   assert_param(IS_RCC_IT(RCC_IT));\r
536   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
537   \r
538   if (NewState != DISABLE)\r
539   {\r
540     /* Perform Byte access to RCC_CIR[12:8] bits to enable the selected interrupts */\r
541     *(__IO uint8_t *) CIR_BYTE2_ADDRESS |= RCC_IT;\r
542   }\r
543   else\r
544   {\r
545     /* Perform Byte access to RCC_CIR[12:8] bits to disable the selected interrupts */\r
546     *(__IO uint8_t *) CIR_BYTE2_ADDRESS &= (uint8_t)~RCC_IT;\r
547   }\r
548 }\r
549 \r
550 /**\r
551   * @brief  Configures the External Low Speed oscillator (LSE).\r
552   * @param  RCC_LSE: specifies the new state of the LSE.\r
553   *   This parameter can be one of the following values:\r
554   *     @arg RCC_LSE_OFF: LSE oscillator OFF\r
555   *     @arg RCC_LSE_ON: LSE oscillator ON\r
556   *     @arg RCC_LSE_Bypass: LSE oscillator bypassed with external clock\r
557   * @retval None\r
558   */\r
559 void RCC_LSEConfig(uint8_t RCC_LSE)\r
560 {\r
561   /* Check the parameters */\r
562   assert_param(IS_RCC_LSE(RCC_LSE));\r
563   \r
564   /* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/\r
565   *(__IO uint8_t *) CSR_BYTE2_ADDRESS = RCC_LSE_OFF;\r
566 \r
567   /* Set the new LSE configuration -------------------------------------------*/\r
568   *(__IO uint8_t *) CSR_BYTE2_ADDRESS = RCC_LSE;  \r
569 }\r
570 \r
571 /**\r
572   * @brief  Enables or disables the Internal Low Speed oscillator (LSI).\r
573   * @note   LSI can not be disabled if the IWDG is running.\r
574   * @param  NewState: new state of the LSI.\r
575   *   This parameter can be: ENABLE or DISABLE.\r
576   * @retval None\r
577   */\r
578 void RCC_LSICmd(FunctionalState NewState)\r
579 {\r
580   /* Check the parameters */\r
581   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
582   \r
583   *(__IO uint32_t *) CSR_LSION_BB = (uint32_t)NewState;\r
584 }\r
585 \r
586 /**\r
587   * @brief  Configures the RTC and LCD clock (RTCCLK / LCDCLK).\r
588   * @note   \r
589   *   - Once the RTC clock is selected it can't be changed unless the RTC is\r
590   *     reset using RCC_RTCResetCmd function.\r
591   *   - This RTC clock (RTCCLK) is used to clock the LCD (LCDCLK).  \r
592   * @param  RCC_RTCCLKSource: specifies the RTC clock source.\r
593   *   This parameter can be one of the following values:\r
594   *     @arg RCC_RTCCLKSource_LSE: LSE selected as RTC clock\r
595   *     @arg RCC_RTCCLKSource_LSI: LSI selected as RTC clock\r
596   *     @arg RCC_RTCCLKSource_HSE_Div2: HSE divided by 2 selected as RTC clock\r
597   *     @arg RCC_RTCCLKSource_HSE_Div4: HSE divided by 4 selected as RTC clock\r
598   *     @arg RCC_RTCCLKSource_HSE_Div8: HSE divided by 8 selected as RTC clock\r
599   *     @arg RCC_RTCCLKSource_HSE_Div16: HSE divided by 16 selected as RTC clock      \r
600   * @retval None\r
601   */\r
602 void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource)\r
603 {\r
604   uint32_t      tmpreg = 0;\r
605 \r
606   /* Check the parameters */\r
607   assert_param(IS_RCC_RTCCLK_SOURCE(RCC_RTCCLKSource));\r
608   \r
609   if ((RCC_RTCCLKSource & RCC_CSR_RTCSEL_HSE) == RCC_CSR_RTCSEL_HSE)\r
610   { \r
611     /* If HSE is selected as RTC clock source, configure HSE division factor for RTC clock */\r
612     tmpreg = RCC->CR;\r
613 \r
614     /* Clear RTCPRE[1:0] bits */\r
615     tmpreg &= ~RCC_CR_RTCPRE;\r
616 \r
617     /* Configure HSE division factor for RTC clock */\r
618     tmpreg |= (RCC_RTCCLKSource & RCC_CR_RTCPRE);\r
619 \r
620     /* Store the new value */\r
621     RCC->CR = tmpreg;\r
622   }\r
623          \r
624   RCC->CSR &= ~RCC_CSR_RTCSEL;\r
625   \r
626   /* Select the RTC clock source */\r
627   RCC->CSR |= (RCC_RTCCLKSource & RCC_CSR_RTCSEL);\r
628 }\r
629 \r
630 /**\r
631   * @brief  Enables or disables the RTC clock.\r
632   * @note   This function must be used only after the RTC clock was selected using the \r
633   *   RCC_RTCCLKConfig function.\r
634   * @param  NewState: new state of the RTC clock.\r
635   *   This parameter can be: ENABLE or DISABLE.\r
636   * @retval None\r
637   */\r
638 void RCC_RTCCLKCmd(FunctionalState NewState)\r
639 {\r
640   /* Check the parameters */\r
641   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
642   \r
643   *(__IO uint32_t *) CSR_RTCEN_BB = (uint32_t)NewState;\r
644 }\r
645 \r
646 /**\r
647   * @brief  Forces or releases the RTC peripheral reset.\r
648   * @param  NewState: new state of the RTC reset.\r
649   *   This parameter can be: ENABLE or DISABLE.\r
650   * @retval None\r
651   */\r
652 void RCC_RTCResetCmd(FunctionalState NewState)\r
653 {\r
654   /* Check the parameters */\r
655   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
656   \r
657   *(__IO uint32_t *) CSR_RTCRST_BB = (uint32_t)NewState;\r
658 }\r
659 \r
660 /**\r
661   * @brief  Returns the frequencies of different on chip clocks.\r
662   * @param  RCC_Clocks: pointer to a RCC_ClocksTypeDef structure which will hold \r
663   *   the clocks frequencies.\r
664   * @retval None\r
665   */\r
666 void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks)\r
667 {\r
668   uint32_t tmp = 0, pllmul = 0, plldiv = 0, pllsource = 0, presc = 0, msirange = 0;\r
669 \r
670   /* Get SYSCLK source -------------------------------------------------------*/\r
671   tmp = RCC->CFGR & RCC_CFGR_SWS;\r
672   \r
673   switch (tmp)\r
674   {\r
675     case 0x00:  /* MSI used as system clock */\r
676       msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE ) >> 13;\r
677       RCC_Clocks->SYSCLK_Frequency = (((1 << msirange) * 64000) - (MSITable[msirange] * 24000));\r
678       break;\r
679     case 0x04:  /* HSI used as system clock */\r
680       RCC_Clocks->SYSCLK_Frequency = HSI_VALUE;\r
681       break;\r
682     case 0x08:  /* HSE used as system clock */\r
683       RCC_Clocks->SYSCLK_Frequency = HSE_VALUE;\r
684       break;\r
685     case 0x0C:  /* PLL used as system clock */\r
686       /* Get PLL clock source and multiplication factor ----------------------*/\r
687       pllmul = RCC->CFGR & RCC_CFGR_PLLMUL;\r
688       plldiv = RCC->CFGR & RCC_CFGR_PLLDIV;\r
689       pllmul = PLLMulTable[(pllmul >> 18)];\r
690       plldiv = (plldiv >> 22) + 1;\r
691       \r
692       pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;\r
693 \r
694       if (pllsource == 0x00)\r
695       {\r
696         /* HSI oscillator clock selected as PLL clock entry */\r
697         RCC_Clocks->SYSCLK_Frequency = (((HSI_VALUE) * pllmul) / plldiv);\r
698       }\r
699       else\r
700       {\r
701         /* HSE selected as PLL clock entry */\r
702         RCC_Clocks->SYSCLK_Frequency = (((HSE_VALUE) * pllmul) / plldiv);\r
703       }\r
704       break;\r
705     default:\r
706       RCC_Clocks->SYSCLK_Frequency = HSI_VALUE;\r
707       break;\r
708   }\r
709   /* Compute HCLK, PCLK1, PCLK2 and ADCCLK clocks frequencies ----------------*/\r
710   /* Get HCLK prescaler */\r
711   tmp = RCC->CFGR & RCC_CFGR_HPRE;\r
712   tmp = tmp >> 4;\r
713   presc = APBAHBPrescTable[tmp]; \r
714   /* HCLK clock frequency */\r
715   RCC_Clocks->HCLK_Frequency = RCC_Clocks->SYSCLK_Frequency >> presc;\r
716 \r
717   /* Get PCLK1 prescaler */\r
718   tmp = RCC->CFGR & RCC_CFGR_PPRE1;\r
719   tmp = tmp >> 8;\r
720   presc = APBAHBPrescTable[tmp];\r
721   /* PCLK1 clock frequency */\r
722   RCC_Clocks->PCLK1_Frequency = RCC_Clocks->HCLK_Frequency >> presc;\r
723 \r
724   /* Get PCLK2 prescaler */\r
725   tmp = RCC->CFGR & RCC_CFGR_PPRE2;\r
726   tmp = tmp >> 11;\r
727   presc = APBAHBPrescTable[tmp];\r
728   /* PCLK2 clock frequency */\r
729   RCC_Clocks->PCLK2_Frequency = RCC_Clocks->HCLK_Frequency >> presc;\r
730 }\r
731 \r
732 /**\r
733   * @brief  Enables or disables the AHB peripheral clock.\r
734   * @param  RCC_AHBPeriph: specifies the AHB peripheral to gates its clock.\r
735   *   This parameter can be any combination of the following values:\r
736   *     @arg RCC_AHBPeriph_GPIOA\r
737   *     @arg RCC_AHBPeriph_GPIOB\r
738   *     @arg RCC_AHBPeriph_GPIOC  \r
739   *     @arg RCC_AHBPeriph_GPIOD\r
740   *     @arg RCC_AHBPeriph_GPIOE\r
741   *     @arg RCC_AHBPeriph_GPIOH\r
742   *     @arg RCC_AHBPeriph_CRC\r
743   *     @arg RCC_AHBPeriph_FLITF (has effect only when the Flash memory is in power down mode)  \r
744   *     @arg RCC_AHBPeriph_DMA1\r
745   * @param  NewState: new state of the specified peripheral clock.\r
746   *   This parameter can be: ENABLE or DISABLE.\r
747   * @retval None\r
748   */\r
749 void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)\r
750 {\r
751   /* Check the parameters */\r
752   assert_param(IS_RCC_AHB_PERIPH(RCC_AHBPeriph));\r
753   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
754   \r
755   if (NewState != DISABLE)\r
756   {\r
757     RCC->AHBENR |= RCC_AHBPeriph;\r
758   }\r
759   else\r
760   {\r
761     RCC->AHBENR &= ~RCC_AHBPeriph;\r
762   }\r
763 }\r
764 \r
765 /**\r
766   * @brief  Enables or disables the High Speed APB (APB2) peripheral clock.\r
767   * @param  RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.\r
768   *   This parameter can be any combination of the following values:\r
769   *     @arg RCC_APB2Periph_SYSCFG\r
770   *     @arg RCC_APB2Periph_TIM9\r
771   *     @arg RCC_APB2Periph_TIM10\r
772   *     @arg RCC_APB2Periph_TIM11\r
773   *     @arg RCC_APB2Periph_ADC1\r
774   *     @arg RCC_APB2Periph_SPI1\r
775   *     @arg RCC_APB2Periph_USART1            \r
776   * @param  NewState: new state of the specified peripheral clock.\r
777   *   This parameter can be: ENABLE or DISABLE.\r
778   * @retval None\r
779   */\r
780 void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)\r
781 {\r
782   /* Check the parameters */\r
783   assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));\r
784   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
785 \r
786   if (NewState != DISABLE)\r
787   {\r
788     RCC->APB2ENR |= RCC_APB2Periph;\r
789   }\r
790   else\r
791   {\r
792     RCC->APB2ENR &= ~RCC_APB2Periph;\r
793   }\r
794 }\r
795 \r
796 /**\r
797   * @brief  Enables or disables the Low Speed APB (APB1) peripheral clock.\r
798   * @param  RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.\r
799   *   This parameter can be any combination of the following values:\r
800   *     @arg RCC_APB1Periph_TIM2\r
801   *     @arg RCC_APB1Periph_TIM3\r
802   *     @arg RCC_APB1Periph_TIM4\r
803   *     @arg RCC_APB1Periph_TIM6\r
804   *     @arg RCC_APB1Periph_TIM7\r
805   *     @arg RCC_APB1Periph_LCD\r
806   *     @arg RCC_APB1Periph_WWDG\r
807   *     @arg RCC_APB1Periph_SPI2\r
808   *     @arg RCC_APB1Periph_USART2\r
809   *     @arg RCC_APB1Periph_USART3\r
810   *     @arg RCC_APB1Periph_I2C1\r
811   *     @arg RCC_APB1Periph_I2C2\r
812   *     @arg RCC_APB1Periph_USB\r
813   *     @arg RCC_APB1Periph_PWR\r
814   *     @arg RCC_APB1Periph_DAC\r
815   *     @arg RCC_APB1Periph_COMP                                \r
816   * @param  NewState: new state of the specified peripheral clock.\r
817   *   This parameter can be: ENABLE or DISABLE.\r
818   * @retval None\r
819   */\r
820 void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)\r
821 {\r
822   /* Check the parameters */\r
823   assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));\r
824   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
825 \r
826   if (NewState != DISABLE)\r
827   {\r
828     RCC->APB1ENR |= RCC_APB1Periph;\r
829   }\r
830   else\r
831   {\r
832     RCC->APB1ENR &= ~RCC_APB1Periph;\r
833   }\r
834 }\r
835 \r
836 /**\r
837   * @brief  Forces or releases AHB peripheral reset.\r
838   * @param  RCC_AHBPeriph: specifies the AHB peripheral to reset.\r
839   *   This parameter can be any combination of the following values:\r
840   *     @arg RCC_AHBPeriph_GPIOA\r
841   *     @arg RCC_AHBPeriph_GPIOB\r
842   *     @arg RCC_AHBPeriph_GPIOC  \r
843   *     @arg RCC_AHBPeriph_GPIOD\r
844   *     @arg RCC_AHBPeriph_GPIOE\r
845   *     @arg RCC_AHBPeriph_GPIOH\r
846   *     @arg RCC_AHBPeriph_CRC\r
847   *     @arg RCC_AHBPeriph_FLITF (has effect only when the Flash memory is in power down mode)  \r
848   *     @arg RCC_AHBPeriph_DMA1   \r
849   * @param  NewState: new state of the specified peripheral reset.\r
850   *   This parameter can be: ENABLE or DISABLE.\r
851   * @retval None\r
852   */\r
853 void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)\r
854 {\r
855   /* Check the parameters */\r
856   assert_param(IS_RCC_AHB_PERIPH(RCC_AHBPeriph));\r
857   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
858 \r
859   if (NewState != DISABLE)\r
860   {\r
861     RCC->AHBRSTR |= RCC_AHBPeriph;\r
862   }\r
863   else\r
864   {\r
865     RCC->AHBRSTR &= ~RCC_AHBPeriph;\r
866   }\r
867 }\r
868 \r
869 /**\r
870   * @brief  Forces or releases High Speed APB (APB2) peripheral reset.\r
871   * @param  RCC_APB2Periph: specifies the APB2 peripheral to reset.\r
872   *   This parameter can be any combination of the following values:\r
873   *     @arg RCC_APB2Periph_SYSCFG\r
874   *     @arg RCC_APB2Periph_TIM9\r
875   *     @arg RCC_APB2Periph_TIM10\r
876   *     @arg RCC_APB2Periph_TIM11\r
877   *     @arg RCC_APB2Periph_ADC1\r
878   *     @arg RCC_APB2Periph_SPI1\r
879   *     @arg RCC_APB2Periph_USART1  \r
880   * @param  NewState: new state of the specified peripheral reset.\r
881   *   This parameter can be: ENABLE or DISABLE.\r
882   * @retval None\r
883   */\r
884 void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)\r
885 {\r
886   /* Check the parameters */\r
887   assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));\r
888   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
889 \r
890   if (NewState != DISABLE)\r
891   {\r
892     RCC->APB2RSTR |= RCC_APB2Periph;\r
893   }\r
894   else\r
895   {\r
896     RCC->APB2RSTR &= ~RCC_APB2Periph;\r
897   }\r
898 }\r
899 \r
900 /**\r
901   * @brief  Forces or releases Low Speed APB (APB1) peripheral reset.\r
902   * @param  RCC_APB1Periph: specifies the APB1 peripheral to reset.\r
903   *   This parameter can be any combination of the following values:\r
904   *     @arg RCC_APB1Periph_TIM2\r
905   *     @arg RCC_APB1Periph_TIM3\r
906   *     @arg RCC_APB1Periph_TIM4\r
907   *     @arg RCC_APB1Periph_TIM6\r
908   *     @arg RCC_APB1Periph_TIM7\r
909   *     @arg RCC_APB1Periph_LCD\r
910   *     @arg RCC_APB1Periph_WWDG\r
911   *     @arg RCC_APB1Periph_SPI2\r
912   *     @arg RCC_APB1Periph_USART2\r
913   *     @arg RCC_APB1Periph_USART3\r
914   *     @arg RCC_APB1Periph_I2C1\r
915   *     @arg RCC_APB1Periph_I2C2\r
916   *     @arg RCC_APB1Periph_USB\r
917   *     @arg RCC_APB1Periph_PWR\r
918   *     @arg RCC_APB1Periph_DAC\r
919   *     @arg RCC_APB1Periph_COMP    \r
920   * @param  NewState: new state of the specified peripheral clock.\r
921   *   This parameter can be: ENABLE or DISABLE.\r
922   * @retval None\r
923   */\r
924 void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)\r
925 {\r
926   /* Check the parameters */\r
927   assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));\r
928   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
929 \r
930   if (NewState != DISABLE)\r
931   {\r
932     RCC->APB1RSTR |= RCC_APB1Periph;\r
933   }\r
934   else\r
935   {\r
936     RCC->APB1RSTR &= ~RCC_APB1Periph;\r
937   }\r
938 }\r
939 \r
940 /**\r
941   * @brief  Enables or disables the AHB peripheral clock during Low Power (SLEEP) mode.\r
942   * @param  RCC_AHBPeriph: specifies the AHB peripheral to gates its clock.\r
943   *   This parameter can be any combination of the following values:\r
944   *     @arg RCC_AHBPeriph_GPIOA\r
945   *     @arg RCC_AHBPeriph_GPIOB\r
946   *     @arg RCC_AHBPeriph_GPIOC  \r
947   *     @arg RCC_AHBPeriph_GPIOD\r
948   *     @arg RCC_AHBPeriph_GPIOE\r
949   *     @arg RCC_AHBPeriph_GPIOH\r
950   *     @arg RCC_AHBPeriph_CRC\r
951   *     @arg RCC_AHBPeriph_FLITF (has effect only when the Flash memory is in power down mode)  \r
952   *     @arg RCC_AHBPeriph_SRAM     \r
953   *     @arg RCC_AHBPeriph_DMA1\r
954   * @param  NewState: new state of the specified peripheral clock.\r
955   *   This parameter can be: ENABLE or DISABLE.\r
956   * @retval None\r
957   */\r
958 void RCC_AHBPeriphClockLPModeCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)\r
959 {\r
960   /* Check the parameters */\r
961   assert_param(IS_RCC_AHB_LPMODE_PERIPH(RCC_AHBPeriph));\r
962   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
963   \r
964   if (NewState != DISABLE)\r
965   {\r
966     RCC->AHBLPENR |= RCC_AHBPeriph;\r
967   }\r
968   else\r
969   {\r
970     RCC->AHBLPENR &= ~RCC_AHBPeriph;\r
971   }\r
972 }\r
973 \r
974 /**\r
975   * @brief  Enables or disables the APB2 peripheral clock during Low Power (SLEEP) mode.\r
976   * @param  RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.\r
977   *   This parameter can be any combination of the following values:\r
978   *     @arg RCC_APB2Periph_SYSCFG\r
979   *     @arg RCC_APB2Periph_TIM9\r
980   *     @arg RCC_APB2Periph_TIM10\r
981   *     @arg RCC_APB2Periph_TIM11\r
982   *     @arg RCC_APB2Periph_ADC1\r
983   *     @arg RCC_APB2Periph_SPI1\r
984   *     @arg RCC_APB2Periph_USART1            \r
985   * @param  NewState: new state of the specified peripheral clock.\r
986   *   This parameter can be: ENABLE or DISABLE.\r
987   * @retval None\r
988   */\r
989 void RCC_APB2PeriphClockLPModeCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)\r
990 {\r
991   /* Check the parameters */\r
992   assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));\r
993   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
994   \r
995   if (NewState != DISABLE)\r
996   {\r
997     RCC->APB2LPENR |= RCC_APB2Periph;\r
998   }\r
999   else\r
1000   {\r
1001     RCC->APB2LPENR &= ~RCC_APB2Periph;\r
1002   }\r
1003 }\r
1004 \r
1005 /**\r
1006   * @brief  Enables or disables the APB1 peripheral clock during Low Power (SLEEP) mode.\r
1007   * @param  RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.\r
1008   *   This parameter can be any combination of the following values:\r
1009   *     @arg RCC_APB1Periph_TIM2\r
1010   *     @arg RCC_APB1Periph_TIM3\r
1011   *     @arg RCC_APB1Periph_TIM4\r
1012   *     @arg RCC_APB1Periph_TIM6\r
1013   *     @arg RCC_APB1Periph_TIM7\r
1014   *     @arg RCC_APB1Periph_LCD\r
1015   *     @arg RCC_APB1Periph_WWDG\r
1016   *     @arg RCC_APB1Periph_SPI2\r
1017   *     @arg RCC_APB1Periph_USART2\r
1018   *     @arg RCC_APB1Periph_USART3\r
1019   *     @arg RCC_APB1Periph_I2C1\r
1020   *     @arg RCC_APB1Periph_I2C2\r
1021   *     @arg RCC_APB1Periph_USB\r
1022   *     @arg RCC_APB1Periph_PWR\r
1023   *     @arg RCC_APB1Periph_DAC\r
1024   *     @arg RCC_APB1Periph_COMP                                \r
1025   * @param  NewState: new state of the specified peripheral clock.\r
1026   *   This parameter can be: ENABLE or DISABLE.\r
1027   * @retval None\r
1028   */\r
1029 void RCC_APB1PeriphClockLPModeCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)\r
1030 {\r
1031   /* Check the parameters */\r
1032   assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));\r
1033   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1034   \r
1035   if (NewState != DISABLE)\r
1036   {\r
1037     RCC->APB1LPENR |= RCC_APB1Periph;\r
1038   }\r
1039   else\r
1040   {\r
1041     RCC->APB1LPENR &= ~RCC_APB1Periph;\r
1042   }\r
1043 }\r
1044 \r
1045 /**\r
1046   * @brief  Enables or disables the Clock Security System.\r
1047   * @param  NewState: new state of the Clock Security System..\r
1048   *   This parameter can be: ENABLE or DISABLE.\r
1049   * @retval None\r
1050   */\r
1051 void RCC_ClockSecuritySystemCmd(FunctionalState NewState)\r
1052 {\r
1053   /* Check the parameters */\r
1054   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1055   \r
1056   *(__IO uint32_t *) CR_CSSON_BB = (uint32_t)NewState;\r
1057 }\r
1058 \r
1059 /**\r
1060   * @brief  Selects the clock source to output on MCO pin.\r
1061   * @param  RCC_MCOSource: specifies the clock source to output.\r
1062   *   This parameter can be one of the following values:\r
1063   *     @arg RCC_MCOSource_NoClock: No clock selected\r
1064   *     @arg RCC_MCOSource_SYSCLK: System clock selected\r
1065   *     @arg RCC_MCOSource_HSI: HSI oscillator clock selected\r
1066   *     @arg RCC_MCOSource_MSI: MSI oscillator clock selected  \r
1067   *     @arg RCC_MCOSource_HSE: HSE oscillator clock selected\r
1068   *     @arg RCC_MCOSource_PLLCLK: PLL clock selected\r
1069   *     @arg RCC_MCOSource_LSI: LSI clock selected\r
1070   *     @arg RCC_MCOSource_LSE: LSE clock selected    \r
1071   * @param  RCC_MCODiv: specifies the MCO prescaler.\r
1072   *   This parameter can be one of the following values: \r
1073   *     @arg RCC_MCODiv_1: no division applied to MCO clock \r
1074   *     @arg RCC_MCODiv_2: division by 2 applied to MCO clock\r
1075   *     @arg RCC_MCODiv_4: division by 4 applied to MCO clock\r
1076   *     @arg RCC_MCODiv_8: division by 8 applied to MCO clock\r
1077   *     @arg RCC_MCODiv_16: division by 16 applied to MCO clock             \r
1078   * @retval None\r
1079   */\r
1080 void RCC_MCOConfig(uint8_t RCC_MCOSource, uint8_t RCC_MCODiv)\r
1081 {\r
1082   /* Check the parameters */\r
1083   assert_param(IS_RCC_MCO_SOURCE(RCC_MCOSource));\r
1084   assert_param(IS_RCC_MCO_DIV(RCC_MCODiv));\r
1085     \r
1086   /* Select MCO clock source and prescaler */\r
1087   *(__IO uint8_t *) CFGR_BYTE4_ADDRESS =  RCC_MCOSource | RCC_MCODiv; \r
1088 }\r
1089 \r
1090 /**\r
1091   * @brief  Checks whether the specified RCC flag is set or not.\r
1092   * @param  RCC_FLAG: specifies the flag to check.\r
1093   *   This parameter can be one of the following values:\r
1094   *     @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready\r
1095   *     @arg RCC_FLAG_MSIRDY: MSI oscillator clock ready  \r
1096   *     @arg RCC_FLAG_HSERDY: HSE oscillator clock ready\r
1097   *     @arg RCC_FLAG_PLLRDY: PLL clock ready\r
1098   *     @arg RCC_FLAG_LSERDY: LSE oscillator clock ready\r
1099   *     @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready\r
1100   *     @arg RCC_FLAG_OBLRST: Option Byte Loader (OBL) reset \r
1101   *     @arg RCC_FLAG_PINRST: Pin reset\r
1102   *     @arg RCC_FLAG_PORRST: POR/PDR reset\r
1103   *     @arg RCC_FLAG_SFTRST: Software reset\r
1104   *     @arg RCC_FLAG_IWDGRST: Independent Watchdog reset\r
1105   *     @arg RCC_FLAG_WWDGRST: Window Watchdog reset\r
1106   *     @arg RCC_FLAG_LPWRRST: Low Power reset\r
1107   * @retval The new state of RCC_FLAG (SET or RESET).\r
1108   */\r
1109 FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG)\r
1110 {\r
1111   uint32_t tmp = 0;\r
1112   uint32_t statusreg = 0;\r
1113   FlagStatus bitstatus = RESET;\r
1114 \r
1115   /* Check the parameters */\r
1116   assert_param(IS_RCC_FLAG(RCC_FLAG));\r
1117 \r
1118   /* Get the RCC register index */\r
1119   tmp = RCC_FLAG >> 5;\r
1120 \r
1121   if (tmp == 1)               /* The flag to check is in CR register */\r
1122   {\r
1123     statusreg = RCC->CR;\r
1124   }\r
1125   else          /* The flag to check is in CSR register (tmp == 2) */\r
1126   {\r
1127     statusreg = RCC->CSR;\r
1128   }\r
1129 \r
1130   /* Get the flag position */\r
1131   tmp = RCC_FLAG & FLAG_MASK;\r
1132 \r
1133   if ((statusreg & ((uint32_t)1 << tmp)) != (uint32_t)RESET)\r
1134   {\r
1135     bitstatus = SET;\r
1136   }\r
1137   else\r
1138   {\r
1139     bitstatus = RESET;\r
1140   }\r
1141   /* Return the flag status */\r
1142   return bitstatus;\r
1143 }\r
1144 \r
1145 /**\r
1146   * @brief  Clears the RCC reset flags.\r
1147   *   The reset flags are: RCC_FLAG_OBLRST, RCC_FLAG_PINRST, RCC_FLAG_PORRST, \r
1148   *   RCC_FLAG_SFTRST, RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST.\r
1149   * @param  None\r
1150   * @retval None\r
1151   */\r
1152 void RCC_ClearFlag(void)\r
1153 {\r
1154   /* Set RMVF bit to clear the reset flags */\r
1155   RCC->CSR |= RCC_CSR_RMVF;\r
1156 }\r
1157 \r
1158 /**\r
1159   * @brief  Checks whether the specified RCC interrupt has occurred or not.\r
1160   * @param  RCC_IT: specifies the RCC interrupt source to check.\r
1161   *   This parameter can be one of the following values:\r
1162   *     @arg RCC_IT_LSIRDY: LSI ready interrupt\r
1163   *     @arg RCC_IT_LSERDY: LSE ready interrupt\r
1164   *     @arg RCC_IT_HSIRDY: HSI ready interrupt\r
1165   *     @arg RCC_IT_HSERDY: HSE ready interrupt\r
1166   *     @arg RCC_IT_PLLRDY: PLL ready interrupt\r
1167   *     @arg RCC_IT_MSIRDY: MSI ready interrupt \r
1168   *     @arg RCC_IT_CSS: Clock Security System interrupt\r
1169   * @retval The new state of RCC_IT (SET or RESET).\r
1170   */\r
1171 ITStatus RCC_GetITStatus(uint8_t RCC_IT)\r
1172 {\r
1173   ITStatus bitstatus = RESET;\r
1174   /* Check the parameters */\r
1175   assert_param(IS_RCC_GET_IT(RCC_IT));\r
1176   \r
1177   /* Check the status of the specified RCC interrupt */\r
1178   if ((RCC->CIR & RCC_IT) != (uint32_t)RESET)\r
1179   {\r
1180     bitstatus = SET;\r
1181   }\r
1182   else\r
1183   {\r
1184     bitstatus = RESET;\r
1185   }\r
1186   /* Return the RCC_IT status */\r
1187   return  bitstatus;\r
1188 }\r
1189 \r
1190 /**\r
1191   * @brief  Clears the RCC's interrupt pending bits.\r
1192   * @param  RCC_IT: specifies the interrupt pending bit to clear.\r
1193   *   This parameter can be any combination of the following values:\r
1194   *     @arg RCC_IT_LSIRDY: LSI ready interrupt\r
1195   *     @arg RCC_IT_LSERDY: LSE ready interrupt\r
1196   *     @arg RCC_IT_HSIRDY: HSI ready interrupt\r
1197   *     @arg RCC_IT_HSERDY: HSE ready interrupt\r
1198   *     @arg RCC_IT_PLLRDY: PLL ready interrupt\r
1199   *     @arg RCC_IT_MSIRDY: MSI ready interrupt  \r
1200   *     @arg RCC_IT_CSS: Clock Security System interrupt\r
1201   * @retval None\r
1202   */\r
1203 void RCC_ClearITPendingBit(uint8_t RCC_IT)\r
1204 {\r
1205   /* Check the parameters */\r
1206   assert_param(IS_RCC_CLEAR_IT(RCC_IT));\r
1207   \r
1208   /* Perform Byte access to RCC_CIR[23:16] bits to clear the selected interrupt\r
1209      pending bits */\r
1210   *(__IO uint8_t *) CIR_BYTE3_ADDRESS = RCC_IT;\r
1211 }\r
1212 \r
1213 /**\r
1214   * @}\r
1215   */\r
1216 \r
1217 /**\r
1218   * @}\r
1219   */\r
1220 \r
1221 /**\r
1222   * @}\r
1223   */\r
1224 \r
1225 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r