STM32F10x_StdPeriph_Examples/RCC/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    RCC/main.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main program body.
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "main.h"
00023 
00024 /** @addtogroup STM32F10x_StdPeriph_Examples
00025   * @{
00026   */
00027 
00028 
00029 /** @addtogroup RCC_Example
00030   * @{
00031   */ 
00032 
00033 /* Private typedef -----------------------------------------------------------*/
00034 /* Private define ------------------------------------------------------------*/
00035 #define DELAY_COUNT    0x3FFFF
00036 
00037 /* Private macro -------------------------------------------------------------*/
00038 /* Private variables ---------------------------------------------------------*/
00039 GPIO_InitTypeDef GPIO_InitStructure;
00040 RCC_ClocksTypeDef RCC_ClockFreq;
00041 ErrorStatus HSEStartUpStatus;
00042 
00043 /* Private function prototypes -----------------------------------------------*/
00044 void NVIC_Configuration(void);
00045 void Delay(__IO uint32_t nCount);
00046 
00047 void SetSysClock(void);
00048 #ifdef SYSCLK_HSE
00049   void SetSysClockToHSE(void);
00050 #elif defined SYSCLK_FREQ_24MHz
00051   void SetSysClockTo24(void);
00052 #elif defined SYSCLK_FREQ_36MHz
00053   void SetSysClockTo36(void);
00054 #elif defined SYSCLK_FREQ_48MHz
00055   void SetSysClockTo48(void);
00056 #elif defined SYSCLK_FREQ_56MHz
00057   void SetSysClockTo56(void);  
00058 #elif defined SYSCLK_FREQ_72MHz
00059   void SetSysClockTo72(void);
00060 #endif
00061 
00062 /* Private functions ---------------------------------------------------------*/
00063 
00064 /**
00065   * @brief  Main program.
00066   * @param  None
00067   * @retval None
00068   */
00069 int main(void)
00070 {
00071   /*!< At this stage the microcontroller clock setting is already configured, 
00072        this is done through SystemInit() function which is called from startup
00073        file (startup_stm32f10x_xx.s) before to branch to application main.
00074        To reconfigure the default setting of SystemInit() function, refer to
00075        system_stm32f10x.c file
00076      */     
00077        
00078   /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */
00079   SetSysClock();
00080 
00081   /* This function fills the RCC_ClockFreq structure with the current
00082      frequencies of different on chip clocks (for debug purpose) */
00083   RCC_GetClocksFreq(&RCC_ClockFreq);
00084 
00085   /* Enable Clock Security System(CSS): this will generate an NMI exception
00086      when HSE clock fails */
00087   RCC_ClockSecuritySystemCmd(ENABLE);
00088      
00089   /* NVIC configuration ------------------------------------------------------*/
00090   NVIC_Configuration();
00091  
00092   /* Initialize Leds mounted on STM3210X-EVAL board --------------------------*/
00093   STM_EVAL_LEDInit(LED1);
00094   STM_EVAL_LEDInit(LED2);
00095   STM_EVAL_LEDInit(LED3);
00096   STM_EVAL_LEDInit(LED4);
00097 
00098   /* Output HSE clock on MCO pin ---------------------------------------------*/
00099   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
00100 
00101   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
00102   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00103   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00104   GPIO_Init(GPIOA, &GPIO_InitStructure);
00105   RCC_MCOConfig(RCC_MCO_HSE);
00106   
00107   while (1)
00108   {
00109     /* Toggle LED1 */
00110     STM_EVAL_LEDToggle(LED1);
00111     /* Insert delay */
00112     Delay(DELAY_COUNT);
00113 
00114     /* Toggle LED2 */
00115     STM_EVAL_LEDToggle(LED2);
00116         /* Insert delay */
00117     Delay(DELAY_COUNT);
00118 
00119     /* Toggle LED3 */
00120     STM_EVAL_LEDToggle(LED3);
00121     /* Insert delay */
00122     Delay(DELAY_COUNT);
00123 
00124     /* Toggle LED4 */
00125     STM_EVAL_LEDToggle(LED4);
00126     /* Insert a delay */
00127     Delay(DELAY_COUNT);
00128   }
00129 }
00130 
00131 /**
00132   * @brief  Configures the System clock frequency, HCLK, PCLK2 and PCLK1
00133   *   prescalers.
00134   * @param  None
00135   * @retval None
00136   */
00137 void SetSysClock(void)
00138 {    
00139 /* The System clock configuration functions defined below assume that:
00140         - For Low, Medium and High density devices an external 8MHz crystal is
00141           used to drive the System clock.
00142         - For Connectivity line devices an external 25MHz crystal is used to drive
00143           the System clock.
00144      If you are using different crystal you have to adapt those functions accordingly.*/
00145 
00146 #if defined SYSCLK_HSE
00147   SetSysClockToHSE();
00148 #elif defined SYSCLK_FREQ_24MHz
00149   SetSysClockTo24();  
00150 #elif defined SYSCLK_FREQ_36MHz
00151   SetSysClockTo36();
00152 #elif defined SYSCLK_FREQ_48MHz
00153   SetSysClockTo48();
00154 #elif defined SYSCLK_FREQ_56MHz
00155   SetSysClockTo56(); 
00156 #elif defined SYSCLK_FREQ_72MHz
00157   SetSysClockTo72();
00158 #endif
00159  
00160  /* If none of the define above is enabled, the HSI is used as System clock
00161     source (default after reset) */ 
00162 }
00163 
00164 /**
00165   * @brief  Selects HSE as System clock source and configure HCLK, PCLK2
00166   *   and PCLK1 prescalers. 
00167   * @param  None
00168   * @retval None
00169   */
00170 void SetSysClockToHSE(void)
00171 {
00172   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/   
00173   /* RCC system reset(for debug purpose) */
00174   RCC_DeInit();
00175 
00176   /* Enable HSE */
00177   RCC_HSEConfig(RCC_HSE_ON);
00178 
00179   /* Wait till HSE is ready */
00180   HSEStartUpStatus = RCC_WaitForHSEStartUp();
00181 
00182   if (HSEStartUpStatus == SUCCESS)
00183   {
00184 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL
00185     /* Enable Prefetch Buffer */
00186     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
00187 
00188 #ifndef STM32F10X_CL
00189     /* Flash 0 wait state */
00190     FLASH_SetLatency(FLASH_Latency_0);
00191 #else
00192     if (HSE_Value <= 24000000)
00193         {
00194       /* Flash 0 wait state */
00195       FLASH_SetLatency(FLASH_Latency_0);
00196         }
00197         else
00198         {
00199       /* Flash 1 wait state */
00200       FLASH_SetLatency(FLASH_Latency_1);
00201         }
00202 #endif /* STM32F10X_CL */
00203 #endif /* STM32F10X_LD_VL && STM32F10X_MD_VL */
00204  
00205     /* HCLK = SYSCLK */
00206     RCC_HCLKConfig(RCC_SYSCLK_Div1); 
00207   
00208     /* PCLK2 = HCLK */
00209     RCC_PCLK2Config(RCC_HCLK_Div1); 
00210 
00211     /* PCLK1 = HCLK */
00212     RCC_PCLK1Config(RCC_HCLK_Div1);
00213 
00214     /* Select HSE as system clock source */
00215     RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
00216 
00217     /* Wait till PLL is used as system clock source */
00218     while (RCC_GetSYSCLKSource() != 0x04)
00219     {
00220     }
00221   }
00222   else
00223   { /* If HSE fails to start-up, the application will have wrong clock configuration.
00224        User can add here some code to deal with this error */    
00225 
00226     /* Go to infinite loop */
00227     while (1)
00228     {
00229     }
00230   }
00231 }
00232 
00233 /**
00234   * @brief  Sets System clock frequency to 24MHz and configure HCLK, PCLK2 
00235   *   and PCLK1 prescalers. 
00236   * @param  None
00237   * @retval None
00238   */
00239 void SetSysClockTo24(void)
00240 {
00241   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/   
00242   /* RCC system reset(for debug purpose) */
00243   RCC_DeInit();
00244 
00245   /* Enable HSE */
00246   RCC_HSEConfig(RCC_HSE_ON);
00247 
00248   /* Wait till HSE is ready */
00249   HSEStartUpStatus = RCC_WaitForHSEStartUp();
00250 
00251   if (HSEStartUpStatus == SUCCESS)
00252   {
00253 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL
00254     /* Enable Prefetch Buffer */
00255     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
00256 
00257     /* Flash 0 wait state */
00258     FLASH_SetLatency(FLASH_Latency_0);
00259 #endif /* STM32F10X_LD_VL && STM32F10X_MD_VL */
00260  
00261     /* HCLK = SYSCLK */
00262     RCC_HCLKConfig(RCC_SYSCLK_Div1); 
00263   
00264     /* PCLK2 = HCLK */
00265     RCC_PCLK2Config(RCC_HCLK_Div1); 
00266 
00267     /* PCLK1 = HCLK */
00268     RCC_PCLK1Config(RCC_HCLK_Div1);
00269 
00270 #ifdef STM32F10X_CL
00271     /* Configure PLLs *********************************************************/
00272     /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
00273     RCC_PREDIV2Config(RCC_PREDIV2_Div5);
00274     RCC_PLL2Config(RCC_PLL2Mul_8);
00275 
00276     /* Enable PLL2 */
00277     RCC_PLL2Cmd(ENABLE);
00278 
00279     /* Wait till PLL2 is ready */
00280     while (RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET)
00281     {}
00282 
00283     /* PLL configuration: PLLCLK = (PLL2 / 10) * 6 = 24 MHz */ 
00284     RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2, RCC_PREDIV1_Div10);
00285     RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_6);
00286 #elif defined STM32F10X_LD_VL || defined STM32F10X_MD_VL || defined STM32F10X_HD_VL 
00287     /* PLLCLK = (8MHz/2) * 6 = 24 MHz */
00288     RCC_PREDIV1Config(RCC_PREDIV1_Source_HSE, RCC_PREDIV1_Div2);
00289     RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_6);
00290 #else
00291     /* PLLCLK = 8MHz * 3 = 24 MHz */
00292     RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_3);
00293 #endif
00294 
00295     /* Enable PLL */ 
00296     RCC_PLLCmd(ENABLE);
00297 
00298     /* Wait till PLL is ready */
00299     while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
00300     {
00301     }
00302 
00303     /* Select PLL as system clock source */
00304     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
00305 
00306     /* Wait till PLL is used as system clock source */
00307     while (RCC_GetSYSCLKSource() != 0x08)
00308     {
00309     }
00310   }
00311   else
00312   { /* If HSE fails to start-up, the application will have wrong clock configuration.
00313        User can add here some code to deal with this error */    
00314 
00315     /* Go to infinite loop */
00316     while (1)
00317     {
00318     }
00319   }
00320 }
00321 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL && !defined STM32F10X_HD_VL
00322 /**
00323   * @brief  Sets System clock frequency to 36MHz and configure HCLK, PCLK2 
00324   *   and PCLK1 prescalers. 
00325   * @param  None
00326   * @retval None
00327   */
00328 void SetSysClockTo36(void)
00329 {
00330   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/   
00331   /* RCC system reset(for debug purpose) */
00332   RCC_DeInit();
00333 
00334   /* Enable HSE */
00335   RCC_HSEConfig(RCC_HSE_ON);
00336 
00337   /* Wait till HSE is ready */
00338   HSEStartUpStatus = RCC_WaitForHSEStartUp();
00339 
00340   if (HSEStartUpStatus == SUCCESS)
00341   {
00342     /* Enable Prefetch Buffer */
00343     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
00344 
00345     /* Flash 1 wait state */
00346     FLASH_SetLatency(FLASH_Latency_1);
00347  
00348     /* HCLK = SYSCLK */
00349     RCC_HCLKConfig(RCC_SYSCLK_Div1); 
00350   
00351     /* PCLK2 = HCLK */
00352     RCC_PCLK2Config(RCC_HCLK_Div1); 
00353 
00354     /* PCLK1 = HCLK */
00355     RCC_PCLK1Config(RCC_HCLK_Div1);
00356 
00357 #ifdef STM32F10X_CL
00358     /* Configure PLLs *********************************************************/
00359     /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
00360     RCC_PREDIV2Config(RCC_PREDIV2_Div5);
00361     RCC_PLL2Config(RCC_PLL2Mul_8);
00362 
00363     /* Enable PLL2 */
00364     RCC_PLL2Cmd(ENABLE);
00365 
00366     /* Wait till PLL2 is ready */
00367     while (RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET)
00368     {}
00369 
00370     /* PLL configuration: PLLCLK = (PLL2 / 10) * 9 = 36 MHz */ 
00371     RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2, RCC_PREDIV1_Div10);
00372     RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_9);
00373 #else
00374     /* PLLCLK = (8MHz / 2) * 9 = 36 MHz */
00375     RCC_PLLConfig(RCC_PLLSource_HSE_Div2, RCC_PLLMul_9);
00376 #endif
00377 
00378     /* Enable PLL */ 
00379     RCC_PLLCmd(ENABLE);
00380 
00381     /* Wait till PLL is ready */
00382     while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
00383     {
00384     }
00385 
00386     /* Select PLL as system clock source */
00387     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
00388 
00389     /* Wait till PLL is used as system clock source */
00390     while (RCC_GetSYSCLKSource() != 0x08)
00391     {
00392     }
00393   }
00394   else
00395   { /* If HSE fails to start-up, the application will have wrong clock configuration.
00396        User can add here some code to deal with this error */    
00397 
00398     /* Go to infinite loop */
00399     while (1)
00400     {
00401     }
00402   }
00403 }
00404 
00405 /**
00406   * @brief  Sets System clock frequency to 48MHz and configure HCLK, PCLK2 
00407   *   and PCLK1 prescalers. 
00408   * @param  None
00409   * @retval None
00410   */
00411 void SetSysClockTo48(void)
00412 {
00413   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/   
00414   /* RCC system reset(for debug purpose) */
00415   RCC_DeInit();
00416 
00417   /* Enable HSE */
00418   RCC_HSEConfig(RCC_HSE_ON);
00419 
00420   /* Wait till HSE is ready */
00421   HSEStartUpStatus = RCC_WaitForHSEStartUp();
00422 
00423   if (HSEStartUpStatus == SUCCESS)
00424   {
00425     /* Enable Prefetch Buffer */
00426     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
00427 
00428     /* Flash 1 wait state */
00429     FLASH_SetLatency(FLASH_Latency_1);
00430  
00431     /* HCLK = SYSCLK */
00432     RCC_HCLKConfig(RCC_SYSCLK_Div1); 
00433   
00434     /* PCLK2 = HCLK */
00435     RCC_PCLK2Config(RCC_HCLK_Div1); 
00436 
00437     /* PCLK1 = HCLK/2 */
00438     RCC_PCLK1Config(RCC_HCLK_Div2);
00439 
00440 #ifdef STM32F10X_CL
00441     /* Configure PLLs *********************************************************/
00442     /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
00443     RCC_PREDIV2Config(RCC_PREDIV2_Div5);
00444     RCC_PLL2Config(RCC_PLL2Mul_8);
00445 
00446     /* Enable PLL2 */
00447     RCC_PLL2Cmd(ENABLE);
00448 
00449     /* Wait till PLL2 is ready */
00450     while (RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET)
00451     {}
00452 
00453     /* PLL configuration: PLLCLK = (PLL2 / 5) * 6 = 48 MHz */ 
00454     RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2, RCC_PREDIV1_Div5);
00455     RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_6);
00456 #else
00457     /* PLLCLK = 8MHz * 6 = 48 MHz */
00458     RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_6);
00459 #endif
00460 
00461     /* Enable PLL */ 
00462     RCC_PLLCmd(ENABLE);
00463 
00464     /* Wait till PLL is ready */
00465     while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
00466     {
00467     }
00468 
00469     /* Select PLL as system clock source */
00470     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
00471 
00472     /* Wait till PLL is used as system clock source */
00473     while (RCC_GetSYSCLKSource() != 0x08)
00474     {
00475     }
00476   }
00477   else
00478   { /* If HSE fails to start-up, the application will have wrong clock configuration.
00479        User can add here some code to deal with this error */    
00480 
00481     /* Go to infinite loop */
00482     while (1)
00483     {
00484     }
00485   }
00486 }
00487 
00488 /**
00489   * @brief  Sets System clock frequency to 56MHz and configure HCLK, PCLK2 
00490   *   and PCLK1 prescalers. 
00491   * @param  None
00492   * @retval None
00493   */
00494 void SetSysClockTo56(void)
00495 {
00496   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/   
00497   /* RCC system reset(for debug purpose) */
00498   RCC_DeInit();
00499 
00500   /* Enable HSE */
00501   RCC_HSEConfig(RCC_HSE_ON);
00502 
00503   /* Wait till HSE is ready */
00504   HSEStartUpStatus = RCC_WaitForHSEStartUp();
00505 
00506   if (HSEStartUpStatus == SUCCESS)
00507   {
00508     /* Enable Prefetch Buffer */
00509     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
00510 
00511     /* Flash 2 wait state */
00512     FLASH_SetLatency(FLASH_Latency_2);
00513  
00514     /* HCLK = SYSCLK */
00515     RCC_HCLKConfig(RCC_SYSCLK_Div1); 
00516   
00517     /* PCLK2 = HCLK */
00518     RCC_PCLK2Config(RCC_HCLK_Div1); 
00519 
00520     /* PCLK1 = HCLK/2 */
00521     RCC_PCLK1Config(RCC_HCLK_Div2);
00522 
00523 #ifdef STM32F10X_CL
00524     /* Configure PLLs *********************************************************/
00525     /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
00526     RCC_PREDIV2Config(RCC_PREDIV2_Div5);
00527     RCC_PLL2Config(RCC_PLL2Mul_8);
00528 
00529     /* Enable PLL2 */
00530     RCC_PLL2Cmd(ENABLE);
00531 
00532     /* Wait till PLL2 is ready */
00533     while (RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET)
00534     {}
00535 
00536     /* PLL configuration: PLLCLK = (PLL2 / 5) * 7 = 56 MHz */ 
00537     RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2, RCC_PREDIV1_Div5);
00538     RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_7);
00539 #else
00540     /* PLLCLK = 8MHz * 7 = 56 MHz */
00541     RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_7);
00542 #endif
00543 
00544     /* Enable PLL */ 
00545     RCC_PLLCmd(ENABLE);
00546 
00547     /* Wait till PLL is ready */
00548     while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
00549     {
00550     }
00551 
00552     /* Select PLL as system clock source */
00553     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
00554 
00555     /* Wait till PLL is used as system clock source */
00556     while (RCC_GetSYSCLKSource() != 0x08)
00557     {
00558     }
00559   }
00560   else
00561   { /* If HSE fails to start-up, the application will have wrong clock configuration.
00562        User can add here some code to deal with this error */    
00563 
00564     /* Go to infinite loop */
00565     while (1)
00566     {
00567     }
00568   }
00569 }
00570 
00571 /**
00572   * @brief  Sets System clock frequency to 72MHz and configure HCLK, PCLK2 
00573   *   and PCLK1 prescalers. 
00574   * @param  None
00575   * @retval None
00576   */
00577 void SetSysClockTo72(void)
00578 {
00579   /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/   
00580   /* RCC system reset(for debug purpose) */
00581   RCC_DeInit();
00582 
00583   /* Enable HSE */
00584   RCC_HSEConfig(RCC_HSE_ON);
00585 
00586   /* Wait till HSE is ready */
00587   HSEStartUpStatus = RCC_WaitForHSEStartUp();
00588 
00589   if (HSEStartUpStatus == SUCCESS)
00590   {
00591     /* Enable Prefetch Buffer */
00592     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
00593 
00594     /* Flash 2 wait state */
00595     FLASH_SetLatency(FLASH_Latency_2);
00596  
00597     /* HCLK = SYSCLK */
00598     RCC_HCLKConfig(RCC_SYSCLK_Div1); 
00599   
00600     /* PCLK2 = HCLK */
00601     RCC_PCLK2Config(RCC_HCLK_Div1); 
00602 
00603     /* PCLK1 = HCLK/2 */
00604     RCC_PCLK1Config(RCC_HCLK_Div2);
00605 
00606 #ifdef STM32F10X_CL
00607     /* Configure PLLs *********************************************************/
00608     /* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
00609     RCC_PREDIV2Config(RCC_PREDIV2_Div5);
00610     RCC_PLL2Config(RCC_PLL2Mul_8);
00611 
00612     /* Enable PLL2 */
00613     RCC_PLL2Cmd(ENABLE);
00614 
00615     /* Wait till PLL2 is ready */
00616     while (RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET)
00617     {}
00618 
00619     /* PLL configuration: PLLCLK = (PLL2 / 5) * 9 = 72 MHz */ 
00620     RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2, RCC_PREDIV1_Div5);
00621     RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_9);
00622 #else
00623     /* PLLCLK = 8MHz * 9 = 72 MHz */
00624     RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
00625 #endif
00626 
00627     /* Enable PLL */ 
00628     RCC_PLLCmd(ENABLE);
00629 
00630     /* Wait till PLL is ready */
00631     while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
00632     {
00633     }
00634 
00635     /* Select PLL as system clock source */
00636     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
00637 
00638     /* Wait till PLL is used as system clock source */
00639     while(RCC_GetSYSCLKSource() != 0x08)
00640     {
00641     }
00642   }
00643   else
00644   { /* If HSE fails to start-up, the application will have wrong clock configuration.
00645        User can add here some code to deal with this error */    
00646 
00647     /* Go to infinite loop */
00648     while (1)
00649     {
00650     }
00651   }
00652 }
00653 #endif /* STM32F10X_LD_VL && STM32F10X_MD_VL */
00654 /**
00655   * @brief  Configures Vector Table base location.
00656   * @param  None
00657   * @retval None
00658   */
00659 void NVIC_Configuration(void)
00660 {
00661   NVIC_InitTypeDef NVIC_InitStructure;
00662 
00663   /* Enable and configure RCC global IRQ channel */
00664   NVIC_InitStructure.NVIC_IRQChannel = RCC_IRQn;
00665   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
00666   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  
00667   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00668   NVIC_Init(&NVIC_InitStructure);
00669 }
00670 
00671 /**
00672   * @brief  Inserts a delay time.
00673   * @param  nCount: specifies the delay time length.
00674   * @retval None
00675   */
00676 void Delay(__IO uint32_t nCount)
00677 {
00678   for(; nCount!= 0;nCount--);
00679 }
00680 
00681 #ifdef  USE_FULL_ASSERT
00682 /**
00683   * @brief  Reports the name of the source file and the source line number
00684   *         where the assert_param error has occurred.
00685   * @param  file: pointer to the source file name
00686   * @param  line: assert_param error line source number
00687   * @retval None
00688   */
00689 void assert_failed(uint8_t* file, uint32_t line)
00690 { 
00691   /* User can add his own implementation to report the file name and line number,
00692      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00693 
00694   /* Infinite loop */
00695   while (1)
00696   {
00697   }
00698 }
00699 #endif
00700 
00701 /**
00702   * @}
00703   */ 
00704 
00705 /**
00706   * @}
00707   */ 
00708 
00709 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32