Example #1
0
/**
  * @brief  Configures the different system clocks.
  * @param  None
  * @retval : None
  */
void RCC_Configuration(void)
{
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();

  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  if (HSEStartUpStatus == SUCCESS)
  {
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);

    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1);

    /* PCLK1 = HCLK/4 */
    RCC_PCLK1Config(RCC_HCLK_Div4);

    /* PLLCLK = 8MHz * 9 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

    /* Enable PLL */
    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */
    while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {}

    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */
    while (RCC_GetSYSCLKSource() != 0x08)
    {}
  }

  /* TIM2 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

  /* GPIOA clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
}
Example #2
0
void ClkSwitch2HseSystemInit (void)
{
  ErrorStatus HSEStartUpStatus;
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();
  
  RCC_HSICmd(DISABLE); //Turn of the internal RC;
 
  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);
 
  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();
 
  if(HSEStartUpStatus == SUCCESS)
  {
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);
    
    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1); 
  
    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1); 
 
    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);
 
    /* PLLCLK = 10MHz * 7 = 70 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_7);
 
    /* Enable PLL */ 
    RCC_PLLCmd(ENABLE);
 
    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }
 
    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
 
    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }  
}
Example #3
0
void cpu_reclock(const ClockDef_t *clk) {
  // Disable interrupts
  cli();
  
  // Switch to HSE (as changing PLL while using it is asking for trouble)
  RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
  while(RCC_GetSYSCLKSource() != (uint32_t)RCC_CFGR_SWS_HSE); // Wait for completion

  // Disable PLL
  RCC_PLLCmd(DISABLE);

  // Set HCLK & PCLK from table
  RCC_HCLKConfig(clk->hps);
  RCC_PCLK2Config(clk->pps2);
  RCC_PCLK1Config(clk->pps1);

  // Set flash latency from table
  FLASH_SetLatency(clk->f_latency);

  // Use PLL?
  if(clk->m) {
    // Configure PLL
    RCC_PLLConfig(RCC_PLLCFGR_PLLSRC_HSE, clk->m, clk->n, clk->p, clk->q);
    // Enable PLL
    RCC_PLLCmd(ENABLE);
    // Wait for PLL to become stable
    while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
    // Switch to PLL
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
    while (RCC_GetSYSCLKSource() != (uint32_t)RCC_CFGR_SWS_PLL); // Wait for completion
  }

  // Update system tick
  SystemCoreClockUpdate();
  SysTick_Config(SystemCoreClock / 1000);

  sei();
}
Example #4
0
/*******************************************************************************
* Function Name  : RCC_Configuration
* Description    : 系统时钟设置
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void RCC_Configuration(void)
{
	ErrorStatus HSEStartUpStatus;

	//使能外部晶振
	RCC_HSEConfig(RCC_HSE_ON);
	//等待外部晶振稳定
	HSEStartUpStatus = RCC_WaitForHSEStartUp();
	//如果外部晶振启动成功,则进行下一步操作
	if (HSEStartUpStatus==SUCCESS)
	{
		//设置HCLK(AHB时钟)=SYSCLK
		RCC_HCLKConfig(RCC_SYSCLK_Div1);

		//PCLK1(APB1) = HCLK/2
		RCC_PCLK1Config(RCC_HCLK_Div2);

		//PCLK2(APB2) = HCLK
		RCC_PCLK2Config(RCC_HCLK_Div1);

		//FLASH时序控制
		//推荐值:SYSCLK = 0~24MHz   Latency=0
		//        SYSCLK = 24~48MHz  Latency=1
		//        SYSCLK = 48~72MHz  Latency=2
		FLASH_SetLatency(FLASH_Latency_2);
		//开启FLASH预取指功能
		FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

		//PLL设置 SYSCLK/1 * 9 = 8*1*9 = 72MHz
		RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
		//启动PLL
		RCC_PLLCmd(ENABLE);
		//等待PLL稳定
		while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
		//系统时钟SYSCLK来自PLL输出
		RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
		//切换时钟后等待系统时钟稳定
		while (RCC_GetSYSCLKSource()!=0x08);
	}

	//下面是给各模块开启时钟
	//启动GPIO
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC |\
						   RCC_APB2Periph_GPIOD,\
						   ENABLE);
	//启动AFIO
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

	return;
}
Example #5
0
void clockInit()
{
  // divide HCLK / 2
  RCC_HCLKConfig(RCC_SYSCLK_Div2);

  // enable HSI
  RCC_HSICmd(ENABLE);
  RCC_PLLCmd(DISABLE);
  // wait for HSI to get ready
  while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);

  // configure PLL - x4 /2 
  RCC_PLLConfig( RCC_PLLSource_HSI, RCC_PLLMul_8,  RCC_PLLDiv_4 );
  RCC_PLLCmd(ENABLE);

  while ( RCC_GetFlagStatus( RCC_FLAG_PLLRDY ) == RESET );

  // set hsi as clock
  //RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);

  // set pll as clock
  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
}
Example #6
0
void RCC_Config(void)
{
  
  RCC_DeInit(); 
  RCC_HSEConfig(RCC_HSE_ON); //Включим внешний генератор
  while (SUCCESS != RCC_WaitForHSEStartUp()); //Подождем запуска генератора
  RCC_PLLCmd(DISABLE); 
  RCC_PLLConfig(RCC_PLLSource_PREDIV1,RCC_PLLMul_12); //Вход ПЛЛ внешний генератор умножим на 12
  RCC_PLLCmd(ENABLE);  
  
  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);   //Системное тактирование от ПЛЛ
  RCC_HCLKConfig(RCC_SYSCLK_Div1);      //Тактирование AHB с делением 1
  
  RCC_PCLKConfig(RCC_HCLK_Div8);        //Тактирование переферии с делением 8
  RCC_ADCCLKConfig(RCC_ADCCLK_PCLK_Div2);       //Тактирование АЦП
  RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK);         //Тактируем шину I2C от системного тактирования
  RCC_USARTCLKConfig(RCC_USART1CLK_PCLK);       //Тактируем UART от шини  переферии
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA + RCC_AHBPeriph_GPIOB,ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 + RCC_APB2Periph_USART1 + RCC_APB2Periph_TIM1 + RCC_APB2Periph_TIM15, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
#ifdef MCO_ENABLE
  GPIOA_Struct_init.GPIO_Pin = GPIO_Pin_8;
  GPIOA_Struct_init.GPIO_Mode = GPIO_Mode_AF;
  GPIOA_Struct_init.GPIO_Speed = GPIO_Speed_Level_2;
  GPIOA_Struct_init.GPIO_OType = GPIO_OType_PP;
  GPIO_Init(GPIOA,&GPIOA_Struct_init);
  RCC_MCOConfig(RCC_MCOSource_SYSCLK);
  while (1);
#else
  RCC_MCOConfig(RCC_MCOSource_NoClock);
#endif /*MCO_ENABLE  */
};
Example #7
0
/*****************************************************************************
 * Function Name  : RCC_Configuration
 * Description    : Reset and Clock Control configuration
 * Input          : None
 * Output         : None
 * Return         : None
 ******************************************************************************/
