Merge pull request #93 from zyp/master
[fw/stlink] / example / libs_stm / src / stm32l1xx / stm32l1xx_rcc.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32l1xx_rcc.c\r
4   * @author  MCD Application Team\r
5   * @version V1.0.0\r
6   * @date    31-December-2010\r
7   * @brief   This file provides firmware functions to manage the following \r
8   *          functionalities of the Reset and clock control (RCC) peripheral:           \r
9   *           - Internal/external clocks, PLL, CSS and MCO configuration\r
10   *           - System, AHB and APB busses clocks configuration\r
11   *           - Peripheral clocks configuration\r
12   *           - Interrupts and flags management\r
13   *\r
14   *  @verbatim\r
15   *               \r
16   *          ===================================================================\r
17   *                               RCC specific features\r
18   *          ===================================================================\r
19   *    \r
20   *          After reset the device is running from MSI (2 MHz) with Flash 0 WS, \r
21   *          all peripherals are off except internal SRAM, Flash and JTAG.\r
22   *           - There is no prescaler on High speed (AHB) and Low speed (APB) busses;\r
23   *             all peripherals mapped on these busses are running at MSI speed.\r
24   *               - The clock for all peripherals is switched off, except the SRAM and FLASH.\r
25   *           - All GPIOs are in input floating state, except the JTAG pins which\r
26   *             are assigned to be used for debug purpose.\r
27   *        \r
28   *          Once the device started from reset, the user application has to:        \r
29   *           - Configure the clock source to be used to drive the System clock\r
30   *             (if the application needs higher frequency/performance)\r
31   *           - Configure the System clock frequency and Flash settings  \r
32   *           - Configure the AHB and APB busses prescalers\r
33   *           - Enable the clock for the peripheral(s) to be used\r
34   *           - Configure the clock source(s) for peripherals whose clocks are not\r
35   *             derived from the System clock (ADC, RTC/LCD and IWDG)      \r
36   *                        \r
37   *  @endverbatim\r
38   *    \r
39   ******************************************************************************\r
40   * @attention\r
41   *\r
42   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
43   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
44   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
45   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
46   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
47   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
48   *\r
49   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>\r
50   ******************************************************************************  \r
51   */ \r
52 \r
53 /* Includes ------------------------------------------------------------------*/\r
54 #include "stm32l1xx_rcc.h"\r
55 \r
56 /** @addtogroup STM32L1xx_StdPeriph_Driver\r
57   * @{\r
58   */\r
59 \r
60 /** @defgroup RCC \r
61   * @brief RCC driver modules\r
62   * @{\r
63   */ \r
64 \r
65 /* Private typedef -----------------------------------------------------------*/\r
66 /* Private define ------------------------------------------------------------*/\r
67 \r
68 /* ------------ RCC registers bit address in the alias region ----------- */\r
69 #define RCC_OFFSET                (RCC_BASE - PERIPH_BASE)\r
70 \r
71 /* --- CR Register ---*/\r
72 \r
73 /* Alias word address of HSION bit */\r
74 #define CR_OFFSET                 (RCC_OFFSET + 0x00)\r
75 #define HSION_BitNumber           0x00\r
76 #define CR_HSION_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (HSION_BitNumber * 4))\r
77 \r
78 /* Alias word address of MSION bit */\r
79 #define MSION_BitNumber           0x08\r
80 #define CR_MSION_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (MSION_BitNumber * 4))\r
81 \r
82 /* Alias word address of PLLON bit */\r
83 #define PLLON_BitNumber           0x18\r
84 #define CR_PLLON_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (PLLON_BitNumber * 4))\r
85 \r
86 /* Alias word address of CSSON bit */\r
87 #define CSSON_BitNumber           0x1C\r
88 #define CR_CSSON_BB               (PERIPH_BB_BASE + (CR_OFFSET * 32) + (CSSON_BitNumber * 4))\r
89 \r
90 /* --- CSR Register ---*/\r
91 \r
92 /* Alias word address of LSION bit */\r
93 #define CSR_OFFSET                (RCC_OFFSET + 0x34)\r
94 #define LSION_BitNumber           0x00\r
95 #define CSR_LSION_BB              (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (LSION_BitNumber * 4))\r
96 \r
97 /* Alias word address of RTCEN bit */\r
98 #define RTCEN_BitNumber           0x16\r
99 #define CSR_RTCEN_BB              (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (RTCEN_BitNumber * 4))\r
100 \r
101 /* Alias word address of RTCRST bit */\r
102 #define RTCRST_BitNumber          0x17\r
103 #define CSR_RTCRST_BB             (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (RTCRST_BitNumber * 4))\r
104 \r
105 \r
106 /* ---------------------- RCC registers mask -------------------------------- */\r
107 /* RCC Flag Mask */\r
108 #define FLAG_MASK                 ((uint8_t)0x1F)\r
109 \r
110 /* CR register byte 3 (Bits[23:16]) base address */\r
111 #define CR_BYTE3_ADDRESS          ((uint32_t)0x40023802)\r
112 \r
113 /* ICSCR register byte 4 (Bits[31:24]) base address */\r
114 #define ICSCR_BYTE4_ADDRESS       ((uint32_t)0x40023807)\r
115 \r
116 /* CFGR register byte 3 (Bits[23:16]) base address */\r
117 #define CFGR_BYTE3_ADDRESS        ((uint32_t)0x4002380A)\r
118 \r
119 /* CFGR register byte 4 (Bits[31:24]) base address */\r
120 #define CFGR_BYTE4_ADDRESS        ((uint32_t)0x4002380B)\r
121 \r
122 /* CIR register byte 2 (Bits[15:8]) base address */\r
123 #define CIR_BYTE2_ADDRESS         ((uint32_t)0x4002380D)\r
124 \r
125 /* CIR register byte 3 (Bits[23:16]) base address */\r
126 #define CIR_BYTE3_ADDRESS         ((uint32_t)0x4002380E)\r
127 \r
128 /* CSR register byte 2 (Bits[15:8]) base address */\r
129 #define CSR_BYTE2_ADDRESS         ((uint32_t)0x40023835)\r
130 \r
131 /* Private macro -------------------------------------------------------------*/\r
132 /* Private variables ---------------------------------------------------------*/\r
133 \r
134 static __I uint8_t PLLMulTable[9] = {3, 4, 6, 8, 12, 16, 24, 32, 48};\r
135 static __I uint8_t APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};\r
136 \r
137 /* Private function prototypes -----------------------------------------------*/\r
138 /* Private functions ---------------------------------------------------------*/\r
139 \r
140 /** @defgroup RCC_Private_Functions\r
141   * @{\r
142   */\r
143 \r
144 /** @defgroup RCC_Group1 Internal and external clocks, PLL, CSS and MCO configuration functions\r
145  *  @brief   Internal and external clocks, PLL, CSS and MCO configuration functions \r
146  *\r
147 @verbatim   \r
148  ===============================================================================\r
149       Internal/external clocks, PLL, CSS and MCO configuration functions\r
150  ===============================================================================  \r
151 \r
152   This section provide functions allowing to configure the internal/external clocks,\r
153   PLL, CSS and MCO.\r
154   \r
155   1. HSI (high-speed internal), 16 MHz factory-trimmed RC used directly or through\r
156      the PLL as System clock source.\r
157 \r
158   2. MSI (multi-speed internal), multispeed low power RC (65.536 KHz to 4.194 MHz)\r
159      MHz used as System clock source.\r
160 \r
161   3. LSI (low-speed internal), 37 KHz low consumption RC used as IWDG and/or RTC\r
162      clock source.\r
163 \r
164   4. HSE (high-speed external), 1 to 24 MHz crystal oscillator used directly or\r
165      through the PLL as System clock source. Can be used also as RTC clock source.\r
166 \r
167   5. LSE (low-speed external), 32 KHz oscillator used as RTC clock source.   \r
168 \r
169   6. PLL (clocked by HSI or HSE), for System clock and USB (48 MHz).\r
170 \r
171   7. CSS (Clock security system), once enable and if a HSE clock failure occurs \r
172      (HSE used directly or through PLL as System clock source), the System clock\r
173      is automatically switched to MSI and an interrupt is generated if enabled. \r
174      The interrupt is linked to the Cortex-M3 NMI (Non-Maskable Interrupt) \r
175      exception vector.   \r
176 \r
177   8. MCO (microcontroller clock output), used to output SYSCLK, HSI, MSI, HSE, PLL,\r
178      LSI or LSE clock (through a configurable prescaler) on PA8 pin.\r
179 \r
180 @endverbatim\r
181   * @{\r
182   */\r
183 \r
184 /**\r
185   * @brief  Resets the RCC clock configuration to the default reset state.\r
186   * @note   - The default reset state of the clock configuration is given below:\r
187   *            - MSI ON and used as system clock source (MSI range is not modified\r
188   *              by this function, it keep the value configured by user application)\r
189   *            - HSI, HSE and PLL OFF\r
190   *            - AHB, APB1 and APB2 prescaler set to 1.\r
191   *            - CSS and MCO OFF\r
192   *            - All interrupts disabled\r
193   *         - However, this function doesn't modify the configuration of the\r
194   *            - Peripheral clocks\r
195   *            - LSI, LSE and RTC clocks                  \r
196   * @param  None\r
197   * @retval None\r
198   */\r
199 void RCC_DeInit(void)\r
200 {\r
201   \r
202   /* Set MSION bit */\r
203   RCC->CR |= (uint32_t)0x00000100;\r
204 \r
205   /* Reset SW[1:0], HPRE[3:0], PPRE1[2:0], PPRE2[2:0], MCOSEL[2:0] and MCOPRE[2:0] bits */\r
206   RCC->CFGR &= (uint32_t)0x88FFC00C;\r
207   \r
208   /* Reset HSION, HSEON, CSSON and PLLON bits */\r
209   RCC->CR &= (uint32_t)0xEEFEFFFE;\r
210 \r
211   /* Reset HSEBYP bit */\r
212   RCC->CR &= (uint32_t)0xFFFBFFFF;\r
213 \r
214   /* Reset PLLSRC, PLLMUL[3:0] and PLLDIV[1:0] bits */\r
215   RCC->CFGR &= (uint32_t)0xFF02FFFF;\r
216 \r
217   /* Disable all interrupts */\r
218   RCC->CIR = 0x00000000;\r
219 }\r
220 \r
221 /**\r
222   * @brief  Configures the External High Speed oscillator (HSE).\r
223   * @note   - After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the application\r
224   *           software should wait on HSERDY flag to be set indicating that HSE clock\r
225   *           is stable and can be used to clock the PLL and/or system clock.\r
226   *         - HSE state can not be changed if it is used directly or through the\r
227   *           PLL as system clock. In this case, you have to select another source\r
228   *           of the system clock then change the HSE state (ex. disable it).\r
229   *         - The HSE is stopped by hardware when entering STOP and STANDBY modes.         \r
230   * @note   This function reset the CSSON bit, so if the Clock security system(CSS)\r
231   *         was previously enabled you have to enable it again after calling this\r
232   *         function.\r
233   * @param RCC_HSE: specifies the new state of the HSE.\r
234   *   This parameter can be one of the following values:\r
235   *     @arg RCC_HSE_OFF: turn OFF the HSE oscillator, HSERDY flag goes low after\r
236   *                       6 HSE oscillator clock cycles.\r
237   *     @arg RCC_HSE_ON: turn ON the HSE oscillator\r
238   *     @arg RCC_HSE_Bypass: HSE oscillator bypassed with external clock\r
239   * @retval None\r
240   */\r
241 void RCC_HSEConfig(uint8_t RCC_HSE)\r
242 {\r
243   /* Check the parameters */\r
244   assert_param(IS_RCC_HSE(RCC_HSE));\r
245 \r
246   /* Reset HSEON and HSEBYP bits before configuring the HSE ------------------*/\r
247   *(__IO uint8_t *) CR_BYTE3_ADDRESS = RCC_HSE_OFF;\r
248 \r
249   /* Set the new HSE configuration -------------------------------------------*/\r
250   *(__IO uint8_t *) CR_BYTE3_ADDRESS = RCC_HSE;\r
251 \r
252 }\r
253 \r
254 /**\r
255   * @brief  Waits for HSE start-up.\r
256   * @note   This functions waits on HSERDY flag to be set and return SUCCESS if \r
257   *         this flag is set, otherwise returns ERROR if the timeout is reached \r
258   *         and this flag is not set. The timeout value is defined by the constant\r
259   *         HSE_STARTUP_TIMEOUT in stm32l1xx.h file. You can tailor it depending\r
260   *         on the HSE crystal used in your application. \r
261   * @param  None\r
262   * @retval An ErrorStatus enumeration value:\r
263   *          - SUCCESS: HSE oscillator is stable and ready to use\r
264   *          - ERROR: HSE oscillator not yet ready\r
265   */\r
266 ErrorStatus RCC_WaitForHSEStartUp(void)\r
267 {\r
268   __IO uint32_t StartUpCounter = 0;\r
269   ErrorStatus status = ERROR;\r
270   FlagStatus HSEStatus = RESET;\r
271   \r
272   /* Wait till HSE is ready and if timeout is reached exit */\r
273   do\r
274   {\r
275     HSEStatus = RCC_GetFlagStatus(RCC_FLAG_HSERDY);\r
276     StartUpCounter++;  \r
277   } while((StartUpCounter != HSE_STARTUP_TIMEOUT) && (HSEStatus == RESET));\r
278   \r
279   if (RCC_GetFlagStatus(RCC_FLAG_HSERDY) != RESET)\r
280   {\r
281     status = SUCCESS;\r
282   }\r
283   else\r
284   {\r
285     status = ERROR;\r
286   }  \r
287   return (status);\r
288 }\r
289 \r
290 /**\r
291   * @brief  Adjusts the Internal Multi Speed oscillator (MSI) calibration value.\r
292   * @note   The calibration is used to compensate for the variations in voltage\r
293   *         and temperature that influence the frequency of the internal MSI RC.\r
294   *         Refer to the Application Note AN3300 for more details on how to  \r
295   *         calibrate the MSI.\r
296   * @param  MSICalibrationValue: specifies the MSI calibration trimming value.\r
297   *   This parameter must be a number between 0 and 0xFF.\r
298   * @retval None\r
299   */\r
300 void RCC_AdjustMSICalibrationValue(uint8_t MSICalibrationValue)\r
301 {\r
302   \r
303   /* Check the parameters */\r
304   assert_param(IS_RCC_MSI_CALIBRATION_VALUE(MSICalibrationValue));\r
305 \r
306   *(__IO uint8_t *) ICSCR_BYTE4_ADDRESS = MSICalibrationValue;  \r
307 }\r
308 \r
309 /**\r
310   * @brief  Configures the Internal Multi Speed oscillator (MSI) clock range.\r
311   * @note   - After restart from Reset or wakeup from STANDBY, the MSI clock is \r
312   *           around 2.097 MHz. The MSI clock does not change after wake-up from\r
313   *           STOP mode.\r
314   *         - The MSI clock range can be modified on the fly.     \r
315   * @param  RCC_MSIRange: specifies the MSI Clock range.\r
316   *   This parameter must be one of the following values:\r
317   *     @arg RCC_MSIRange_0: MSI clock is around 65.536 KHz\r
318   *     @arg RCC_MSIRange_1: MSI clock is around 131.072 KHz\r
319   *     @arg RCC_MSIRange_2: MSI clock is around 262.144 KHz\r
320   *     @arg RCC_MSIRange_3: MSI clock is around 524.288 KHz\r
321   *     @arg RCC_MSIRange_4: MSI clock is around 1.048 MHz\r
322   *     @arg RCC_MSIRange_5: MSI clock is around 2.097 MHz (default after Reset or wake-up from STANDBY)\r
323   *     @arg RCC_MSIRange_6: MSI clock is around \r
324   *                   \r
325   * @retval None\r
326   */\r
327 void RCC_MSIRangeConfig(uint32_t RCC_MSIRange)\r
328 {\r
329   uint32_t tmpreg = 0;\r
330   \r
331   /* Check the parameters */\r
332   assert_param(IS_RCC_MSI_CLOCK_RANGE(RCC_MSIRange));\r
333   \r
334   tmpreg = RCC->ICSCR;\r
335   \r
336   /* Clear MSIRANGE[2:0] bits */\r
337   tmpreg &= ~RCC_ICSCR_MSIRANGE;\r
338   \r
339   /* Set the MSIRANGE[2:0] bits according to RCC_MSIRange value */\r
340   tmpreg |= (uint32_t)RCC_MSIRange;\r
341 \r
342   /* Store the new value */\r
343   RCC->ICSCR = tmpreg;\r
344 }\r
345 \r
346 /**\r
347   * @brief  Enables or disables the Internal Multi Speed oscillator (MSI).\r
348   * @note   - The MSI is stopped by hardware when entering STOP and STANDBY modes.\r
349   *           It is used (enabled by hardware) as system clock source after\r
350   *           startup from Reset, wakeup from STOP and STANDBY mode, or in case\r
351   *           of failure of the HSE used directly or indirectly as system clock\r
352   *           (if the Clock Security System CSS is enabled).             \r
353   *         - MSI can not be stopped if it is used as system clock source.\r
354   *           In this case, you have to select another source of the system\r
355   *           clock then stop the MSI.  \r
356   *         - After enabling the MSI, the application software should wait on\r
357   *           MSIRDY flag to be set indicating that MSI clock is stable and can\r
358   *           be used as system clock source.                                       \r
359   * @param  NewState: new state of the MSI.\r
360   *   This parameter can be: ENABLE or DISABLE.\r
361   * @note   When the MSI is stopped, MSIRDY flag goes low after 6 MSI oscillator\r
362   *         clock cycles.  \r
363   * @retval None\r
364   */\r
365 void RCC_MSICmd(FunctionalState NewState)\r
366 {\r
367   /* Check the parameters */\r
368   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
369   \r
370   *(__IO uint32_t *) CR_MSION_BB = (uint32_t)NewState;\r
371 }\r
372 \r
373 /**\r
374   * @brief  Adjusts the Internal High Speed oscillator (HSI) calibration value.\r
375   * @note   The calibration is used to compensate for the variations in voltage\r
376   *         and temperature that influence the frequency of the internal HSI RC.\r
377   *         Refer to the Application Note AN3300 for more details on how to  \r
378   *         calibrate the HSI.\r
379   * @param  HSICalibrationValue: specifies the HSI calibration trimming value.\r
380   *   This parameter must be a number between 0 and 0x1F.\r
381   * @retval None\r
382   */\r
383 void RCC_AdjustHSICalibrationValue(uint8_t HSICalibrationValue)\r
384 {\r
385   uint32_t tmpreg = 0;\r
386   \r
387   /* Check the parameters */\r
388   assert_param(IS_RCC_HSI_CALIBRATION_VALUE(HSICalibrationValue));\r
389   \r
390   tmpreg = RCC->ICSCR;\r
391   \r
392   /* Clear HSITRIM[4:0] bits */\r
393   tmpreg &= ~RCC_ICSCR_HSITRIM;\r
394   \r
395   /* Set the HSITRIM[4:0] bits according to HSICalibrationValue value */\r
396   tmpreg |= (uint32_t)HSICalibrationValue << 8;\r
397 \r
398   /* Store the new value */\r
399   RCC->ICSCR = tmpreg;\r
400 }\r
401 \r
402 /**\r
403   * @brief  Enables or disables the Internal High Speed oscillator (HSI).\r
404   * @note   - After enabling the HSI, the application software should wait on \r
405   *           HSIRDY flag to be set indicating that HSI clock is stable and can\r
406   *           be used to clock the PLL and/or system clock.\r
407   *         - HSI can not be stopped if it is used directly or through the PLL\r
408   *           as system clock. In this case, you have to select another source \r
409   *           of the system clock then stop the HSI.\r
410   *         - The HSI is stopped by hardware when entering STOP and STANDBY modes. \r
411   * @param  NewState: new state of the HSI.\r
412   *   This parameter can be: ENABLE or DISABLE.\r
413   * @note   When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator\r
414   *         clock cycles.  \r
415   * @retval None\r
416   */\r
417 void RCC_HSICmd(FunctionalState NewState)\r
418 {\r
419   /* Check the parameters */\r
420   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
421   \r
422   *(__IO uint32_t *) CR_HSION_BB = (uint32_t)NewState;\r
423 }\r
424 \r
425 /**\r
426   * @brief  Configures the External Low Speed oscillator (LSE).\r
427   * @note   - As the LSE is in the RTC domain and write access is denied to this\r
428   *           domain after reset, you have to enable write access using \r
429   *           PWR_RTCAccessCmd(ENABLE) function before to configure the LSE\r
430   *           (to be done once after reset).  \r
431   *         - After enabling the LSE (RCC_LSE_ON or RCC_LSE_Bypass), the application\r
432   *           software should wait on LSERDY flag to be set indicating that LSE clock\r
433   *           is stable and can be used to clock the RTC.\r
434   * @param  RCC_LSE: specifies the new state of the LSE.\r
435   *   This parameter can be one of the following values:\r
436   *     @arg RCC_LSE_OFF: turn OFF the LSE oscillator, LSERDY flag goes low after\r
437   *                       6 LSE oscillator clock cycles.\r
438   *     @arg RCC_LSE_ON: turn ON the LSE oscillator\r
439   *     @arg RCC_LSE_Bypass: LSE oscillator bypassed with external clock\r
440   * @retval None\r
441   */\r
442 void RCC_LSEConfig(uint8_t RCC_LSE)\r
443 {\r
444   /* Check the parameters */\r
445   assert_param(IS_RCC_LSE(RCC_LSE));\r
446   \r
447   /* Reset LSEON and LSEBYP bits before configuring the LSE ------------------*/\r
448   *(__IO uint8_t *) CSR_BYTE2_ADDRESS = RCC_LSE_OFF;\r
449 \r
450   /* Set the new LSE configuration -------------------------------------------*/\r
451   *(__IO uint8_t *) CSR_BYTE2_ADDRESS = RCC_LSE;  \r
452 }\r
453 \r
454 /**\r
455   * @brief  Enables or disables the Internal Low Speed oscillator (LSI).  \r
456   * @note   - After enabling the LSI, the application software should wait on \r
457   *           LSIRDY flag to be set indicating that LSI clock is stable and can\r
458   *           be used to clock the IWDG and/or the RTC.\r
459   *         - LSI can not be disabled if the IWDG is running.  \r
460   * @param  NewState: new state of the LSI.\r
461   *   This parameter can be: ENABLE or DISABLE.\r
462   * @note   When the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator\r
463   *         clock cycles. \r
464   * @retval None\r
465   */\r
466 void RCC_LSICmd(FunctionalState NewState)\r
467 {\r
468   /* Check the parameters */\r
469   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
470   \r
471   *(__IO uint32_t *) CSR_LSION_BB = (uint32_t)NewState;\r
472 }\r
473 \r
474 /**\r
475   * @brief  Configures the PLL clock source and multiplication factor.\r
476   * @note   This function must be used only when the PLL is disabled.\r
477   *   \r
478   * @param  RCC_PLLSource: specifies the PLL entry clock source.\r
479   *   This parameter can be one of the following values:\r
480   *     @arg RCC_PLLSource_HSI: HSI oscillator clock selected as PLL clock source\r
481   *     @arg RCC_PLLSource_HSE: HSE oscillator clock selected as PLL clock source\r
482   * @note   The minimum input clock frequency for PLL is 2 MHz (when using HSE as\r
483   *         PLL source).\r
484   *               \r
485   * @param  RCC_PLLMul: specifies the PLL multiplication factor, which drive the PLLVCO clock\r
486   *   This parameter can be:\r
487   *     @arg RCC_PLLMul_3: PLL clock source multiplied by 3\r
488   *     @arg RCC_PLLMul_4: PLL clock source multiplied by 4\r
489   *     @arg RCC_PLLMul_6: PLL clock source multiplied by 6\r
490   *     @arg RCC_PLLMul_8: PLL clock source multiplied by 8\r
491   *     @arg RCC_PLLMul_12: PLL clock source multiplied by 12\r
492   *     @arg RCC_PLLMul_16: PLL clock source multiplied by 16  \r
493   *     @arg RCC_PLLMul_24: PLL clock source multiplied by 24\r
494   *     @arg RCC_PLLMul_32: PLL clock source multiplied by 32\r
495   *     @arg RCC_PLLMul_48: PLL clock source multiplied by 48\r
496   * @note   The application software must set correctly the PLL multiplication\r
497   *         factor to avoid exceeding\r
498   *             - 96 MHz as PLLVCO when the product is in range 1\r
499   *             - 48 MHz as PLLVCO when the product is in range 2\r
500   *             - 24 MHz when the product is in range 3\r
501   * @note   When using the USB the PLLVCO should be 96MHz\r
502   *                                   \r
503   * @param  RCC_PLLDiv: specifies the PLL division factor.\r
504   *   This parameter can be:\r
505   *     @arg RCC_PLLDiv_2: PLL Clock output divided by 2  \r
506   *     @arg RCC_PLLDiv_3: PLL Clock output divided by 3         \r
507   *     @arg RCC_PLLDiv_4: PLL Clock output divided by 4  \r
508   * @note   The application software must set correctly the output division to avoid\r
509   *         exceeding 32 MHz as SYSCLK.\r
510   *            \r
511   * @retval None\r
512   */\r
513 void RCC_PLLConfig(uint8_t RCC_PLLSource, uint8_t RCC_PLLMul, uint8_t RCC_PLLDiv)\r
514 {\r
515   /* Check the parameters */\r
516   assert_param(IS_RCC_PLL_SOURCE(RCC_PLLSource));\r
517   assert_param(IS_RCC_PLL_MUL(RCC_PLLMul));\r
518   assert_param(IS_RCC_PLL_DIV(RCC_PLLDiv));\r
519   \r
520   *(__IO uint8_t *) CFGR_BYTE3_ADDRESS = (uint8_t)(RCC_PLLSource | ((uint8_t)(RCC_PLLMul | (uint8_t)(RCC_PLLDiv))));\r
521 }\r
522 \r
523 /**\r
524   * @brief  Enables or disables the PLL.\r
525   * @note   - After enabling the PLL, the application software should wait on \r
526   *           PLLRDY flag to be set indicating that PLL clock is stable and can\r
527   *           be used as system clock source.\r
528   *         - The PLL can not be disabled if it is used as system clock source\r
529   *         - The PLL is disabled by hardware when entering STOP and STANDBY modes.    \r
530   * @param  NewState: new state of the PLL.\r
531   *   This parameter can be: ENABLE or DISABLE.\r
532   * @retval None\r
533   */\r
534 void RCC_PLLCmd(FunctionalState NewState)\r
535 {\r
536   /* Check the parameters */\r
537   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
538   \r
539   *(__IO uint32_t *) CR_PLLON_BB = (uint32_t)NewState;\r
540 }\r
541 \r
542 /**\r
543   * @brief  Enables or disables the Clock Security System.\r
544   * @note   If a failure is detected on the HSE oscillator clock, this oscillator\r
545   *         is automatically disabled and an interrupt is generated to inform the\r
546   *         software about the failure (Clock Security System Interrupt, CSSI),\r
547   *         allowing the MCU to perform rescue operations. The CSSI is linked to \r
548   *         the Cortex-M3 NMI (Non-Maskable Interrupt) exception vector.  \r
549   * @param  NewState: new state of the Clock Security System.\r
550   *         This parameter can be: ENABLE or DISABLE.\r
551   * @retval None\r
552   */\r
553 void RCC_ClockSecuritySystemCmd(FunctionalState NewState)\r
554 {\r
555   /* Check the parameters */\r
556   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
557   \r
558   *(__IO uint32_t *) CR_CSSON_BB = (uint32_t)NewState;\r
559 }\r
560 \r
561 /**\r
562   * @brief  Selects the clock source to output on MCO pin (PA8).\r
563   * @note   PA8 should be configured in alternate function mode.   \r
564   * @param  RCC_MCOSource: specifies the clock source to output.\r
565   *   This parameter can be one of the following values:\r
566   *     @arg RCC_MCOSource_NoClock: No clock selected\r
567   *     @arg RCC_MCOSource_SYSCLK: System clock selected\r
568   *     @arg RCC_MCOSource_HSI: HSI oscillator clock selected\r
569   *     @arg RCC_MCOSource_MSI: MSI oscillator clock selected  \r
570   *     @arg RCC_MCOSource_HSE: HSE oscillator clock selected\r
571   *     @arg RCC_MCOSource_PLLCLK: PLL clock selected\r
572   *     @arg RCC_MCOSource_LSI: LSI clock selected\r
573   *     @arg RCC_MCOSource_LSE: LSE clock selected    \r
574   * @param  RCC_MCODiv: specifies the MCO prescaler.\r
575   *   This parameter can be one of the following values: \r
576   *     @arg RCC_MCODiv_1: no division applied to MCO clock \r
577   *     @arg RCC_MCODiv_2: division by 2 applied to MCO clock\r
578   *     @arg RCC_MCODiv_4: division by 4 applied to MCO clock\r
579   *     @arg RCC_MCODiv_8: division by 8 applied to MCO clock\r
580   *     @arg RCC_MCODiv_16: division by 16 applied to MCO clock             \r
581   * @retval None\r
582   */\r
583 void RCC_MCOConfig(uint8_t RCC_MCOSource, uint8_t RCC_MCODiv)\r
584 {\r
585   /* Check the parameters */\r
586   assert_param(IS_RCC_MCO_SOURCE(RCC_MCOSource));\r
587   assert_param(IS_RCC_MCO_DIV(RCC_MCODiv));\r
588     \r
589   /* Select MCO clock source and prescaler */\r
590   *(__IO uint8_t *) CFGR_BYTE4_ADDRESS =  RCC_MCOSource | RCC_MCODiv; \r
591 }\r
592 \r
593 /**\r
594   * @}\r
595   */\r
596 \r
597 /** @defgroup RCC_Group2 System AHB and APB busses clocks configuration functions\r
598  *  @brief   System, AHB and APB busses clocks configuration functions\r
599  *\r
600 @verbatim   \r
601  ===============================================================================\r
602              System, AHB and APB busses clocks configuration functions\r
603  ===============================================================================  \r
604 \r
605   This section provide functions allowing to configure the System, AHB, APB1 and \r
606   APB2 busses clocks.\r
607   \r
608   1. Several clock sources can be used to drive the System clock (SYSCLK): MSI, HSI,\r
609      HSE and PLL.\r
610      The AHB clock (HCLK) is derived from System clock through configurable prescaler\r
611      and used to clock the CPU, memory and peripherals mapped on AHB bus (DMA and GPIO).\r
612      APB1 (PCLK1) and APB2 (PCLK2) clocks are derived from AHB clock through \r
613      configurable prescalers and used to clock the peripherals mapped on these busses.\r
614      You can use "RCC_GetClocksFreq()" function to retrieve the frequencies of these clocks.  \r
615 \r
616 Note: All the peripheral clocks are derived from the System clock (SYSCLK) except:\r
617 ====   - The USB 48 MHz clock which is derived from the PLL VCO clock.\r
618        - The ADC clock which is always the HSI clock. A divider by 1, 2 or 4 allows\r
619          to adapt the clock frequency to the device operating conditions. \r
620        - The RTC/LCD clock which is derived from the LSE, LSI or 1 MHz HSE_RTC (HSE\r
621          divided by a programmable prescaler).\r
622          The System clock (SYSCLK) frequency must be higher or equal to the RTC/LCD\r
623          clock frequency.\r
624        - IWDG clock which is always the LSI clock.\r
625        \r
626   2. The maximum frequency of the SYSCLK, HCLK, PCLK1 and PCLK2 is 32 MHz.\r
627      Depending on the device voltage range, the maximum frequency should be \r
628      adapted accordingly:\r
629         +----------------------------------------------------------------+     \r
630         |  Wait states  |                HCLK clock frequency (MHz)      |\r
631         |               |------------------------------------------------|     \r
632         |   (Latency)   |            voltage range       | voltage range | \r
633         |               |            1.65 V - 3.6 V      | 2.0 V - 3.6 V |\r
634         |               |----------------|---------------|---------------| \r
635         |               |  VCORE = 1.2 V | VCORE = 1.5 V | VCORE = 1.8 V |\r
636         |-------------- |----------------|---------------|---------------|             \r
637         |0WS(1CPU cycle)|0 < HCLK <= 2   |0 < HCLK <= 8  |0 < HCLK <= 16 |\r
638         |---------------|----------------|---------------|---------------|  \r
639         |1WS(2CPU cycle)|2 < HCLK <= 4   |8 < HCLK <= 16 |16 < HCLK <= 32| \r
640         +----------------------------------------------------------------+   \r
641 \r
642   3. After reset, the System clock source is the MSI (2 MHz) with 0 WS, Flash\r
643      32-bit access is enabled and prefetch is disabled.\r
644   \r
645      It is recommended to use the following software sequences to tune the number\r
646      of wait states needed to access the Flash memory with the CPU frequency (HCLK).\r
647       - Increasing the CPU frequency (in the same voltage range)\r
648          - Program the Flash 64-bit access, using "FLASH_ReadAccess64Cmd(ENABLE)" function\r
649          - Check that 64-bit access is taken into account by reading FLASH_ACR\r
650          - Program Flash WS to 1, using "FLASH_SetLatency(FLASH_Latency_1)" function\r
651          - Check that the new number of WS is taken into account by reading FLASH_ACR\r
652          - Modify the CPU clock source, using "RCC_SYSCLKConfig()" function\r
653          - If needed, modify the CPU clock prescaler by using "RCC_HCLKConfig()" function\r
654          - Check that the new CPU clock source is taken into account by reading \r
655            the clock source status, using "RCC_GetSYSCLKSource()" function \r
656       - Decreasing the CPU frequency (in the same voltage range)\r
657          - Modify the CPU clock source, using "RCC_SYSCLKConfig()" function\r
658          - If needed, modify the CPU clock prescaler by using "RCC_HCLKConfig()" function\r
659          - Check that the new CPU clock source is taken into account by reading \r
660            the clock source status, using "RCC_GetSYSCLKSource()" function\r
661          - Program the new number of WS, using "FLASH_SetLatency()" function\r
662          - Check that the new number of WS is taken into account by reading FLASH_ACR\r
663          - Enable the Flash 32-bit access, using "FLASH_ReadAccess64Cmd(DISABLE)" function\r
664          - Check that 32-bit access is taken into account by reading FLASH_ACR\r
665 \r
666 @endverbatim\r
667   * @{\r
668   */\r
669 \r
670 /**\r
671   * @brief  Configures the system clock (SYSCLK).\r
672   * @note   - The MSI is used (enabled by hardware) as system clock source after\r
673   *           startup from Reset, wake-up from STOP and STANDBY mode, or in case\r
674   *           of failure of the HSE used directly or indirectly as system clock\r
675   *           (if the Clock Security System CSS is enabled).\r
676   *         - A switch from one clock source to another occurs only if the target\r
677   *           clock source is ready (clock stable after startup delay or PLL locked). \r
678   *           If a clock source which is not yet ready is selected, the switch will\r
679   *           occur when the clock source will be ready. \r
680   *           You can use RCC_GetSYSCLKSource() function to know which clock is\r
681   *           currently used as system clock source.  \r
682   * @param  RCC_SYSCLKSource: specifies the clock source used as system clock source \r
683   *   This parameter can be one of the following values:\r
684   *     @arg RCC_SYSCLKSource_MSI:    MSI selected as system clock source\r
685   *     @arg RCC_SYSCLKSource_HSI:    HSI selected as system clock source\r
686   *     @arg RCC_SYSCLKSource_HSE:    HSE selected as system clock source\r
687   *     @arg RCC_SYSCLKSource_PLLCLK: PLL selected as system clock source\r
688   * @retval None\r
689   */\r
690 void RCC_SYSCLKConfig(uint32_t RCC_SYSCLKSource)\r
691 {\r
692   uint32_t tmpreg = 0;\r
693   \r
694   /* Check the parameters */\r
695   assert_param(IS_RCC_SYSCLK_SOURCE(RCC_SYSCLKSource));\r
696   \r
697   tmpreg = RCC->CFGR;\r
698   \r
699   /* Clear SW[1:0] bits */\r
700   tmpreg &= ~RCC_CFGR_SW;\r
701   \r
702   /* Set SW[1:0] bits according to RCC_SYSCLKSource value */\r
703   tmpreg |= RCC_SYSCLKSource;\r
704   \r
705   /* Store the new value */\r
706   RCC->CFGR = tmpreg;\r
707 }\r
708 \r
709 /**\r
710   * @brief  Returns the clock source used as system clock.\r
711   * @param  None\r
712   * @retval The clock source used as system clock. The returned value can be one \r
713   *         of the following values:\r
714   *              - 0x00: MSI used as system clock\r
715   *              - 0x04: HSI used as system clock  \r
716   *              - 0x08: HSE used as system clock\r
717   *              - 0x0C: PLL used as system clock\r
718   */\r
719 uint8_t RCC_GetSYSCLKSource(void)\r
720 {\r
721   return ((uint8_t)(RCC->CFGR & RCC_CFGR_SWS));\r
722 }\r
723 \r
724 /**\r
725   * @brief  Configures the AHB clock (HCLK).\r
726   * @note   Depending on the device voltage range, the software has to set correctly\r
727   *         these bits to ensure that the system frequency does not exceed the\r
728   *         maximum allowed frequency (for more details refer to section above\r
729   *         "CPU, AHB and APB busses clocks configuration functions")\r
730   * @param  RCC_SYSCLK: defines the AHB clock divider. This clock is derived from \r
731   *                     the system clock (SYSCLK).\r
732   *   This parameter can be one of the following values:\r
733   *     @arg RCC_SYSCLK_Div1:   AHB clock = SYSCLK\r
734   *     @arg RCC_SYSCLK_Div2:   AHB clock = SYSCLK/2\r
735   *     @arg RCC_SYSCLK_Div4:   AHB clock = SYSCLK/4\r
736   *     @arg RCC_SYSCLK_Div8:   AHB clock = SYSCLK/8\r
737   *     @arg RCC_SYSCLK_Div16:  AHB clock = SYSCLK/16\r
738   *     @arg RCC_SYSCLK_Div64:  AHB clock = SYSCLK/64\r
739   *     @arg RCC_SYSCLK_Div128: AHB clock = SYSCLK/128\r
740   *     @arg RCC_SYSCLK_Div256: AHB clock = SYSCLK/256\r
741   *     @arg RCC_SYSCLK_Div512: AHB clock = SYSCLK/512\r
742   * @retval None\r
743   */\r
744 void RCC_HCLKConfig(uint32_t RCC_SYSCLK)\r
745 {\r
746   uint32_t tmpreg = 0;\r
747   \r
748   /* Check the parameters */\r
749   assert_param(IS_RCC_HCLK(RCC_SYSCLK));\r
750   \r
751   tmpreg = RCC->CFGR;\r
752   \r
753   /* Clear HPRE[3:0] bits */\r
754   tmpreg &= ~RCC_CFGR_HPRE;\r
755   \r
756   /* Set HPRE[3:0] bits according to RCC_SYSCLK value */\r
757   tmpreg |= RCC_SYSCLK;\r
758   \r
759   /* Store the new value */\r
760   RCC->CFGR = tmpreg;\r
761 }\r
762 \r
763 /**\r
764   * @brief  Configures the Low Speed APB clock (PCLK1).\r
765   * @param  RCC_HCLK: defines the APB1 clock divider. This clock is derived from \r
766   *                   the AHB clock (HCLK).\r
767   *   This parameter can be one of the following values:\r
768   *     @arg RCC_HCLK_Div1:  APB1 clock = HCLK\r
769   *     @arg RCC_HCLK_Div2:  APB1 clock = HCLK/2\r
770   *     @arg RCC_HCLK_Div4:  APB1 clock = HCLK/4\r
771   *     @arg RCC_HCLK_Div8:  APB1 clock = HCLK/8\r
772   *     @arg RCC_HCLK_Div16: APB1 clock = HCLK/16\r
773   * @retval None\r
774   */\r
775 void RCC_PCLK1Config(uint32_t RCC_HCLK)\r
776 {\r
777   uint32_t tmpreg = 0;\r
778   \r
779   /* Check the parameters */\r
780   assert_param(IS_RCC_PCLK(RCC_HCLK));\r
781   \r
782   tmpreg = RCC->CFGR;\r
783   \r
784   /* Clear PPRE1[2:0] bits */\r
785   tmpreg &= ~RCC_CFGR_PPRE1;\r
786   \r
787   /* Set PPRE1[2:0] bits according to RCC_HCLK value */\r
788   tmpreg |= RCC_HCLK;\r
789   \r
790   /* Store the new value */\r
791   RCC->CFGR = tmpreg;\r
792 }\r
793 \r
794 /**\r
795   * @brief  Configures the High Speed APB clock (PCLK2).\r
796   * @param  RCC_HCLK: defines the APB2 clock divider. This clock is derived from \r
797   *                   the AHB clock (HCLK).\r
798   *   This parameter can be one of the following values:\r
799   *     @arg RCC_HCLK_Div1:  APB2 clock = HCLK\r
800   *     @arg RCC_HCLK_Div2:  APB2 clock = HCLK/2\r
801   *     @arg RCC_HCLK_Div4:  APB2 clock = HCLK/4\r
802   *     @arg RCC_HCLK_Div8:  APB2 clock = HCLK/8\r
803   *     @arg RCC_HCLK_Div16: APB2 clock = HCLK/16\r
804   * @retval None\r
805   */\r
806 void RCC_PCLK2Config(uint32_t RCC_HCLK)\r
807 {\r
808   uint32_t tmpreg = 0;\r
809   \r
810   /* Check the parameters */\r
811   assert_param(IS_RCC_PCLK(RCC_HCLK));\r
812   \r
813   tmpreg = RCC->CFGR;\r
814   \r
815   /* Clear PPRE2[2:0] bits */\r
816   tmpreg &= ~RCC_CFGR_PPRE2;\r
817   \r
818   /* Set PPRE2[2:0] bits according to RCC_HCLK value */\r
819   tmpreg |= RCC_HCLK << 3;\r
820   \r
821   /* Store the new value */\r
822   RCC->CFGR = tmpreg;\r
823 }\r
824 \r
825 /**\r
826   * @brief  Returns the frequencies of the System, AHB and APB busses clocks.\r
827   * @note   - The frequency returned by this function is not the real frequency\r
828   *           in the chip. It is calculated based on the predefined constant and\r
829   *           the source selected by RCC_SYSCLKConfig():\r
830   *             \r
831   *           - If SYSCLK source is MSI, function returns constant the MSI value\r
832   *             as defined by the MSI range, refer to RCC_MSIRangeConfig()\r
833   *                                   \r
834   *           - If SYSCLK source is HSI, function returns constant HSI_VALUE(*)\r
835   *                                              \r
836   *           - If SYSCLK source is HSE, function returns constant HSE_VALUE(**)\r
837   *                          \r
838   *           - If SYSCLK source is PLL, function returns constant HSE_VALUE(**) \r
839   *             or HSI_VALUE(*) multiplied/divided by the PLL factors.\r
840   *         \r
841   *         (*) HSI_VALUE is a constant defined in stm32l1xx.h file (default value\r
842   *             16 MHz) but the real value may vary depending on the variations\r
843   *             in voltage and temperature, refer to RCC_AdjustHSICalibrationValue().   \r
844   *    \r
845   *         (**) HSE_VALUE is a constant defined in stm32l1xx.h file (default value\r
846   *              8 MHz), user has to ensure that HSE_VALUE is same as the real\r
847   *              frequency of the crystal used. Otherwise, this function may\r
848   *              return wrong result.\r
849   *                \r
850   *         - The result of this function could be not correct when using fractional\r
851   *           value for HSE crystal.   \r
852   *             \r
853   * @param  RCC_Clocks: pointer to a RCC_ClocksTypeDef structure which will hold \r
854   *         the clocks frequencies. \r
855   * @retval None\r
856   */\r
857 void RCC_GetClocksFreq(RCC_ClocksTypeDef* RCC_Clocks)\r
858 {\r
859   uint32_t tmp = 0, pllmul = 0, plldiv = 0, pllsource = 0, presc = 0, msirange = 0;\r
860 \r
861   /* Get SYSCLK source -------------------------------------------------------*/\r
862   tmp = RCC->CFGR & RCC_CFGR_SWS;\r
863   \r
864   switch (tmp)\r
865   {\r
866     case 0x00:  /* MSI used as system clock */\r
867       msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE ) >> 13;\r
868       RCC_Clocks->SYSCLK_Frequency = (32768 * (1 << (msirange + 1)));\r
869       break;\r
870     case 0x04:  /* HSI used as system clock */\r
871       RCC_Clocks->SYSCLK_Frequency = HSI_VALUE;\r
872       break;\r
873     case 0x08:  /* HSE used as system clock */\r
874       RCC_Clocks->SYSCLK_Frequency = HSE_VALUE;\r
875       break;\r
876     case 0x0C:  /* PLL used as system clock */\r
877       /* Get PLL clock source and multiplication factor ----------------------*/\r
878       pllmul = RCC->CFGR & RCC_CFGR_PLLMUL;\r
879       plldiv = RCC->CFGR & RCC_CFGR_PLLDIV;\r
880       pllmul = PLLMulTable[(pllmul >> 18)];\r
881       plldiv = (plldiv >> 22) + 1;\r
882       \r
883       pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;\r
884 \r
885       if (pllsource == 0x00)\r
886       {\r
887         /* HSI oscillator clock selected as PLL clock source */\r
888         RCC_Clocks->SYSCLK_Frequency = (((HSI_VALUE) * pllmul) / plldiv);\r
889       }\r
890       else\r
891       {\r
892         /* HSE selected as PLL clock source */\r
893         RCC_Clocks->SYSCLK_Frequency = (((HSE_VALUE) * pllmul) / plldiv);\r
894       }\r
895       break;\r
896     default: /* MSI used as system clock */\r
897       msirange = (RCC->ICSCR & RCC_ICSCR_MSIRANGE ) >> 13;\r
898       RCC_Clocks->SYSCLK_Frequency = (32768 * (1 << (msirange + 1)));\r
899       break;\r
900   }\r
901   /* Compute HCLK, PCLK1, PCLK2 and ADCCLK clocks frequencies ----------------*/\r
902   /* Get HCLK prescaler */\r
903   tmp = RCC->CFGR & RCC_CFGR_HPRE;\r
904   tmp = tmp >> 4;\r
905   presc = APBAHBPrescTable[tmp]; \r
906   /* HCLK clock frequency */\r
907   RCC_Clocks->HCLK_Frequency = RCC_Clocks->SYSCLK_Frequency >> presc;\r
908 \r
909   /* Get PCLK1 prescaler */\r
910   tmp = RCC->CFGR & RCC_CFGR_PPRE1;\r
911   tmp = tmp >> 8;\r
912   presc = APBAHBPrescTable[tmp];\r
913   /* PCLK1 clock frequency */\r
914   RCC_Clocks->PCLK1_Frequency = RCC_Clocks->HCLK_Frequency >> presc;\r
915 \r
916   /* Get PCLK2 prescaler */\r
917   tmp = RCC->CFGR & RCC_CFGR_PPRE2;\r
918   tmp = tmp >> 11;\r
919   presc = APBAHBPrescTable[tmp];\r
920   /* PCLK2 clock frequency */\r
921   RCC_Clocks->PCLK2_Frequency = RCC_Clocks->HCLK_Frequency >> presc;\r
922 }\r
923 \r
924 /**\r
925   * @}\r
926   */\r
927 \r
928 /** @defgroup RCC_Group3 Peripheral clocks configuration functions\r
929  *  @brief   Peripheral clocks configuration functions \r
930  *\r
931 @verbatim   \r
932  ===============================================================================\r
933                    Peripheral clocks configuration functions\r
934  ===============================================================================  \r
935 \r
936   This section provide functions allowing to configure the Peripheral clocks. \r
937   \r
938   1. The RTC/LCD clock which is derived from the LSE, LSI or 1 MHz HSE_RTC (HSE\r
939      divided by a programmable prescaler).\r
940      \r
941   2. After restart from Reset or wakeup from STANDBY, all peripherals are off\r
942      except internal SRAM, Flash and JTAG. Before to start using a peripheral you\r
943      have to enable its interface clock. You can do this using RCC_AHBPeriphClockCmd()\r
944      , RCC_APB2PeriphClockCmd() and RCC_APB1PeriphClockCmd() functions.\r
945 \r
946   3. To reset the peripherals configuration (to the default state after device reset)\r
947      you can use RCC_AHBPeriphResetCmd(), RCC_APB2PeriphResetCmd() and \r
948      RCC_APB1PeriphResetCmd() functions.\r
949      \r
950   4. To further reduce power consumption in SLEEP mode the peripheral clocks can\r
951      be disabled prior to executing the WFI or WFE instructions. You can do this\r
952      using RCC_AHBPeriphClockLPModeCmd(), RCC_APB2PeriphClockLPModeCmd() and\r
953      RCC_APB1PeriphClockLPModeCmd() functions.  \r
954 \r
955 @endverbatim\r
956   * @{\r
957   */\r
958 \r
959 /**\r
960   * @brief  Configures the RTC and LCD clock (RTCCLK / LCDCLK).\r
961   * @note   - As the RTC clock configuration bits are in the RTC domain and write\r
962   *           access is denied to this domain after reset, you have to enable write\r
963   *           access using PWR_RTCAccessCmd(ENABLE) function before to configure\r
964   *           the RTC clock source (to be done once after reset).    \r
965   *         - Once the RTC clock is configured it can't be changed unless the RTC\r
966   *           is reset using RCC_RTCResetCmd function, or by a Power On Reset (POR)\r
967   *         - The RTC clock (RTCCLK) is used also to clock the LCD (LCDCLK).\r
968   *             \r
969   * @param  RCC_RTCCLKSource: specifies the RTC clock source.\r
970   *   This parameter can be one of the following values:\r
971   *     @arg RCC_RTCCLKSource_LSE: LSE selected as RTC clock\r
972   *     @arg RCC_RTCCLKSource_LSI: LSI selected as RTC clock\r
973   *     @arg RCC_RTCCLKSource_HSE_Div2: HSE divided by 2 selected as RTC clock\r
974   *     @arg RCC_RTCCLKSource_HSE_Div4: HSE divided by 4 selected as RTC clock\r
975   *     @arg RCC_RTCCLKSource_HSE_Div8: HSE divided by 8 selected as RTC clock\r
976   *     @arg RCC_RTCCLKSource_HSE_Div16: HSE divided by 16 selected as RTC clock\r
977   *       \r
978   * @note   - If the LSE or LSI is used as RTC clock source, the RTC continues to\r
979   *           work in STOP and STANDBY modes, and can be used as wakeup source.\r
980   *           However, when the HSE clock is used as RTC clock source, the RTC\r
981   *           cannot be used in STOP and STANDBY modes.\r
982   *             \r
983   *         - The maximum input clock frequency for RTC is 1MHz (when using HSE as\r
984   *           RTC clock source).\r
985   *                          \r
986   * @retval None\r
987   */\r
988 void RCC_RTCCLKConfig(uint32_t RCC_RTCCLKSource)\r
989 {\r
990   uint32_t      tmpreg = 0;\r
991 \r
992   /* Check the parameters */\r
993   assert_param(IS_RCC_RTCCLK_SOURCE(RCC_RTCCLKSource));\r
994   \r
995   if ((RCC_RTCCLKSource & RCC_CSR_RTCSEL_HSE) == RCC_CSR_RTCSEL_HSE)\r
996   { \r
997     /* If HSE is selected as RTC clock source, configure HSE division factor for RTC clock */\r
998     tmpreg = RCC->CR;\r
999 \r
1000     /* Clear RTCPRE[1:0] bits */\r
1001     tmpreg &= ~RCC_CR_RTCPRE;\r
1002 \r
1003     /* Configure HSE division factor for RTC clock */\r
1004     tmpreg |= (RCC_RTCCLKSource & RCC_CR_RTCPRE);\r
1005 \r
1006     /* Store the new value */\r
1007     RCC->CR = tmpreg;\r
1008   }\r
1009          \r
1010   RCC->CSR &= ~RCC_CSR_RTCSEL;\r
1011   \r
1012   /* Select the RTC clock source */\r
1013   RCC->CSR |= (RCC_RTCCLKSource & RCC_CSR_RTCSEL);\r
1014 }\r
1015 \r
1016 /**\r
1017   * @brief  Enables or disables the RTC clock.\r
1018   * @note   This function must be used only after the RTC clock source was selected\r
1019   *         using the RCC_RTCCLKConfig function.\r
1020   * @param  NewState: new state of the RTC clock.\r
1021   *   This parameter can be: ENABLE or DISABLE.\r
1022   * @retval None\r
1023   */\r
1024 void RCC_RTCCLKCmd(FunctionalState NewState)\r
1025 {\r
1026   /* Check the parameters */\r
1027   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1028   \r
1029   *(__IO uint32_t *) CSR_RTCEN_BB = (uint32_t)NewState;\r
1030 }\r
1031 \r
1032 /**\r
1033   * @brief  Forces or releases the RTC peripheral and associated resources reset.\r
1034   * @note   This function resets the RTC peripheral, RTC clock source selection\r
1035   *         (in RCC_CSR) and the backup registers.\r
1036   * @param  NewState: new state of the RTC reset.\r
1037   *   This parameter can be: ENABLE or DISABLE.\r
1038   * @retval None\r
1039   */\r
1040 void RCC_RTCResetCmd(FunctionalState NewState)\r
1041 {\r
1042   /* Check the parameters */\r
1043   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1044   \r
1045   *(__IO uint32_t *) CSR_RTCRST_BB = (uint32_t)NewState;\r
1046 }\r
1047 \r
1048 /**\r
1049   * @brief  Enables or disables the AHB peripheral clock.\r
1050   * @note   After reset, the peripheral clock (used for registers read/write access)\r
1051   *         is disabled and the application software has to enable this clock before \r
1052   *         using it.    \r
1053   * @param  RCC_AHBPeriph: specifies the AHB peripheral to gates its clock.\r
1054   *   This parameter can be any combination of the following values:\r
1055   *     @arg RCC_AHBPeriph_GPIOA\r
1056   *     @arg RCC_AHBPeriph_GPIOB\r
1057   *     @arg RCC_AHBPeriph_GPIOC  \r
1058   *     @arg RCC_AHBPeriph_GPIOD\r
1059   *     @arg RCC_AHBPeriph_GPIOE\r
1060   *     @arg RCC_AHBPeriph_GPIOH\r
1061   *     @arg RCC_AHBPeriph_CRC\r
1062   *     @arg RCC_AHBPeriph_FLITF (has effect only when the Flash memory is in power down mode)  \r
1063   *     @arg RCC_AHBPeriph_DMA1\r
1064   * @param  NewState: new state of the specified peripheral clock.\r
1065   *         This parameter can be: ENABLE or DISABLE.\r
1066   * @retval None\r
1067   */\r
1068 void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)\r
1069 {\r
1070   /* Check the parameters */\r
1071   assert_param(IS_RCC_AHB_PERIPH(RCC_AHBPeriph));\r
1072   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1073   \r
1074   if (NewState != DISABLE)\r
1075   {\r
1076     RCC->AHBENR |= RCC_AHBPeriph;\r
1077   }\r
1078   else\r
1079   {\r
1080     RCC->AHBENR &= ~RCC_AHBPeriph;\r
1081   }\r
1082 }\r
1083 \r
1084 /**\r
1085   * @brief  Enables or disables the High Speed APB (APB2) peripheral clock.\r
1086   * @note   After reset, the peripheral clock (used for registers read/write access)\r
1087   *         is disabled and the application software has to enable this clock before \r
1088   *         using it.\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_SYSCFG\r
1092   *     @arg RCC_APB2Periph_TIM9\r
1093   *     @arg RCC_APB2Periph_TIM10\r
1094   *     @arg RCC_APB2Periph_TIM11\r
1095   *     @arg RCC_APB2Periph_ADC1\r
1096   *     @arg RCC_APB2Periph_SPI1\r
1097   *     @arg RCC_APB2Periph_USART1            \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 \r
1108   if (NewState != DISABLE)\r
1109   {\r
1110     RCC->APB2ENR |= RCC_APB2Periph;\r
1111   }\r
1112   else\r
1113   {\r
1114     RCC->APB2ENR &= ~RCC_APB2Periph;\r
1115   }\r
1116 }\r
1117 \r
1118 /**\r
1119   * @brief  Enables or disables the Low Speed APB (APB1) peripheral clock.\r
1120   * @note   After reset, the peripheral clock (used for registers read/write access)\r
1121   *         is disabled and the application software has to enable this clock before \r
1122   *         using it.\r
1123   * @param  RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.\r
1124   *   This parameter can be any combination of the following values:\r
1125   *     @arg RCC_APB1Periph_TIM2\r
1126   *     @arg RCC_APB1Periph_TIM3\r
1127   *     @arg RCC_APB1Periph_TIM4\r
1128   *     @arg RCC_APB1Periph_TIM6\r
1129   *     @arg RCC_APB1Periph_TIM7\r
1130   *     @arg RCC_APB1Periph_LCD\r
1131   *     @arg RCC_APB1Periph_WWDG\r
1132   *     @arg RCC_APB1Periph_SPI2\r
1133   *     @arg RCC_APB1Periph_USART2\r
1134   *     @arg RCC_APB1Periph_USART3\r
1135   *     @arg RCC_APB1Periph_I2C1\r
1136   *     @arg RCC_APB1Periph_I2C2\r
1137   *     @arg RCC_APB1Periph_USB\r
1138   *     @arg RCC_APB1Periph_PWR\r
1139   *     @arg RCC_APB1Periph_DAC\r
1140   *     @arg RCC_APB1Periph_COMP                                \r
1141   * @param  NewState: new state of the specified peripheral clock.\r
1142   *         This parameter can be: ENABLE or DISABLE.\r
1143   * @retval None\r
1144   */\r
1145 void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)\r
1146 {\r
1147   /* Check the parameters */\r
1148   assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));\r
1149   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1150 \r
1151   if (NewState != DISABLE)\r
1152   {\r
1153     RCC->APB1ENR |= RCC_APB1Periph;\r
1154   }\r
1155   else\r
1156   {\r
1157     RCC->APB1ENR &= ~RCC_APB1Periph;\r
1158   }\r
1159 }\r
1160 \r
1161 /**\r
1162   * @brief  Forces or releases AHB peripheral reset.\r
1163   * @param  RCC_AHBPeriph: specifies the AHB peripheral to reset.\r
1164   *   This parameter can be any combination of the following values:\r
1165   *     @arg RCC_AHBPeriph_GPIOA\r
1166   *     @arg RCC_AHBPeriph_GPIOB\r
1167   *     @arg RCC_AHBPeriph_GPIOC  \r
1168   *     @arg RCC_AHBPeriph_GPIOD\r
1169   *     @arg RCC_AHBPeriph_GPIOE\r
1170   *     @arg RCC_AHBPeriph_GPIOH\r
1171   *     @arg RCC_AHBPeriph_CRC\r
1172   *     @arg RCC_AHBPeriph_FLITF (has effect only when the Flash memory is in power down mode)  \r
1173   *     @arg RCC_AHBPeriph_DMA1   \r
1174   * @param  NewState: new state of the specified peripheral reset.\r
1175   *         This parameter can be: ENABLE or DISABLE.\r
1176   * @retval None\r
1177   */\r
1178 void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)\r
1179 {\r
1180   /* Check the parameters */\r
1181   assert_param(IS_RCC_AHB_PERIPH(RCC_AHBPeriph));\r
1182   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1183 \r
1184   if (NewState != DISABLE)\r
1185   {\r
1186     RCC->AHBRSTR |= RCC_AHBPeriph;\r
1187   }\r
1188   else\r
1189   {\r
1190     RCC->AHBRSTR &= ~RCC_AHBPeriph;\r
1191   }\r
1192 }\r
1193 \r
1194 /**\r
1195   * @brief  Forces or releases High Speed APB (APB2) peripheral reset.\r
1196   * @param  RCC_APB2Periph: specifies the APB2 peripheral to reset.\r
1197   *   This parameter can be any combination of the following values:\r
1198   *     @arg RCC_APB2Periph_SYSCFG\r
1199   *     @arg RCC_APB2Periph_TIM9\r
1200   *     @arg RCC_APB2Periph_TIM10\r
1201   *     @arg RCC_APB2Periph_TIM11\r
1202   *     @arg RCC_APB2Periph_ADC1\r
1203   *     @arg RCC_APB2Periph_SPI1\r
1204   *     @arg RCC_APB2Periph_USART1  \r
1205   * @param  NewState: new state of the specified peripheral reset.\r
1206   *         This parameter can be: ENABLE or DISABLE.\r
1207   * @retval None\r
1208   */\r
1209 void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)\r
1210 {\r
1211   /* Check the parameters */\r
1212   assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));\r
1213   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1214 \r
1215   if (NewState != DISABLE)\r
1216   {\r
1217     RCC->APB2RSTR |= RCC_APB2Periph;\r
1218   }\r
1219   else\r
1220   {\r
1221     RCC->APB2RSTR &= ~RCC_APB2Periph;\r
1222   }\r
1223 }\r
1224 \r
1225 /**\r
1226   * @brief  Forces or releases Low Speed APB (APB1) peripheral reset.\r
1227   * @param  RCC_APB1Periph: specifies the APB1 peripheral to reset.\r
1228   *   This parameter can be any combination of the following values:\r
1229   *     @arg RCC_APB1Periph_TIM2\r
1230   *     @arg RCC_APB1Periph_TIM3\r
1231   *     @arg RCC_APB1Periph_TIM4\r
1232   *     @arg RCC_APB1Periph_TIM6\r
1233   *     @arg RCC_APB1Periph_TIM7\r
1234   *     @arg RCC_APB1Periph_LCD\r
1235   *     @arg RCC_APB1Periph_WWDG\r
1236   *     @arg RCC_APB1Periph_SPI2\r
1237   *     @arg RCC_APB1Periph_USART2\r
1238   *     @arg RCC_APB1Periph_USART3\r
1239   *     @arg RCC_APB1Periph_I2C1\r
1240   *     @arg RCC_APB1Periph_I2C2\r
1241   *     @arg RCC_APB1Periph_USB\r
1242   *     @arg RCC_APB1Periph_PWR\r
1243   *     @arg RCC_APB1Periph_DAC\r
1244   *     @arg RCC_APB1Periph_COMP    \r
1245   * @param  NewState: new state of the specified peripheral clock.\r
1246   *         This parameter can be: ENABLE or DISABLE.\r
1247   * @retval None\r
1248   */\r
1249 void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)\r
1250 {\r
1251   /* Check the parameters */\r
1252   assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));\r
1253   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1254 \r
1255   if (NewState != DISABLE)\r
1256   {\r
1257     RCC->APB1RSTR |= RCC_APB1Periph;\r
1258   }\r
1259   else\r
1260   {\r
1261     RCC->APB1RSTR &= ~RCC_APB1Periph;\r
1262   }\r
1263 }\r
1264 \r
1265 /**\r
1266   * @brief  Enables or disables the AHB peripheral clock during SLEEP mode.\r
1267   * @note   - Peripheral clock gating in SLEEP mode can be used to further reduce\r
1268   *           power consumption.\r
1269   *         - After wakeup from SLEEP mode, the peripheral clock is enabled again.\r
1270   *         - By default, all peripheral clocks are enabled during SLEEP mode. \r
1271   * @param  RCC_AHBPeriph: specifies the AHB peripheral to gates its clock.\r
1272   *   This parameter can be any combination of the following values:\r
1273   *     @arg RCC_AHBPeriph_GPIOA\r
1274   *     @arg RCC_AHBPeriph_GPIOB\r
1275   *     @arg RCC_AHBPeriph_GPIOC  \r
1276   *     @arg RCC_AHBPeriph_GPIOD\r
1277   *     @arg RCC_AHBPeriph_GPIOE\r
1278   *     @arg RCC_AHBPeriph_GPIOH\r
1279   *     @arg RCC_AHBPeriph_CRC\r
1280   *     @arg RCC_AHBPeriph_FLITF (has effect only when the Flash memory is in power down mode)  \r
1281   *     @arg RCC_AHBPeriph_SRAM     \r
1282   *     @arg RCC_AHBPeriph_DMA1\r
1283   * @param  NewState: new state of the specified peripheral clock.\r
1284   *         This parameter can be: ENABLE or DISABLE.\r
1285   * @retval None\r
1286   */\r
1287 void RCC_AHBPeriphClockLPModeCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState)\r
1288 {\r
1289   /* Check the parameters */\r
1290   assert_param(IS_RCC_AHB_LPMODE_PERIPH(RCC_AHBPeriph));\r
1291   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1292   \r
1293   if (NewState != DISABLE)\r
1294   {\r
1295     RCC->AHBLPENR |= RCC_AHBPeriph;\r
1296   }\r
1297   else\r
1298   {\r
1299     RCC->AHBLPENR &= ~RCC_AHBPeriph;\r
1300   }\r
1301 }\r
1302 \r
1303 /**\r
1304   * @brief  Enables or disables the APB2 peripheral clock during SLEEP mode.\r
1305   * @note   - Peripheral clock gating in SLEEP mode can be used to further reduce\r
1306   *           power consumption.\r
1307   *         - After wakeup from SLEEP mode, the peripheral clock is enabled again.\r
1308   *         - By default, all peripheral clocks are enabled during SLEEP mode. \r
1309   * @param  RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.\r
1310   *   This parameter can be any combination of the following values:\r
1311   *     @arg RCC_APB2Periph_SYSCFG\r
1312   *     @arg RCC_APB2Periph_TIM9\r
1313   *     @arg RCC_APB2Periph_TIM10\r
1314   *     @arg RCC_APB2Periph_TIM11\r
1315   *     @arg RCC_APB2Periph_ADC1\r
1316   *     @arg RCC_APB2Periph_SPI1\r
1317   *     @arg RCC_APB2Periph_USART1            \r
1318   * @param  NewState: new state of the specified peripheral clock.\r
1319   *         This parameter can be: ENABLE or DISABLE.\r
1320   * @retval None\r
1321   */\r
1322 void RCC_APB2PeriphClockLPModeCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)\r
1323 {\r
1324   /* Check the parameters */\r
1325   assert_param(IS_RCC_APB2_PERIPH(RCC_APB2Periph));\r
1326   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1327   \r
1328   if (NewState != DISABLE)\r
1329   {\r
1330     RCC->APB2LPENR |= RCC_APB2Periph;\r
1331   }\r
1332   else\r
1333   {\r
1334     RCC->APB2LPENR &= ~RCC_APB2Periph;\r
1335   }\r
1336 }\r
1337 \r
1338 /**\r
1339   * @brief  Enables or disables the APB1 peripheral clock during SLEEP mode.\r
1340   * @note   - Peripheral clock gating in SLEEP mode can be used to further reduce\r
1341   *           power consumption.\r
1342   *         - After wakeup from SLEEP mode, the peripheral clock is enabled again.\r
1343   *         - By default, all peripheral clocks are enabled during SLEEP mode.        \r
1344   * @param  RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.\r
1345   *   This parameter can be any combination of the following values:\r
1346   *     @arg RCC_APB1Periph_TIM2\r
1347   *     @arg RCC_APB1Periph_TIM3\r
1348   *     @arg RCC_APB1Periph_TIM4\r
1349   *     @arg RCC_APB1Periph_TIM6\r
1350   *     @arg RCC_APB1Periph_TIM7\r
1351   *     @arg RCC_APB1Periph_LCD\r
1352   *     @arg RCC_APB1Periph_WWDG\r
1353   *     @arg RCC_APB1Periph_SPI2\r
1354   *     @arg RCC_APB1Periph_USART2\r
1355   *     @arg RCC_APB1Periph_USART3\r
1356   *     @arg RCC_APB1Periph_I2C1\r
1357   *     @arg RCC_APB1Periph_I2C2\r
1358   *     @arg RCC_APB1Periph_USB\r
1359   *     @arg RCC_APB1Periph_PWR\r
1360   *     @arg RCC_APB1Periph_DAC\r
1361   *     @arg RCC_APB1Periph_COMP                                \r
1362   * @param  NewState: new state of the specified peripheral clock.\r
1363   *         This parameter can be: ENABLE or DISABLE.\r
1364   * @retval None\r
1365   */\r
1366 void RCC_APB1PeriphClockLPModeCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)\r
1367 {\r
1368   /* Check the parameters */\r
1369   assert_param(IS_RCC_APB1_PERIPH(RCC_APB1Periph));\r
1370   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1371   \r
1372   if (NewState != DISABLE)\r
1373   {\r
1374     RCC->APB1LPENR |= RCC_APB1Periph;\r
1375   }\r
1376   else\r
1377   {\r
1378     RCC->APB1LPENR &= ~RCC_APB1Periph;\r
1379   }\r
1380 }\r
1381 \r
1382 /**\r
1383   * @}\r
1384   */\r
1385 \r
1386 /** @defgroup RCC_Group4 Interrupts and flags management functions\r
1387  *  @brief   Interrupts and flags management functions \r
1388  *\r
1389 @verbatim   \r
1390  ===============================================================================\r
1391                    Interrupts and flags management functions\r
1392  ===============================================================================  \r
1393 \r
1394 @endverbatim\r
1395   * @{\r
1396   */\r
1397 \r
1398 /**\r
1399   * @brief  Enables or disables the specified RCC interrupts.\r
1400   * @note   The CSS interrupt doesn't have an enable bit; once the CSS is enabled\r
1401   *         and if the HSE clock fails, the CSS interrupt occurs and an NMI is\r
1402   *         automatically generated. The NMI will be executed indefinitely, and \r
1403   *         since NMI has higher priority than any other IRQ (and main program)\r
1404   *         the application will be stacked in the NMI ISR unless the CSS interrupt\r
1405   *         pending bit is cleared.\r
1406   * @param  RCC_IT: specifies the RCC interrupt sources to be enabled or disabled.\r
1407   *   This parameter can be any combination of the following values:\r
1408   *     @arg RCC_IT_LSIRDY: LSI ready interrupt\r
1409   *     @arg RCC_IT_LSERDY: LSE ready interrupt\r
1410   *     @arg RCC_IT_HSIRDY: HSI ready interrupt\r
1411   *     @arg RCC_IT_HSERDY: HSE ready interrupt\r
1412   *     @arg RCC_IT_PLLRDY: PLL ready interrupt\r
1413   *     @arg RCC_IT_MSIRDY: MSI ready interrupt\r
1414   * @param  NewState: new state of the specified RCC interrupts.\r
1415   *   This parameter can be: ENABLE or DISABLE.\r
1416   * @retval None\r
1417   */\r
1418 void RCC_ITConfig(uint8_t RCC_IT, FunctionalState NewState)\r
1419 {\r
1420   /* Check the parameters */\r
1421   assert_param(IS_RCC_IT(RCC_IT));\r
1422   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1423   \r
1424   if (NewState != DISABLE)\r
1425   {\r
1426     /* Perform Byte access to RCC_CIR[12:8] bits to enable the selected interrupts */\r
1427     *(__IO uint8_t *) CIR_BYTE2_ADDRESS |= RCC_IT;\r
1428   }\r
1429   else\r
1430   {\r
1431     /* Perform Byte access to RCC_CIR[12:8] bits to disable the selected interrupts */\r
1432     *(__IO uint8_t *) CIR_BYTE2_ADDRESS &= (uint8_t)~RCC_IT;\r
1433   }\r
1434 }\r
1435 \r
1436 /**\r
1437   * @brief  Checks whether the specified RCC flag is set or not.\r
1438   * @param  RCC_FLAG: specifies the flag to check.\r
1439   *   This parameter can be one of the following values:\r
1440   *     @arg RCC_FLAG_HSIRDY: HSI oscillator clock ready\r
1441   *     @arg RCC_FLAG_MSIRDY: MSI oscillator clock ready  \r
1442   *     @arg RCC_FLAG_HSERDY: HSE oscillator clock ready\r
1443   *     @arg RCC_FLAG_PLLRDY: PLL clock ready\r
1444   *     @arg RCC_FLAG_LSERDY: LSE oscillator clock ready\r
1445   *     @arg RCC_FLAG_LSIRDY: LSI oscillator clock ready\r
1446   *     @arg RCC_FLAG_OBLRST: Option Byte Loader (OBL) reset \r
1447   *     @arg RCC_FLAG_PINRST: Pin reset\r
1448   *     @arg RCC_FLAG_PORRST: POR/PDR reset\r
1449   *     @arg RCC_FLAG_SFTRST: Software reset\r
1450   *     @arg RCC_FLAG_IWDGRST: Independent Watchdog reset\r
1451   *     @arg RCC_FLAG_WWDGRST: Window Watchdog reset\r
1452   *     @arg RCC_FLAG_LPWRRST: Low Power reset\r
1453   * @retval The new state of RCC_FLAG (SET or RESET).\r
1454   */\r
1455 FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG)\r
1456 {\r
1457   uint32_t tmp = 0;\r
1458   uint32_t statusreg = 0;\r
1459   FlagStatus bitstatus = RESET;\r
1460 \r
1461   /* Check the parameters */\r
1462   assert_param(IS_RCC_FLAG(RCC_FLAG));\r
1463 \r
1464   /* Get the RCC register index */\r
1465   tmp = RCC_FLAG >> 5;\r
1466 \r
1467   if (tmp == 1)               /* The flag to check is in CR register */\r
1468   {\r
1469     statusreg = RCC->CR;\r
1470   }\r
1471   else          /* The flag to check is in CSR register (tmp == 2) */\r
1472   {\r
1473     statusreg = RCC->CSR;\r
1474   }\r
1475 \r
1476   /* Get the flag position */\r
1477   tmp = RCC_FLAG & FLAG_MASK;\r
1478 \r
1479   if ((statusreg & ((uint32_t)1 << tmp)) != (uint32_t)RESET)\r
1480   {\r
1481     bitstatus = SET;\r
1482   }\r
1483   else\r
1484   {\r
1485     bitstatus = RESET;\r
1486   }\r
1487   /* Return the flag status */\r
1488   return bitstatus;\r
1489 }\r
1490 \r
1491 /**\r
1492   * @brief  Clears the RCC reset flags.\r
1493   *         The reset flags are: RCC_FLAG_OBLRST, RCC_FLAG_PINRST, RCC_FLAG_PORRST, \r
1494   *         RCC_FLAG_SFTRST, RCC_FLAG_IWDGRST, RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST.\r
1495   * @param  None\r
1496   * @retval None\r
1497   */\r
1498 void RCC_ClearFlag(void)\r
1499 {\r
1500   /* Set RMVF bit to clear the reset flags */\r
1501   RCC->CSR |= RCC_CSR_RMVF;\r
1502 }\r
1503 \r
1504 /**\r
1505   * @brief  Checks whether the specified RCC interrupt has occurred or not.\r
1506   * @param  RCC_IT: specifies the RCC interrupt source to check.\r
1507   *   This parameter can be one of the following values:\r
1508   *     @arg RCC_IT_LSIRDY: LSI ready interrupt\r
1509   *     @arg RCC_IT_LSERDY: LSE ready interrupt\r
1510   *     @arg RCC_IT_HSIRDY: HSI ready interrupt\r
1511   *     @arg RCC_IT_HSERDY: HSE ready interrupt\r
1512   *     @arg RCC_IT_PLLRDY: PLL ready interrupt\r
1513   *     @arg RCC_IT_MSIRDY: MSI ready interrupt \r
1514   *     @arg RCC_IT_CSS: Clock Security System interrupt\r
1515   * @retval The new state of RCC_IT (SET or RESET).\r
1516   */\r
1517 ITStatus RCC_GetITStatus(uint8_t RCC_IT)\r
1518 {\r
1519   ITStatus bitstatus = RESET;\r
1520   /* Check the parameters */\r
1521   assert_param(IS_RCC_GET_IT(RCC_IT));\r
1522   \r
1523   /* Check the status of the specified RCC interrupt */\r
1524   if ((RCC->CIR & RCC_IT) != (uint32_t)RESET)\r
1525   {\r
1526     bitstatus = SET;\r
1527   }\r
1528   else\r
1529   {\r
1530     bitstatus = RESET;\r
1531   }\r
1532   /* Return the RCC_IT status */\r
1533   return  bitstatus;\r
1534 }\r
1535 \r
1536 /**\r
1537   * @brief  Clears the RCC's interrupt pending bits.\r
1538   * @param  RCC_IT: specifies the interrupt pending bit to clear.\r
1539   *   This parameter can be any combination of the following values:\r
1540   *     @arg RCC_IT_LSIRDY: LSI ready interrupt\r
1541   *     @arg RCC_IT_LSERDY: LSE ready interrupt\r
1542   *     @arg RCC_IT_HSIRDY: HSI ready interrupt\r
1543   *     @arg RCC_IT_HSERDY: HSE ready interrupt\r
1544   *     @arg RCC_IT_PLLRDY: PLL ready interrupt\r
1545   *     @arg RCC_IT_MSIRDY: MSI ready interrupt  \r
1546   *     @arg RCC_IT_CSS: Clock Security System interrupt\r
1547   * @retval None\r
1548   */\r
1549 void RCC_ClearITPendingBit(uint8_t RCC_IT)\r
1550 {\r
1551   /* Check the parameters */\r
1552   assert_param(IS_RCC_CLEAR_IT(RCC_IT));\r
1553   \r
1554   /* Perform Byte access to RCC_CIR[23:16] bits to clear the selected interrupt\r
1555      pending bits */\r
1556   *(__IO uint8_t *) CIR_BYTE3_ADDRESS = RCC_IT;\r
1557 }\r
1558 \r
1559 /**\r
1560   * @}\r
1561   */\r
1562 \r
1563 /**\r
1564   * @}\r
1565   */\r
1566 \r
1567 /**\r
1568   * @}\r
1569   */\r
1570 \r
1571 /**\r
1572   * @}\r
1573   */\r
1574 \r
1575 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r