]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_STM32F100_Atollic/Simple_Demo_Source/system_stm32f10x.c
Update version number ready to release the FAT file system demo.
[freertos] / FreeRTOS / Demo / CORTEX_STM32F100_Atollic / Simple_Demo_Source / system_stm32f10x.c
1 /**\r
2   ******************************************************************************\r
3   * @file    system_stm32f10x.c\r
4   * @author  MCD Application Team\r
5   * @version V3.4.0\r
6   * @date    10/15/2010\r
7   * @brief   CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.\r
8   ******************************************************************************  \r
9   *\r
10   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
11   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
12   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
13   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
14   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
15   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
16   *\r
17   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>\r
18   ******************************************************************************\r
19   */\r
20 \r
21 /** @addtogroup CMSIS\r
22   * @{\r
23   */\r
24 \r
25 /** @addtogroup stm32f10x_system\r
26   * @{\r
27   */  \r
28   \r
29 /** @addtogroup STM32F10x_System_Private_Includes\r
30   * @{\r
31   */\r
32 \r
33 #include "stm32f10x.h"\r
34 \r
35 /**\r
36   * @}\r
37   */\r
38 \r
39 /** @addtogroup STM32F10x_System_Private_TypesDefinitions\r
40   * @{\r
41   */\r
42 \r
43 /**\r
44   * @}\r
45   */\r
46 \r
47 /** @addtogroup STM32F10x_System_Private_Defines\r
48   * @{\r
49   */\r
50 \r
51 /*!< Uncomment the line corresponding to the desired System clock (SYSCLK)\r
52    frequency (after reset the HSI is used as SYSCLK source)\r
53    \r
54    IMPORTANT NOTE:\r
55    ============== \r
56    1. After each device reset the HSI is used as System clock source.\r
57 \r
58    2. Please make sure that the selected System clock doesn't exceed your device's\r
59       maximum frequency.\r
60       \r
61    3. If none of the define below is enabled, the HSI is used as System clock\r
62     source.\r
63 \r
64    4. The System clock configuration functions provided within this file assume that:\r
65         - For Low, Medium and High density Value line devices an external 8MHz \r
66           crystal is used to drive the System clock.\r
67         - For Low, Medium and High density devices an external 8MHz crystal is\r
68           used to drive the System clock.\r
69         - For Connectivity line devices an external 25MHz crystal is used to drive\r
70           the System clock.\r
71      If you are using different crystal you have to adapt those functions accordingly.\r
72     */\r
73     \r
74 #if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)\r
75 /* #define SYSCLK_FREQ_HSE    HSE_VALUE */\r
76  #define SYSCLK_FREQ_24MHz  24000000\r
77 #else\r
78 /* #define SYSCLK_FREQ_HSE    HSE_VALUE */\r
79 /* #define SYSCLK_FREQ_24MHz  24000000 */ \r
80 /* #define SYSCLK_FREQ_36MHz  36000000 */\r
81 /* #define SYSCLK_FREQ_48MHz  48000000 */\r
82 /* #define SYSCLK_FREQ_56MHz  56000000 */\r
83 #define SYSCLK_FREQ_72MHz  72000000\r
84 #endif\r
85 \r
86 /*!< Uncomment the following line if you need to use external SRAM mounted\r
87      on STM3210E-EVAL board (STM32 High density and XL-density devices) or on \r
88      STM32100E-EVAL board (STM32 High-density value line devices) as data memory */ \r
89 #if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL)\r
90 /* #define DATA_IN_ExtSRAM */\r
91 #endif\r
92 \r
93 /*!< Uncomment the following line if you need to relocate your vector Table in\r
94      Internal SRAM. */ \r
95 /* #define VECT_TAB_SRAM */\r
96 #define VECT_TAB_OFFSET  0x0 /*!< Vector Table base offset field. \r
97                                   This value must be a multiple of 0x100. */\r
98 \r
99 \r
100 /**\r
101   * @}\r
102   */\r
103 \r
104 /** @addtogroup STM32F10x_System_Private_Macros\r
105   * @{\r
106   */\r
107 \r
108 /**\r
109   * @}\r
110   */\r
111 \r
112 /** @addtogroup STM32F10x_System_Private_Variables\r
113   * @{\r
114   */\r
115 \r
116 /*******************************************************************************\r
117 *  Clock Definitions\r
118 *******************************************************************************/\r
119 #ifdef SYSCLK_FREQ_HSE\r
120   uint32_t SystemCoreClock         = SYSCLK_FREQ_HSE;        /*!< System Clock Frequency (Core Clock) */\r
121 #elif defined SYSCLK_FREQ_24MHz\r
122   uint32_t SystemCoreClock         = SYSCLK_FREQ_24MHz;        /*!< System Clock Frequency (Core Clock) */\r
123 #elif defined SYSCLK_FREQ_36MHz\r
124   uint32_t SystemCoreClock         = SYSCLK_FREQ_36MHz;        /*!< System Clock Frequency (Core Clock) */\r
125 #elif defined SYSCLK_FREQ_48MHz\r
126   uint32_t SystemCoreClock         = SYSCLK_FREQ_48MHz;        /*!< System Clock Frequency (Core Clock) */\r
127 #elif defined SYSCLK_FREQ_56MHz\r
128   uint32_t SystemCoreClock         = SYSCLK_FREQ_56MHz;        /*!< System Clock Frequency (Core Clock) */\r
129 #elif defined SYSCLK_FREQ_72MHz\r
130   uint32_t SystemCoreClock         = SYSCLK_FREQ_72MHz;        /*!< System Clock Frequency (Core Clock) */\r
131 #else /*!< HSI Selected as System Clock source */\r
132   uint32_t SystemCoreClock         = HSI_VALUE;        /*!< System Clock Frequency (Core Clock) */\r
133 #endif\r
134 \r
135 __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};\r
136 /**\r
137   * @}\r
138   */\r
139 \r
140 /** @addtogroup STM32F10x_System_Private_FunctionPrototypes\r
141   * @{\r
142   */\r
143 \r
144 static void SetSysClock(void);\r
145 \r
146 #ifdef SYSCLK_FREQ_HSE\r
147   static void SetSysClockToHSE(void);\r
148 #elif defined SYSCLK_FREQ_24MHz\r
149   static void SetSysClockTo24(void);\r
150 #elif defined SYSCLK_FREQ_36MHz\r
151   static void SetSysClockTo36(void);\r
152 #elif defined SYSCLK_FREQ_48MHz\r
153   static void SetSysClockTo48(void);\r
154 #elif defined SYSCLK_FREQ_56MHz\r
155   static void SetSysClockTo56(void);  \r
156 #elif defined SYSCLK_FREQ_72MHz\r
157   static void SetSysClockTo72(void);\r
158 #endif\r
159 \r
160 #ifdef DATA_IN_ExtSRAM\r
161   static void SystemInit_ExtMemCtl(void); \r
162 #endif /* DATA_IN_ExtSRAM */\r
163 \r
164 /**\r
165   * @}\r
166   */\r
167 \r
168 /** @addtogroup STM32F10x_System_Private_Functions\r
169   * @{\r
170   */\r
171 \r
172 /**\r
173   * @brief  Setup the microcontroller system\r
174   *         Initialize the Embedded Flash Interface, the PLL and update the \r
175   *         SystemCoreClock variable.\r
176   * @note   This function should be used only after reset.\r
177   * @param  None\r
178   * @retval None\r
179   */\r
180 void SystemInit (void)\r
181 {\r
182   /* Reset the RCC clock configuration to the default reset state(for debug purpose) */\r
183   /* Set HSION bit */\r
184   RCC->CR |= (uint32_t)0x00000001;\r
185 \r
186   /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */\r
187 #ifndef STM32F10X_CL\r
188   RCC->CFGR &= (uint32_t)0xF8FF0000;\r
189 #else\r
190   RCC->CFGR &= (uint32_t)0xF0FF0000;\r
191 #endif /* STM32F10X_CL */   \r
192   \r
193   /* Reset HSEON, CSSON and PLLON bits */\r
194   RCC->CR &= (uint32_t)0xFEF6FFFF;\r
195 \r
196   /* Reset HSEBYP bit */\r
197   RCC->CR &= (uint32_t)0xFFFBFFFF;\r
198 \r
199   /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */\r
200   RCC->CFGR &= (uint32_t)0xFF80FFFF;\r
201 \r
202 #ifdef STM32F10X_CL\r
203   /* Reset PLL2ON and PLL3ON bits */\r
204   RCC->CR &= (uint32_t)0xEBFFFFFF;\r
205 \r
206   /* Disable all interrupts and clear pending bits  */\r
207   RCC->CIR = 0x00FF0000;\r
208 \r
209   /* Reset CFGR2 register */\r
210   RCC->CFGR2 = 0x00000000;\r
211 #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)\r
212   /* Disable all interrupts and clear pending bits  */\r
213   RCC->CIR = 0x009F0000;\r
214 \r
215   /* Reset CFGR2 register */\r
216   RCC->CFGR2 = 0x00000000;      \r
217 #else\r
218   /* Disable all interrupts and clear pending bits  */\r
219   RCC->CIR = 0x009F0000;\r
220 #endif /* STM32F10X_CL */\r
221     \r
222 #if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL)\r
223   #ifdef DATA_IN_ExtSRAM\r
224     SystemInit_ExtMemCtl(); \r
225   #endif /* DATA_IN_ExtSRAM */\r
226 #endif \r
227 \r
228   /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */\r
229   /* Configure the Flash Latency cycles and enable prefetch buffer */\r
230   SetSysClock();\r
231 \r
232 #ifdef VECT_TAB_SRAM\r
233   SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */\r
234 #else\r
235   SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */\r
236 #endif \r
237 }\r
238 \r
239 /**\r
240   * @brief  Update SystemCoreClock according to Clock Register Values\r
241   * @note   None\r
242   * @param  None\r
243   * @retval None\r
244   */\r
245 void SystemCoreClockUpdate (void)\r
246 {\r
247   uint32_t tmp = 0, pllmull = 0, pllsource = 0;\r
248 \r
249 #ifdef  STM32F10X_CL\r
250   uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = 0, pll2mull = 0;\r
251 #endif /* STM32F10X_CL */\r
252 \r
253 #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)\r
254   uint32_t prediv1factor = 0;\r
255 #endif /* STM32F10X_LD_VL or STM32F10X_MD_VL or STM32F10X_HD_VL */\r
256     \r
257   /* Get SYSCLK source -------------------------------------------------------*/\r
258   tmp = RCC->CFGR & RCC_CFGR_SWS;\r
259   \r
260   switch (tmp)\r
261   {\r
262     case 0x00:  /* HSI used as system clock */\r
263       SystemCoreClock = HSI_VALUE;\r
264       break;\r
265     case 0x04:  /* HSE used as system clock */\r
266       SystemCoreClock = HSE_VALUE;\r
267       break;\r
268     case 0x08:  /* PLL used as system clock */\r
269 \r
270       /* Get PLL clock source and multiplication factor ----------------------*/\r
271       pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;\r
272       pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;\r
273       \r
274 #ifndef STM32F10X_CL      \r
275       pllmull = ( pllmull >> 18) + 2;\r
276       \r
277       if (pllsource == 0x00)\r
278       {\r
279         /* HSI oscillator clock divided by 2 selected as PLL clock entry */\r
280         SystemCoreClock = (HSI_VALUE >> 1) * pllmull;\r
281       }\r
282       else\r
283       {\r
284  #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)\r
285        prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;\r
286        /* HSE oscillator clock selected as PREDIV1 clock entry */\r
287        SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; \r
288  #else\r
289         /* HSE selected as PLL clock entry */\r
290         if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)\r
291         {/* HSE oscillator clock divided by 2 */\r
292           SystemCoreClock = (HSE_VALUE >> 1) * pllmull;\r
293         }\r
294         else\r
295         {\r
296           SystemCoreClock = HSE_VALUE * pllmull;\r
297         }\r
298  #endif\r
299       }\r
300 #else\r
301       pllmull = pllmull >> 18;\r
302       \r
303       if (pllmull != 0x0D)\r
304       {\r
305          pllmull += 2;\r
306       }\r
307       else\r
308       { /* PLL multiplication factor = PLL input clock * 6.5 */\r
309         pllmull = 13 / 2; \r
310       }\r
311             \r
312       if (pllsource == 0x00)\r
313       {\r
314         /* HSI oscillator clock divided by 2 selected as PLL clock entry */\r
315         SystemCoreClock = (HSI_VALUE >> 1) * pllmull;\r
316       }\r
317       else\r
318       {/* PREDIV1 selected as PLL clock entry */\r
319         \r
320         /* Get PREDIV1 clock source and division factor */\r
321         prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;\r
322         prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;\r
323         \r
324         if (prediv1source == 0)\r
325         { \r
326           /* HSE oscillator clock selected as PREDIV1 clock entry */\r
327           SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;          \r
328         }\r
329         else\r
330         {/* PLL2 clock selected as PREDIV1 clock entry */\r
331           \r
332           /* Get PREDIV2 division factor and PLL2 multiplication factor */\r
333           prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4) + 1;\r
334           pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8 ) + 2; \r
335           SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;                         \r
336         }\r
337       }\r
338 #endif /* STM32F10X_CL */ \r
339       break;\r
340 \r
341     default:\r
342       SystemCoreClock = HSI_VALUE;\r
343       break;\r
344   }\r
345   \r
346   /* Compute HCLK clock frequency ----------------*/\r
347   /* Get HCLK prescaler */\r
348   tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];\r
349   /* HCLK clock frequency */\r
350   SystemCoreClock >>= tmp;  \r
351 }\r
352 \r
353 /**\r
354   * @brief  Configures the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers.\r
355   * @param  None\r
356   * @retval None\r
357   */\r
358 static void SetSysClock(void)\r
359 {\r
360 #ifdef SYSCLK_FREQ_HSE\r
361   SetSysClockToHSE();\r
362 #elif defined SYSCLK_FREQ_24MHz\r
363   SetSysClockTo24();\r
364 #elif defined SYSCLK_FREQ_36MHz\r
365   SetSysClockTo36();\r
366 #elif defined SYSCLK_FREQ_48MHz\r
367   SetSysClockTo48();\r
368 #elif defined SYSCLK_FREQ_56MHz\r
369   SetSysClockTo56();  \r
370 #elif defined SYSCLK_FREQ_72MHz\r
371   SetSysClockTo72();\r
372 #endif\r
373  \r
374  /* If none of the define above is enabled, the HSI is used as System clock\r
375     source (default after reset) */ \r
376 }\r
377 \r
378 /**\r
379   * @brief  Setup the external memory controller. Called in startup_stm32f10x.s \r
380   *          before jump to __main\r
381   * @param  None\r
382   * @retval None\r
383   */ \r
384 #ifdef DATA_IN_ExtSRAM\r
385 /**\r
386   * @brief  Setup the external memory controller. \r
387   *         Called in startup_stm32f10x_xx.s/.c before jump to main.\r
388   *           This function configures the external SRAM mounted on STM3210E-EVAL\r
389   *         board (STM32 High density devices). This SRAM will be used as program\r
390   *         data memory (including heap and stack).\r
391   * @param  None\r
392   * @retval None\r
393   */ \r
394 void SystemInit_ExtMemCtl(void) \r
395 {\r
396 /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is \r
397   required, then adjust the Register Addresses */\r
398 \r
399   /* Enable FSMC clock */\r
400   RCC->AHBENR = 0x00000114;\r
401   \r
402   /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */  \r
403   RCC->APB2ENR = 0x000001E0;\r
404   \r
405 /* ---------------  SRAM Data lines, NOE and NWE configuration ---------------*/\r
406 /*----------------  SRAM Address lines configuration -------------------------*/\r
407 /*----------------  NOE and NWE configuration --------------------------------*/  \r
408 /*----------------  NE3 configuration ----------------------------------------*/\r
409 /*----------------  NBL0, NBL1 configuration ---------------------------------*/\r
410   \r
411   GPIOD->CRL = 0x44BB44BB;  \r
412   GPIOD->CRH = 0xBBBBBBBB;\r
413 \r
414   GPIOE->CRL = 0xB44444BB;  \r
415   GPIOE->CRH = 0xBBBBBBBB;\r
416 \r
417   GPIOF->CRL = 0x44BBBBBB;  \r
418   GPIOF->CRH = 0xBBBB4444;\r
419 \r
420   GPIOG->CRL = 0x44BBBBBB;  \r
421   GPIOG->CRH = 0x44444B44;\r
422    \r
423 /*----------------  FSMC Configuration ---------------------------------------*/  \r
424 /*----------------  Enable FSMC Bank1_SRAM Bank ------------------------------*/\r
425   \r
426   FSMC_Bank1->BTCR[4] = 0x00001011;\r
427   FSMC_Bank1->BTCR[5] = 0x00000200;\r
428 }\r
429 #endif /* DATA_IN_ExtSRAM */\r
430 \r
431 #ifdef SYSCLK_FREQ_HSE\r
432 /**\r
433   * @brief  Selects HSE as System clock source and configure HCLK, PCLK2\r
434   *          and PCLK1 prescalers.\r
435   * @note   This function should be used only after reset.\r
436   * @param  None\r
437   * @retval None\r
438   */\r
439 static void SetSysClockToHSE(void)\r
440 {\r
441   __IO uint32_t StartUpCounter = 0, HSEStatus = 0;\r
442   \r
443   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/    \r
444   /* Enable HSE */    \r
445   RCC->CR |= ((uint32_t)RCC_CR_HSEON);\r
446  \r
447   /* Wait till HSE is ready and if Time out is reached exit */\r
448   do\r
449   {\r
450     HSEStatus = RCC->CR & RCC_CR_HSERDY;\r
451     StartUpCounter++;  \r
452   } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));\r
453 \r
454   if ((RCC->CR & RCC_CR_HSERDY) != RESET)\r
455   {\r
456     HSEStatus = (uint32_t)0x01;\r
457   }\r
458   else\r
459   {\r
460     HSEStatus = (uint32_t)0x00;\r
461   }  \r
462 \r
463   if (HSEStatus == (uint32_t)0x01)\r
464   {\r
465 \r
466 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL\r
467     /* Enable Prefetch Buffer */\r
468     FLASH->ACR |= FLASH_ACR_PRFTBE;\r
469 \r
470     /* Flash 0 wait state */\r
471     FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);\r
472 \r
473 #ifndef STM32F10X_CL\r
474     FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_0;\r
475 #else\r
476     if (HSE_VALUE <= 24000000)\r
477         {\r
478       FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_0;\r
479         }\r
480         else\r
481         {\r
482       FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1;\r
483         }\r
484 #endif /* STM32F10X_CL */\r
485 #endif\r
486  \r
487     /* HCLK = SYSCLK */\r
488     RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;\r
489       \r
490     /* PCLK2 = HCLK */\r
491     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;\r
492     \r
493     /* PCLK1 = HCLK */\r
494     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;\r
495     \r
496     /* Select HSE as system clock source */\r
497     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));\r
498     RCC->CFGR |= (uint32_t)RCC_CFGR_SW_HSE;    \r
499 \r
500     /* Wait till HSE is used as system clock source */\r
501     while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x04)\r
502     {\r
503     }\r
504   }\r
505   else\r
506   { /* If HSE fails to start-up, the application will have wrong clock \r
507          configuration. User can add here some code to deal with this error */\r
508   }  \r
509 }\r
510 #elif defined SYSCLK_FREQ_24MHz\r
511 /**\r
512   * @brief  Sets System clock frequency to 24MHz and configure HCLK, PCLK2 \r
513   *          and PCLK1 prescalers.\r
514   * @note   This function should be used only after reset.\r
515   * @param  None\r
516   * @retval None\r
517   */\r
518 static void SetSysClockTo24(void)\r
519 {\r
520   __IO uint32_t StartUpCounter = 0, HSEStatus = 0;\r
521   \r
522   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/    \r
523   /* Enable HSE */    \r
524   RCC->CR |= ((uint32_t)RCC_CR_HSEON);\r
525  \r
526   /* Wait till HSE is ready and if Time out is reached exit */\r
527   do\r
528   {\r
529     HSEStatus = RCC->CR & RCC_CR_HSERDY;\r
530     StartUpCounter++;  \r
531   } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));\r
532 \r
533   if ((RCC->CR & RCC_CR_HSERDY) != RESET)\r
534   {\r
535     HSEStatus = (uint32_t)0x01;\r
536   }\r
537   else\r
538   {\r
539     HSEStatus = (uint32_t)0x00;\r
540   }  \r
541 \r
542   if (HSEStatus == (uint32_t)0x01)\r
543   {\r
544 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL \r
545     /* Enable Prefetch Buffer */\r
546     FLASH->ACR |= FLASH_ACR_PRFTBE;\r
547 \r
548     /* Flash 0 wait state */\r
549     FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);\r
550     FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_0;    \r
551 #endif\r
552  \r
553     /* HCLK = SYSCLK */\r
554     RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;\r
555       \r
556     /* PCLK2 = HCLK */\r
557     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;\r
558     \r
559     /* PCLK1 = HCLK */\r
560     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;\r
561     \r
562 #ifdef STM32F10X_CL\r
563     /* Configure PLLs ------------------------------------------------------*/\r
564     /* PLL configuration: PLLCLK = PREDIV1 * 6 = 24 MHz */ \r
565     RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);\r
566     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | \r
567                             RCC_CFGR_PLLMULL6); \r
568 \r
569     /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */\r
570     /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 10 = 4 MHz */       \r
571     RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |\r
572                               RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);\r
573     RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |\r
574                              RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10);\r
575   \r
576     /* Enable PLL2 */\r
577     RCC->CR |= RCC_CR_PLL2ON;\r
578     /* Wait till PLL2 is ready */\r
579     while((RCC->CR & RCC_CR_PLL2RDY) == 0)\r
580     {\r
581     }   \r
582 #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)\r
583     /*  PLL configuration:  = (HSE / 2) * 6 = 24 MHz */\r
584     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));\r
585     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1_Div2 | RCC_CFGR_PLLMULL6);\r
586 #else    \r
587     /*  PLL configuration:  = (HSE / 2) * 6 = 24 MHz */\r
588     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));\r
589     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL6);\r
590 #endif /* STM32F10X_CL */\r
591 \r
592     /* Enable PLL */\r
593     RCC->CR |= RCC_CR_PLLON;\r
594 \r
595     /* Wait till PLL is ready */\r
596     while((RCC->CR & RCC_CR_PLLRDY) == 0)\r
597     {\r
598     }\r
599 \r
600     /* Select PLL as system clock source */\r
601     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));\r
602     RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;    \r
603 \r
604     /* Wait till PLL is used as system clock source */\r
605     while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)\r
606     {\r
607     }\r
608   }\r
609   else\r
610   { /* If HSE fails to start-up, the application will have wrong clock \r
611          configuration. User can add here some code to deal with this error */\r
612   } \r
613 }\r
614 #elif defined SYSCLK_FREQ_36MHz\r
615 /**\r
616   * @brief  Sets System clock frequency to 36MHz and configure HCLK, PCLK2 \r
617   *          and PCLK1 prescalers. \r
618   * @note   This function should be used only after reset.\r
619   * @param  None\r
620   * @retval None\r
621   */\r
622 static void SetSysClockTo36(void)\r
623 {\r
624   __IO uint32_t StartUpCounter = 0, HSEStatus = 0;\r
625   \r
626   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/    \r
627   /* Enable HSE */    \r
628   RCC->CR |= ((uint32_t)RCC_CR_HSEON);\r
629  \r
630   /* Wait till HSE is ready and if Time out is reached exit */\r
631   do\r
632   {\r
633     HSEStatus = RCC->CR & RCC_CR_HSERDY;\r
634     StartUpCounter++;  \r
635   } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));\r
636 \r
637   if ((RCC->CR & RCC_CR_HSERDY) != RESET)\r
638   {\r
639     HSEStatus = (uint32_t)0x01;\r
640   }\r
641   else\r
642   {\r
643     HSEStatus = (uint32_t)0x00;\r
644   }  \r
645 \r
646   if (HSEStatus == (uint32_t)0x01)\r
647   {\r
648     /* Enable Prefetch Buffer */\r
649     FLASH->ACR |= FLASH_ACR_PRFTBE;\r
650 \r
651     /* Flash 1 wait state */\r
652     FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);\r
653     FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1;    \r
654  \r
655     /* HCLK = SYSCLK */\r
656     RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;\r
657       \r
658     /* PCLK2 = HCLK */\r
659     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;\r
660     \r
661     /* PCLK1 = HCLK */\r
662     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV1;\r
663     \r
664 #ifdef STM32F10X_CL\r
665     /* Configure PLLs ------------------------------------------------------*/\r
666     \r
667     /* PLL configuration: PLLCLK = PREDIV1 * 9 = 36 MHz */ \r
668     RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);\r
669     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | \r
670                             RCC_CFGR_PLLMULL9); \r
671 \r
672         /*!< PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */\r
673     /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 10 = 4 MHz */\r
674         \r
675     RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |\r
676                               RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);\r
677     RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |\r
678                              RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV10);\r
679   \r
680     /* Enable PLL2 */\r
681     RCC->CR |= RCC_CR_PLL2ON;\r
682     /* Wait till PLL2 is ready */\r
683     while((RCC->CR & RCC_CR_PLL2RDY) == 0)\r
684     {\r
685     }\r
686     \r
687 #else    \r
688     /*  PLL configuration: PLLCLK = (HSE / 2) * 9 = 36 MHz */\r
689     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));\r
690     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLXTPRE_HSE_Div2 | RCC_CFGR_PLLMULL9);\r
691 #endif /* STM32F10X_CL */\r
692 \r
693     /* Enable PLL */\r
694     RCC->CR |= RCC_CR_PLLON;\r
695 \r
696     /* Wait till PLL is ready */\r
697     while((RCC->CR & RCC_CR_PLLRDY) == 0)\r
698     {\r
699     }\r
700 \r
701     /* Select PLL as system clock source */\r
702     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));\r
703     RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;    \r
704 \r
705     /* Wait till PLL is used as system clock source */\r
706     while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)\r
707     {\r
708     }\r
709   }\r
710   else\r
711   { /* If HSE fails to start-up, the application will have wrong clock \r
712          configuration. User can add here some code to deal with this error */\r
713   } \r
714 }\r
715 #elif defined SYSCLK_FREQ_48MHz\r
716 /**\r
717   * @brief  Sets System clock frequency to 48MHz and configure HCLK, PCLK2 \r
718   *          and PCLK1 prescalers. \r
719   * @note   This function should be used only after reset.\r
720   * @param  None\r
721   * @retval None\r
722   */\r
723 static void SetSysClockTo48(void)\r
724 {\r
725   __IO uint32_t StartUpCounter = 0, HSEStatus = 0;\r
726   \r
727   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/    \r
728   /* Enable HSE */    \r
729   RCC->CR |= ((uint32_t)RCC_CR_HSEON);\r
730  \r
731   /* Wait till HSE is ready and if Time out is reached exit */\r
732   do\r
733   {\r
734     HSEStatus = RCC->CR & RCC_CR_HSERDY;\r
735     StartUpCounter++;  \r
736   } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));\r
737 \r
738   if ((RCC->CR & RCC_CR_HSERDY) != RESET)\r
739   {\r
740     HSEStatus = (uint32_t)0x01;\r
741   }\r
742   else\r
743   {\r
744     HSEStatus = (uint32_t)0x00;\r
745   }  \r
746 \r
747   if (HSEStatus == (uint32_t)0x01)\r
748   {\r
749     /* Enable Prefetch Buffer */\r
750     FLASH->ACR |= FLASH_ACR_PRFTBE;\r
751 \r
752     /* Flash 1 wait state */\r
753     FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);\r
754     FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_1;    \r
755  \r
756     /* HCLK = SYSCLK */\r
757     RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;\r
758       \r
759     /* PCLK2 = HCLK */\r
760     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;\r
761     \r
762     /* PCLK1 = HCLK */\r
763     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;\r
764     \r
765 #ifdef STM32F10X_CL\r
766     /* Configure PLLs ------------------------------------------------------*/\r
767     /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */\r
768     /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */\r
769         \r
770     RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |\r
771                               RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);\r
772     RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |\r
773                              RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);\r
774   \r
775     /* Enable PLL2 */\r
776     RCC->CR |= RCC_CR_PLL2ON;\r
777     /* Wait till PLL2 is ready */\r
778     while((RCC->CR & RCC_CR_PLL2RDY) == 0)\r
779     {\r
780     }\r
781     \r
782    \r
783     /* PLL configuration: PLLCLK = PREDIV1 * 6 = 48 MHz */ \r
784     RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);\r
785     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | \r
786                             RCC_CFGR_PLLMULL6); \r
787 #else    \r
788     /*  PLL configuration: PLLCLK = HSE * 6 = 48 MHz */\r
789     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));\r
790     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL6);\r
791 #endif /* STM32F10X_CL */\r
792 \r
793     /* Enable PLL */\r
794     RCC->CR |= RCC_CR_PLLON;\r
795 \r
796     /* Wait till PLL is ready */\r
797     while((RCC->CR & RCC_CR_PLLRDY) == 0)\r
798     {\r
799     }\r
800 \r
801     /* Select PLL as system clock source */\r
802     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));\r
803     RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;    \r
804 \r
805     /* Wait till PLL is used as system clock source */\r
806     while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)\r
807     {\r
808     }\r
809   }\r
810   else\r
811   { /* If HSE fails to start-up, the application will have wrong clock \r
812          configuration. User can add here some code to deal with this error */\r
813   } \r
814 }\r
815 \r
816 #elif defined SYSCLK_FREQ_56MHz\r
817 /**\r
818   * @brief  Sets System clock frequency to 56MHz and configure HCLK, PCLK2 \r
819   *          and PCLK1 prescalers. \r
820   * @note   This function should be used only after reset.\r
821   * @param  None\r
822   * @retval None\r
823   */\r
824 static void SetSysClockTo56(void)\r
825 {\r
826   __IO uint32_t StartUpCounter = 0, HSEStatus = 0;\r
827   \r
828   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/   \r
829   /* Enable HSE */    \r
830   RCC->CR |= ((uint32_t)RCC_CR_HSEON);\r
831  \r
832   /* Wait till HSE is ready and if Time out is reached exit */\r
833   do\r
834   {\r
835     HSEStatus = RCC->CR & RCC_CR_HSERDY;\r
836     StartUpCounter++;  \r
837   } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));\r
838 \r
839   if ((RCC->CR & RCC_CR_HSERDY) != RESET)\r
840   {\r
841     HSEStatus = (uint32_t)0x01;\r
842   }\r
843   else\r
844   {\r
845     HSEStatus = (uint32_t)0x00;\r
846   }  \r
847 \r
848   if (HSEStatus == (uint32_t)0x01)\r
849   {\r
850     /* Enable Prefetch Buffer */\r
851     FLASH->ACR |= FLASH_ACR_PRFTBE;\r
852 \r
853     /* Flash 2 wait state */\r
854     FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);\r
855     FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_2;    \r
856  \r
857     /* HCLK = SYSCLK */\r
858     RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;\r
859       \r
860     /* PCLK2 = HCLK */\r
861     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;\r
862     \r
863     /* PCLK1 = HCLK */\r
864     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;\r
865 \r
866 #ifdef STM32F10X_CL\r
867     /* Configure PLLs ------------------------------------------------------*/\r
868     /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */\r
869     /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */\r
870         \r
871     RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |\r
872                               RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);\r
873     RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |\r
874                              RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);\r
875   \r
876     /* Enable PLL2 */\r
877     RCC->CR |= RCC_CR_PLL2ON;\r
878     /* Wait till PLL2 is ready */\r
879     while((RCC->CR & RCC_CR_PLL2RDY) == 0)\r
880     {\r
881     }\r
882     \r
883    \r
884     /* PLL configuration: PLLCLK = PREDIV1 * 7 = 56 MHz */ \r
885     RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);\r
886     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | \r
887                             RCC_CFGR_PLLMULL7); \r
888 #else     \r
889     /* PLL configuration: PLLCLK = HSE * 7 = 56 MHz */\r
890     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));\r
891     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL7);\r
892 \r
893 #endif /* STM32F10X_CL */\r
894 \r
895     /* Enable PLL */\r
896     RCC->CR |= RCC_CR_PLLON;\r
897 \r
898     /* Wait till PLL is ready */\r
899     while((RCC->CR & RCC_CR_PLLRDY) == 0)\r
900     {\r
901     }\r
902 \r
903     /* Select PLL as system clock source */\r
904     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));\r
905     RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;    \r
906 \r
907     /* Wait till PLL is used as system clock source */\r
908     while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)\r
909     {\r
910     }\r
911   }\r
912   else\r
913   { /* If HSE fails to start-up, the application will have wrong clock \r
914          configuration. User can add here some code to deal with this error */\r
915   } \r
916 }\r
917 \r
918 #elif defined SYSCLK_FREQ_72MHz\r
919 /**\r
920   * @brief  Sets System clock frequency to 72MHz and configure HCLK, PCLK2 \r
921   *          and PCLK1 prescalers. \r
922   * @note   This function should be used only after reset.\r
923   * @param  None\r
924   * @retval None\r
925   */\r
926 static void SetSysClockTo72(void)\r
927 {\r
928   __IO uint32_t StartUpCounter = 0, HSEStatus = 0;\r
929   \r
930   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/    \r
931   /* Enable HSE */    \r
932   RCC->CR |= ((uint32_t)RCC_CR_HSEON);\r
933  \r
934   /* Wait till HSE is ready and if Time out is reached exit */\r
935   do\r
936   {\r
937     HSEStatus = RCC->CR & RCC_CR_HSERDY;\r
938     StartUpCounter++;  \r
939   } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));\r
940 \r
941   if ((RCC->CR & RCC_CR_HSERDY) != RESET)\r
942   {\r
943     HSEStatus = (uint32_t)0x01;\r
944   }\r
945   else\r
946   {\r
947     HSEStatus = (uint32_t)0x00;\r
948   }  \r
949 \r
950   if (HSEStatus == (uint32_t)0x01)\r
951   {\r
952     /* Enable Prefetch Buffer */\r
953     FLASH->ACR |= FLASH_ACR_PRFTBE;\r
954 \r
955     /* Flash 2 wait state */\r
956     FLASH->ACR &= (uint32_t)((uint32_t)~FLASH_ACR_LATENCY);\r
957     FLASH->ACR |= (uint32_t)FLASH_ACR_LATENCY_2;    \r
958 \r
959  \r
960     /* HCLK = SYSCLK */\r
961     RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;\r
962       \r
963     /* PCLK2 = HCLK */\r
964     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;\r
965     \r
966     /* PCLK1 = HCLK */\r
967     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;\r
968 \r
969 #ifdef STM32F10X_CL\r
970     /* Configure PLLs ------------------------------------------------------*/\r
971     /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */\r
972     /* PREDIV1 configuration: PREDIV1CLK = PLL2 / 5 = 8 MHz */\r
973         \r
974     RCC->CFGR2 &= (uint32_t)~(RCC_CFGR2_PREDIV2 | RCC_CFGR2_PLL2MUL |\r
975                               RCC_CFGR2_PREDIV1 | RCC_CFGR2_PREDIV1SRC);\r
976     RCC->CFGR2 |= (uint32_t)(RCC_CFGR2_PREDIV2_DIV5 | RCC_CFGR2_PLL2MUL8 |\r
977                              RCC_CFGR2_PREDIV1SRC_PLL2 | RCC_CFGR2_PREDIV1_DIV5);\r
978   \r
979     /* Enable PLL2 */\r
980     RCC->CR |= RCC_CR_PLL2ON;\r
981     /* Wait till PLL2 is ready */\r
982     while((RCC->CR & RCC_CR_PLL2RDY) == 0)\r
983     {\r
984     }\r
985     \r
986    \r
987     /* PLL configuration: PLLCLK = PREDIV1 * 9 = 72 MHz */ \r
988     RCC->CFGR &= (uint32_t)~(RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | RCC_CFGR_PLLMULL);\r
989     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLSRC_PREDIV1 | \r
990                             RCC_CFGR_PLLMULL9); \r
991 #else    \r
992     /*  PLL configuration: PLLCLK = HSE * 9 = 72 MHz */\r
993     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE |\r
994                                         RCC_CFGR_PLLMULL));\r
995     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9);\r
996 #endif /* STM32F10X_CL */\r
997 \r
998     /* Enable PLL */\r
999     RCC->CR |= RCC_CR_PLLON;\r
1000 \r
1001     /* Wait till PLL is ready */\r
1002     while((RCC->CR & RCC_CR_PLLRDY) == 0)\r
1003     {\r
1004     }\r
1005     \r
1006     /* Select PLL as system clock source */\r
1007     RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));\r
1008     RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;    \r
1009 \r
1010     /* Wait till PLL is used as system clock source */\r
1011     while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)0x08)\r
1012     {\r
1013     }\r
1014   }\r
1015   else\r
1016   { /* If HSE fails to start-up, the application will have wrong clock \r
1017          configuration. User can add here some code to deal with this error */\r
1018   }\r
1019 }\r
1020 #endif\r
1021 \r
1022 /**\r
1023   * @}\r
1024   */\r
1025 \r
1026 /**\r
1027   * @}\r
1028   */\r
1029   \r
1030 /**\r
1031   * @}\r
1032   */    \r
1033 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r