void RCC_Configuration(void)
{
    ErrorStatus HSEStartUpStatus;
    
    /* Reset the RCC clock configuration to default reset state */
    RCC_DeInit();
    
    /* Configure the High Speed External oscillator */
    RCC_HSEConfig(RCC_HSE_ON);
    
    /* Wait for HSE start-up */
    HSEStartUpStatus = RCC_WaitForHSEStartUp();
    
    if(HSEStartUpStatus == SUCCESS)
    {
        /* Enable Prefetch Buffer */
        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
        
        /* Set the code latency value: FLASH Two Latency cycles */
        FLASH_SetLatency(FLASH_Latency_2);
        
        /* Configure the AHB clock(HCLK): HCLK = SYSCLK */
        RCC_HCLKConfig(RCC_SYSCLK_Div1);
        
        /* Configure the High Speed APB2 clcok(PCLK2): PCLK2 = HCLK */
        RCC_PCLK2Config(RCC_HCLK_Div1);
        
        /* Configure the Low Speed APB1 clock(PCLK1): PCLK1 = HCLK/2 */
        RCC_PCLK1Config(RCC_HCLK_Div2);
        
        /* Configure the PLL clock source and multiplication factor	*/
        /* PLLCLK = HSE*PLLMul = 8*9 = 72MHz */
        RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
        
        /* Enable PLL	*/
        RCC_PLLCmd(ENABLE);
        
        /* Check whether the specified RCC flag is set or not */
        /* Wait till PLL is ready	*/
        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
        
        /* Select PLL as system clock source */
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
        
        /* Get System Clock Source */
        /* Wait till PLL is used as system clock source	*/
        while(RCC_GetSYSCLKSource() != 0x08);
    } 
}
Example #8
0
void RCC_Internal_Configuration(void)
{
	ErrorStatus HSEStartUpStatus;

	//将外设 RCC寄存器重设为缺省值

	RCC_DeInit();

	RCC_HSICmd(ENABLE);

	while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);

	if(HSEStartUpStatus == SUCCESS) 
	{

		RCC_HCLKConfig(RCC_SYSCLK_Div1);

		RCC_PCLK2Config(RCC_HCLK_Div1);

		RCC_PCLK1Config(RCC_HCLK_Div2);

		//设置 PLL 时钟源及倍频系数

		RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_2);

		//使能或者失能 PLL,这个参数可以取:ENABLE或者DISABLE

		RCC_PLLCmd(ENABLE);//如果PLL被用于系统时钟,那么它不能被失能

		//等待指定的 RCC 标志位设置成功 等待PLL初始化成功

		while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

		//设置系统时钟(SYSCLK) 设置PLL为系统时钟源

		RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

		//等待PLL成功用作于系统时钟的时钟源

		// 0x00:HSI 作为系统时钟

		// 0x04:HSE作为系统时钟

		// 0x08:PLL作为系统时钟

		while(RCC_GetSYSCLKSource() != 0x08);
	}
}
Example #9
0
void fastMode() {
    RCC_DeInit();

    RCC_HSEConfig(RCC_HSE_ON);
    if (RCC_WaitForHSEStartUp() == ERROR) {
        return;
    }
    RCC_PLLConfig(RCC_PLLSource_HSE, 8, 336, 2, 15);
    RCC_PLLCmd(ENABLE);

    RCC_WaitForPLLSturtUp();

    RCC_HCLKConfig(RCC_SYSCLK_Div4);
    RCC_PCLK1Config(RCC_HCLK_Div1);
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
}
Example #10
0
/**************************************************************/
//程 序 名: RCC_Config()
//开 发 者: Haichao.Xie
//入口参数: 无
//功能说明: 系统时钟配置
//**************************************************************/
void RCC_Config(void)
{
	ErrorStatus HSEStartUpStatus;	//定义结构体
	/* RCC system reset(for debug purpose)将外设 RCC寄存器重设为缺省值 */
	RCC_DeInit();
	/* Enable HSE 设置外部高速晶振(HSE)*/
	RCC_HSEConfig(RCC_HSE_ON);
	/* Wait till HSE is ready 等待 HSE 起振*/
	HSEStartUpStatus = RCC_WaitForHSEStartUp();

	if (HSEStartUpStatus == SUCCESS)
	{
		/* Enable Prefetch Buffer 预取指缓存使能*/
		FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

		/* Flash 2 wait state 设置代码延时值*/
		FLASH_SetLatency(FLASH_Latency_2);

		/* HCLK = SYSCLK 设置 AHB 时钟(HCLK)*/
		RCC_HCLKConfig(RCC_SYSCLK_Div1);

		/* PCLK2 = HCLK 设置高速 AHB 时钟(PCLK2)*/
		RCC_PCLK2Config(RCC_HCLK_Div1);

		/* PCLK1 = HCLK/1 设置低速 AHB 时钟(PCLK1)*/
		RCC_PCLK1Config(RCC_HCLK_Div1);

		/* PLLCLK = 12MHz * 6 = 72 MHz 设置 PLL 时钟源及倍频系数*/
		RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_6);

		/* Enable PLL 使能或者失能 PLL*/
		RCC_PLLCmd(ENABLE);

		/* Wait till PLL is ready 等待指定的 RCC 标志位设置成功 等待PLL初始化成功*/
		while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
		{
		}
		/* Select PLL as system clock source 设置系统时钟(SYSCLK) 设置PLL为系统时钟源*/
		RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

		/* Wait till PLL is used as system clock source 等待PLL成功用作于系统时钟的时钟源*/
		while(RCC_GetSYSCLKSource() != 0x08)
		{
		}
	}
}
Example #11
0
static void RCC_Configuration(void)
{
  /*---------------------------------*/
  /*  /!\  PLL2 not configured  /!\  */
  /*---------------------------------*/
  ErrorStatus HSEStartUpStatus;
  // RCC system reset(for debug purpose)
  RCC_DeInit();
  // Enable HSE
  RCC_HSEConfig(RCC_HSE_ON);
  // Wait till HSE is ready
  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  if(HSEStartUpStatus == SUCCESS)
  {
    // Enable Prefetch Buffer
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
    // Flash 2 wait state
    FLASH_SetLatency(FLASH_Latency_2);
    // HCLK = SYSCLK
    RCC_HCLKConfig(RCC_SYSCLK_Div1);
    // PCLK2 = HCLK
    RCC_PCLK2Config(RCC_HCLK_Div1);
    // PCLK1 = HCLK/2
    RCC_PCLK1Config(RCC_HCLK_Div2);
    /* ADCCLK = PCLK2/4 */
    RCC_ADCCLKConfig(RCC_PCLK2_Div4);
    // PLLCLK = 8MHz * 9 = 72 MHz
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
    // Enable PLL
    RCC_PLLCmd(ENABLE);
    // Wait till PLL is ready
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {;}
    // Select PLL as system clock source
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
    // Wait till PLL is used as system clock source
    while(RCC_GetSYSCLKSource() != 0x08)  ///????
    {;}
  }

    /* Enable peripheral clocks (FOR USART1)---------------------------------*/
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
    /* Enable GPIOA / GPIOC clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
}
Example #12
0
/*
 * RCC时钟频率引脚配置
 */
void RCC_Configuration(void)
{
	//定义错误状态变量
	ErrorStatus HSEStartUpStatus;
	
	//将RCC寄存器重新设置为默认值
	RCC_DeInit();
	
	//打开外部高速时钟晶振
	RCC_HSEConfig(RCC_HSE_ON);
	
	//等待外部高速时钟晶振工作
	HSEStartUpStatus = RCC_WaitForHSEStartUp();
	if(HSEStartUpStatus != SUCCESS) return;
	
	//使能预取指缓存
	FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
	
	//设置FLASH代码延时
	FLASH_SetLatency(FLASH_Latency_2);

	//设置AHB时钟(HCLK)为系统时钟
	RCC_HCLKConfig(RCC_SYSCLK_Div1); 

	//设置高速AHB时钟(APB2)为HCLK时钟
	RCC_PCLK2Config(RCC_HCLK_Div1); 

  //设置低速AHB时钟(APB1)为HCLK的2分频
	RCC_PCLK1Config(RCC_HCLK_Div2);	

  //设置PLL时钟,为HSE的12倍频 PLLCLK = 12MHz/2 * 12 = 72 MHz
	RCC_PLLConfig(RCC_PLLSource_HSE_Div2, RCC_PLLMul_12);

	//使能PLL
	RCC_PLLCmd(ENABLE);

	//等待PLL准备就绪
	while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

	//设置PLL为系统时钟源
	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

	//判断PLL是否是系统时钟
	while(RCC_GetSYSCLKSource() != 0x08);
}
Example #13
0
void RCC_Configuration(void)
{
  ErrorStatus HSEStartUpStatus;
 
  RCC_DeInit();                                                      
  RCC_HSEConfig(RCC_HSE_ON);                    
  HSEStartUpStatus = RCC_WaitForHSEStartUp(); 
  if(HSEStartUpStatus == SUCCESS)                      
    {          
      RCC_HCLKConfig(RCC_SYSCLK_Div1);        
      RCC_PCLK2Config(RCC_HCLK_Div1);
      RCC_PCLK1Config(RCC_HCLK_Div2);
      FLASH_SetLatency(FLASH_Latency_2);
			FLASH_PrefetchBufferCmd(ENABLE);
			RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);
      RCC_PLLCmd(ENABLE);                              
      while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET);                                                              
      RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);  
      while(RCC_GetSYSCLKSource() !=0x08);
			
			// the following is the selected part of the clock inicialization, according to your connecting devices
			
			//SPI1 clock open
			RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1,ENABLE);
			RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
			RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
			
			//USART-XTend (wireless data transmittion) clock open
			RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
      
			//USART-GPS clock open
			RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
			
			//USART-sensor clock open
			RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
			
			//GPIO LED clock open
			RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
			
			//GPIO Launching clock open
			RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
			
			SysTick_ITConfig(ENABLE);
   }
}
Example #14
0
//when wakeup by alarm, configure rcc
void RCC_Wakeup(void)
{
    GPIOC->ODR ^= 0X0010;
    //enable PLL
    RCC_PLLCmd(ENABLE);

    // Wait till PLL is ready 
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {}

    // Select PLL as system clock source 
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
  
    // Wait till PLL is used as system clock source 
    while(RCC_GetSYSCLKSource() != 0x08)
    {}
    GPIOC->ODR ^= 0X0010;
}
Example #15
0
void RCC_HSE_Configuration(void){
	RCC_DeInit(); /*将外设RCC寄存器重设为缺省值 */ 
	RCC_HSEConfig(RCC_HSE_ON); 	 /*设置外部高速晶振打开*/

	if(RCC_WaitForHSEStartUp() == SUCCESS) {  /*等待HSE起振,晶振稳定且就绪*/

		RCC_HCLKConfig(RCC_SYSCLK_Div1);/*设置AHB时钟*/
		RCC_PCLK2Config(RCC_HCLK_Div1); /*设置高速AHB时钟*/
		RCC_PCLK1Config(RCC_HCLK_Div2); /*设置低速AHB时钟*/

		RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);/*设置PLL时钟源、倍频系数*/		 
		RCC_PLLCmd(ENABLE);//使能PLL
		while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);//检查指定RCC标志位

		RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //设置系统时钟
		while(RCC_GetSYSCLKSource() != 0x08);    //PLL作为系统时钟
	}
}
Example #16
0
void TSVN_FOSC_Init(void)
{
	RCC_DeInit();								
	RCC_HSEConfig(RCC_HSE_ON);	
	while(RCC_WaitForHSEStartUp() != SUCCESS);
	RCC_PREDIV1Config(RCC_PREDIV1_Source_HSE, RCC_PREDIV1_Div1);
	RCC_HCLKConfig(RCC_SYSCLK_Div1); 
	RCC_PCLK2Config(RCC_HCLK_Div2);     
	RCC_PCLK1Config(RCC_HCLK_Div2);  
	RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_9);
	RCC_PLLCmd(ENABLE);	
	while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); 
	while(RCC_GetSYSCLKSource() != 0x08)
	SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
	SystemCoreClockUpdate();
	SysTick_Config(SystemCoreClock/1000);
}
Example #17
0
void Startup::clkInit()
{
	// Set STKALIGN in NVIC
	SCB->CCR |= 0x200;

	// 1. Clocking the controller from internal HSI RC (8 MHz)
	RCC_HSICmd(ENABLE);
	// wait until the HSI is ready
	while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
	RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
	// 2. Enable ext. high frequency OSC
	RCC_HSEConfig(RCC_HSE_ON);
	// wait until the HSE is ready
	while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);
	// 3. Init PLL
	RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9); // 72MHz
//  RCC_PLLConfig(RCC_PLLSource_HSE_Div2,RCC_PLLMul_9); // 72MHz
	RCC_PLLCmd(ENABLE);
	// wait until the PLL is ready
	while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
	// 4. Set system clock dividers
	RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
	RCC_ADCCLKConfig(RCC_PCLK2_Div8);
	RCC_PCLK2Config(RCC_HCLK_Div1);
	RCC_PCLK1Config(RCC_HCLK_Div2);
	RCC_HCLKConfig(RCC_SYSCLK_Div1);

	// Flash 1 wait state
//	*(vu32 *)0x40022000 = 0x12;
//	*(vu32 *)0x40022000 = 0x01;

    // Enable Prefetch Buffer
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
    // Flash 2 wait state
    FLASH_SetLatency(FLASH_Latency_2);

	// Select PLL as system clock source
	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    // Wait till PLL is used as system clock source
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
}
Example #18
0
void RCC_Configuration(void)
{
	/* RCC system reset(for debug purpose) */
	RCC_DeInit();

	/* Enable HSE */
	RCC_HSEConfig(RCC_HSE_ON);

	/* Wait till HSE is ready */
	while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET)
		;

	/* Enable Prefetch Buffer */
	FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

	/* Flash 2 wait state */
	FLASH_SetLatency(FLASH_Latency_2);

	/* HCLK = SYSCLK */
	RCC_HCLKConfig(RCC_SYSCLK_Div1);

	/* PCLK2 = HCLK */
	RCC_PCLK2Config(RCC_HCLK_Div1);

	/* PCLK1 = HCLK/2 */
	RCC_PCLK1Config(RCC_HCLK_Div2);

	/* PLLCLK = 8MHz * 9 = 72 MHz */
	RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

	/* Enable PLL */
	RCC_PLLCmd(ENABLE);

	/* Wait till PLL is ready */
	while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
		;

	/* Select PLL as system clock source */
	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

	/* Wait till PLL is used as system clock source */
	while (RCC_GetSYSCLKSource() != 0x08)
		;
}
Example #19
0
File: bsp.c Project: xinmulan/RGB
void RCC_Configuration(void)
{
     /* 定义枚举型变量HSEStartUpStatus */
    ErrorStatus HSEStartUpStatus;
    /* 复位系统时钟设置*/
    RCC_DeInit();
    /* 开启HSE*/
    RCC_HSEConfig(RCC_HSE_ON);
    /* 等待HSE启振并稳定*/
    HSEStartUpStatus = RCC_WaitForHSEStartUp();

    /*判断HSE是否起振成功, */
    if(HSEStartUpStatus == SUCCESS)
    {
        /* 选择HCLK(AHB)时钟源为 SYSCLK 1分频 */
        RCC_HCLKConfig(RCC_SYSCLK_Div1);
        /* 选择PCLK2时钟源为HCLK(AHB) 1分频*/
        RCC_PCLK2Config(RCC_HCLK_Div1);
        /* 选择PCLK1时钟源为HCLK(AHB) 2分频*/
        RCC_PCLK1Config(RCC_HCLK_Div2);
        /* 设置FLASH延时周期数为2 */
        FLASH_SetLatency(FLASH_Latency_2);
        /* 使能FLASH预缓存 */
        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
        /* 选择锁相环(PLL)时钟源为HSE 1分频,倍频数为9,则PLL输出频率 8MHz * 9 = 72MHz */
        RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
        /* 使能PLL */
        RCC_PLLCmd(ENABLE);
        /* 等待PLL输出稳定 */
        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
        /* 选择SYSCLK时钟源为PLL */
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
        /* 等待PLL成为SYSCLK时钟源*/
        while(RCC_GetSYSCLKSource() != 0x08);
    }

    /* 打开APB2总线上的GPIOA时钟*/
		RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB|
													 RCC_APB2Periph_AFIO  |RCC_APB2Periph_USART1 ,ENABLE);       
		RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 | RCC_APB1Periph_TIM4,ENABLE);
		

}
Example #20
0
void RCC_HSE_Configuration(void) //HSE作为PLL时钟,PLL作为SYSCLK 
{ 
   RCC_DeInit(); /*将外设RCC寄存器重设为缺省值 */ 
   RCC_HSEConfig(RCC_HSE_ON); 	 /*设置外部高速晶振(HSE) HSE晶振打开(ON)*/ 

   if(RCC_WaitForHSEStartUp() == SUCCESS) {  /*等待HSE起振,  SUCCESS:HSE晶振稳定且就绪*/  

   RCC_HCLKConfig(RCC_SYSCLK_Div1);/*设置AHB时钟(HCLK)RCC_SYSCLK_Div1——AHB时钟 = 系统时*/  
   RCC_PCLK2Config(RCC_HCLK_Div1); /*设置高速AHB时钟(PCLK2)RCC_HCLK_Div1——APB2时钟 = HCLK*/     
   RCC_PCLK1Config(RCC_HCLK_Div2); /*设置低速AHB时钟(PCLK1)RCC_HCLK_Div2——APB1时钟 = HCLK / 2*/      

   RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);/*设置PLL时钟源及倍频系数*/    
   RCC_PLLCmd(ENABLE); 	 /*使能PLL */ 
   while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) ; /*检查指定的RCC标志位(PLL准备好标志)设置与否*/ 
    
   RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);  /*设置系统时钟(SYSCLK) */  
   while(RCC_GetSYSCLKSource() != 0x08);     /*0x08:PLL作为系统时钟 */	    
 } 
} 
Example #21
0
void RCC_Configuration(void)
{
    RCC_DeInit();                                    //将外设RCC寄存器重设为缺省值

#ifdef ExtOSC

    RCC_HSEConfig(RCC_HSE_ON);                    //开启外部高速晶振(HSE)

    //等待HSE起振
    if( RCC_WaitForHSEStartUp() == SUCCESS)               //若成功起振,(下面为系统总线时钟设置)
    {
        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //使能FLASH预取指缓存

        //FLASH_SetLatency(FLASH_Latency_0);   //设置FLASH存储器延时时钟周期数(根据不同的系统时钟选取不同的值)
        //RCC_HCLKConfig(RCC_SYSCLK_Div1);   //设置AHB时钟=72 MHz
        //RCC_PCLK2Config(RCC_HCLK_Div2);   //设置APB1时钟=36 MHz(APB1时钟最大值)
        //RCC_PCLK1Config(RCC_HCLK_Div1);   //设置APB2时钟=72 MHz
        //4*8=32Mhz
        RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_4); //PLL必须在其激活前完成配置(设置PLL时钟源及倍频系数)
        RCC_PLLCmd(ENABLE);

        // while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

        // while(RCC_GetSYSCLKSource() != 0x08);

    }
    //DebugPrint("Use ExtOSC PLL \r\n",);
#else

    /*  使用内部RC晶振 */
    RCC_HSICmd(ENABLE);//使能内部高速晶振 ;
    while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);

    RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);//选择内部高速时钟作为系统时钟SYSCLOCK=8MHZ
    RCC_HCLKConfig(RCC_SYSCLK_Div1);//选择HCLK时钟源为系统时钟SYYSCLOCK
    //DebugPrint("Use IntOSC\r\n");
#endif


    SystemCoreClockUpdate(); //更新时钟必须调用
}
Example #22
0
//===============================================
void RCC_Configuration(void)
{
	FLASH_PrefetchBufferCmd(ENABLE);
	FLASH_SetLatency(FLASH_ACR_LATENCY_1);
    RCC_DeInit();
    RCC_HSICmd(ENABLE);
	RCC_HCLKConfig(RCC_SYSCLK_Div1);
	RCC_PCLK1Config(RCC_HCLK_Div1);
	RCC_PCLK2Config(RCC_HCLK_Div1);
	RCC_ADCCLKConfig(RCC_PCLK2_Div6);
	RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_6);
	RCC_PLLCmd(ENABLE);
	/* Wait till PLL is ready */
	while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {}
	/* Select PLL as system clock source */
	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
	/* Wait till PLL is used as system clock source */
	while (RCC_GetSYSCLKSource() != 0x08) {};
};
Example #23
0
void RtcRecoverMcuStatus( void )
{
    if( TimerGetLowPowerEnable( ) == true )
    {
        if( ( LowPowerDisableDuringTask == false ) && ( RtcTimerEventAllowsLowPower == true ) )
        {
            // Disable IRQ while the MCU is not running on HSI
            __disable_irq( );

            /* After wake-up from STOP reconfigure the system clock */
            /* Enable HSI */
            RCC_HSICmd( ENABLE );

            /* Wait till HSI is ready */
            while( RCC_GetFlagStatus( RCC_FLAG_HSIRDY ) == RESET )
            {}

            /* Enable PLL */
            RCC_PLLCmd( ENABLE );

            /* Wait till PLL is ready */
            while( RCC_GetFlagStatus( RCC_FLAG_PLLRDY ) == RESET )
            {}

            /* Select PLL as system clock source */
            RCC_SYSCLKConfig( RCC_SYSCLKSource_PLLCLK );

            /* Wait till PLL is used as system clock source */
            while( RCC_GetSYSCLKSource( ) != 0x0C )
            {}

            /* Set MCU in ULP (Ultra Low Power) */
            PWR_UltraLowPowerCmd( DISABLE ); // add up to 3ms wakeup time

            /* Enable the Power Voltage Detector */
            PWR_PVDCmd( ENABLE );

            BoardInitMcu( );

            __enable_irq( );
        }
    }
}
Example #24
0
/**
* @brief  This function handles EXTI0_IRQ Handler.
* @param  None
* @retval None
*/
void EXTI0_IRQHandler(void) {

  if (EXTI_GetITStatus(EXTI_Line0) != RESET) {

//    if (USB_OTG_dev.dev.DevRemoteWakeup) {

      if((USB_OTG_dev.cfg.low_power)&&(USB_OTG_dev.dev.device_status==USB_OTG_SUSPENDED)) {

        /* Reset SLEEPDEEP and SLEEPONEXIT bits */
        SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));

        /* After wake-up from sleep mode, reconfigure the system clock */
        /* After wake-up from STOP reconfigure the system clock */

        /* Enable HSE */
        RCC_HSEConfig(RCC_HSE_ON);

        /* Wait till HSE is ready */
        while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);

        /* Enable PLL */
        RCC_PLLCmd(ENABLE);

        /* Wait till PLL is ready */
        while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

        /* Select PLL as system clock source */
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

        /* Wait till PLL is used as system clock source */
        while (RCC_GetSYSCLKSource() != 0x08);

        USB_OTG_UngateClock(&USB_OTG_dev);
      }
      USB_OTG_ActiveRemoteWakeup(&USB_OTG_dev);
      USB_OTG_dev.dev.device_status = USB_OTG_dev.dev.device_old_status;

//    }
    /* Clear the EXTI line pending bit */
    EXTI_ClearITPendingBit(EXTI_Line0);

  }
}
void RCC_Config_30MHz(void){
RCC_DeInit();
FLASH_SetLatency(FLASH_Latency_2);
/*configurar clock externo a 72Mhz */

//bypass pois está ligado no OSC_IN um circuito oscilatorio externo
RCC_HSEConfig(RCC_HSE_Bypass);
//Após a ativação do HSE deveremos esperar até que o sinal de relógio esteja pronto e estável
ErrorStatus HSEStartUpStatus;
HSEStartUpStatus=RCC_WaitForHSEStartUp();

if(HSEStartUpStatus==SUCCESS) /*retorna SUCCESS ou ERROR*/
{   

    //divisão do prescaler AHB por 1
    RCC_HCLKConfig(RCC_SYSCLK_Div1);
    //divisão do prescaler APB1 por 2
    RCC_PCLK1Config(RCC_HCLK_Div1);
    //divisão do prescaler APB2 por 1
    RCC_PCLK2Config(RCC_HCLK_Div1);
    //configuar a PLL para 30Mhz
    RCC_PLLConfig(RCC_PLLSource_HSE_Div2,RCC_PLLMul_5);
    //activar a pll
    RCC_PLLCmd(ENABLE);
    
    while(RCC_GetFlagStatus( RCC_FLAG_PLLRDY)==RESET);
    //activa o sysclk pll
    
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    
    //confirmar que o clock está correcto logo esperar que a fonte de relógio esteja correta
    while(RCC_GetSYSCLKSource()!=0x08);
    //clock configurado com sucesso 
}
else
 while(1); /*se deu erro o micro nao arranca*/




}
Example #26
0
/*******************************************************************************
* Function Name  : Leave_LowPowerMode.
* Description    : Restores system clocks and power while exiting suspend mode.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void Leave_LowPowerMode(void)
{
  DEVICE_INFO *pInfo = &Device_Info;

  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET)
  {}

  /* Enable PLL */
  RCC_PLLCmd(ENABLE);

  /* Wait till PLL is ready */
  while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
  {}

  /* Select PLL as system clock source */
  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

  /* Wait till PLL is used as system clock source */
  while (RCC_GetSYSCLKSource() != 0x08)
  {}

  /* Set the device state to the correct state */
  if (pInfo->Current_Configuration != 0)
  {
    /* Device configured */
    bDeviceState = CONFIGURED;
  }
  else
  {
    bDeviceState = ATTACHED;
  }
}
Example #27
0
void RCC_Configuration(void)
{
    ErrorStatus HSEStartUpStatus;
    RCC_DeInit();

    RCC_HSEConfig(RCC_HSE_ON);
    HSEStartUpStatus = RCC_WaitForHSEStartUp();
    if(HSEStartUpStatus == SUCCESS)
    {
      RCC_HCLKConfig(RCC_SYSCLK_Div1);
      RCC_PCLK2Config(RCC_HCLK_Div1);
      RCC_PCLK1Config(RCC_HCLK_Div2);
      RCC_PLLConfig(RCC_PLLSource_HSE, 8, 168, 2, 6);
      RCC_PLLCmd(ENABLE);
      while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
      RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
      while(RCC_GetSYSCLKSource() != 0x08);
      
    }
}
Example #28
0
void CLOCK_FLASH_config()
{
	// クロックの状態を初期値に戻す
	RCC_DeInit();

	// wait stateの設定
	if     (VoltageRange_x == VoltageRange_2) FLASH_SetLatency(FLASH_Latency_6);
	else if(VoltageRange_x == VoltageRange_3) FLASH_SetLatency(FLASH_Latency_5);
	else while(1);

	// ART Acceleratorの設定
	FLASH_PrefetchBufferCmd(ENABLE);
	FLASH_InstructionCacheCmd(ENABLE);
	FLASH_DataCacheCmd(ENABLE);

	// HSIのキャリブレーション値を設定する
	RCC_AdjustHSICalibrationValue(HSICalibrationValue);

	// PLLの設定をする (max. 168 MHz)
	// PLLM: division factor, 2-63 --> 1-2 MHz (2MHz is recommended)
	// PLLN: multiplication factor, 64-432 --> 64-432 MHz
	// PLLP: division factor, 2, 4, 6, or 8 --> max 168 MHz
	// PLLQ: division factor, 2-15 --> 48 MHz
	RCC_PLLConfig(RCC_PLLSource_HSI, 8, 168, 2, 7); // HSI / 8 * 168 / 2 = 168 MHz
	//RCC_PLLConfig(RCC_PLLSource_HSI, 8, 168, 4, 7); // HSI / 8 * 168 / 4 = 84 MHz
	RCC_PLLCmd(ENABLE);
	while( RCC_GetFlagStatus(RCC_FLAG_PLLRDY) != SET);

	// HCLKの分周比を設定する (max. 168 MHz)
	RCC_HCLKConfig(RCC_SYSCLK_Div1);

	// PCLK2の分周比を設定する (max. 84 MHz)
	RCC_PCLK2Config(RCC_HCLK_Div2);

	// PLCK1の分周比を設定する (max. 42 MHz)
	RCC_PCLK1Config(RCC_HCLK_Div4);

	// SYSCLKのクロックソースをPLLに切り替える
	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
	while(RCC_GetSYSCLKSource() != 0x08);
}
Example #29
0
File: hal_mcu.c Project: gxp/node
void RCC_Configuration(void)
{
	/* system clocks configuration -----------------系统时钟配置-------------------*/
	/* RCC system reset(for debug purpose) */
	RCC_DeInit();                                    //将外设RCC寄存器重设为缺省值
	/* Enable HSE */
	//RCC_HSEConfig(RCC_HSE_ON);                    //开启外部高速晶振(HSE)
	/* Wait till HSE is ready */ 
	//HSEStartUpStatus = RCC_WaitForHSEStartUp();    //等待HSE起振
	//if(HSEStartUpStatus == SUCCESS)               //若成功起振,(下面为系统总线时钟设置)
	//{
		/* Enable Prefetch Buffer */
		FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //使能FLASH预取指缓存
		/* Flash 2 wait state */
		FLASH_SetLatency(FLASH_Latency_2);   //设置FLASH存储器延时时钟周期数(根据不同的系统时钟选取不同的值)

		/* HCLK = SYSCLK */
		RCC_HCLKConfig(RCC_SYSCLK_Div1);   //设置AHB时钟=72 MHz
		/* PCLK2 = HCLK/2 */
		RCC_PCLK2Config(RCC_HCLK_Div2);   //设置APB1时钟=36 MHz(APB1时钟最大值)
		/* PCLK1 = HCLK/2 */
		RCC_PCLK1Config(RCC_HCLK_Div8);   //设置APB2时钟=72 MHz
		/* Configure ADCCLK such as ADCCLK = PCLK2/2 */
		RCC_ADCCLKConfig(RCC_PCLK2_Div2); //RCC_PCLK2_Div2,4,6,8
		/* PLLCLK = 8MHz * 9 = 72 MHz */
		//RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_12); //PLL必须在其激活前完成配置(设置PLL时钟源及倍频系数)
		RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_12);
		/* Enable PLL */
		RCC_PLLCmd(ENABLE);
		/* Wait till PLL is ready */
		while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
		{
		}
		/* Select PLL as system clock source */
		RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
		/* Wait till PLL is used as system clock source */
		while(RCC_GetSYSCLKSource() != 0x08)
		{
		}   
	//}
}
Example #30
0
//配置系统时钟
void RCC_Configuration(void){
	//定义枚举类型变量
	ErrorStatus	HSEStartUpStatus;
	
	//复位系统时钟设置
	RCC_DeInit();  
	
	//开启HSE时钟
	RCC_HSEConfig(RCC_HSE_ON);
	//等待HSE起振并稳定
	HSEStartUpStatus=RCC_WaitForHSEStartUp();
	//判断HSE是否起振成功
	if(HSEStartUpStatus == SUCCESS){
		//选择HCLK(AHB)时钟源为SYSCLK	1分频
		RCC_HCLKConfig(RCC_SYSCLK_Div1);
		//选择PCLK2时钟源为HCLK(AHB)	1分频
		RCC_PCLK2Config(RCC_HCLK_Div1);
		//选择PCLK1时钟源为HCLK(AHB)	2分频
		RCC_PCLK1Config(RCC_HCLK_Div2);
		
		//设置flash延时周期数为2
		FLASH_SetLatency(FLASH_Latency_2);
		//使能预取缓冲
		FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

		//选择锁相环(PLL时钟源为HSE 1分频,倍频数为9,则PLL输出频率为8M * 9 = 72M)
		RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
		//使能PLL
		RCC_PLLCmd(ENABLE);
		//等待PLL输出稳定
		while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET){};

		//选择PLL为系统时钟源,并等待PLL准备好
		RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
		while(RCC_GetSYSCLKSource() != 0x08){};
	}
	//4个LED对应PE2 PE3 PE4 PE5
	//因此要使能APB2总线上的GPIOE时钟
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
	
}