if(HSEStartUpStatus==SUCCESS)
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_0);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div1);
RCC_PLLConfig(RCC_PLLSource_HSE_Div2,RCC_PLLMul_5);//HSE为8MHz设置PLL输出频率为20MHz
RCC_PLLCmd(ENABLE);//使能PLL
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)//等待PLL就绪
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//配置系统时钟为PLL
while(RCC_GetSYSCLKSource()!=0x08)//检查系统时钟是否为PLL
{
}
}
else
{
while(1)
{
}
}
}
voidSetSysClockTo36(void)//设置系统时钟为36MHz函数
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus=RCC_WaitForHSEStartUp();
if(HSEStartUpStatus==SUCCESS)
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_1);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div1);
RCC_PLLConfig(RCC_PLLSource_HSE_Div2,RCC_PLLMul_9);//8/2*9=36设置PLL为36MHz
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource()!=0x08)
{
}
}
else
{
while(1)
{
}
}
}
voidSetSysClockTo48(void)//设置系统时钟为48MHz函数
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus=RCC_WaitForHSEStartUp();
if(HSEStartUpStatus==SUCCESS)
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_1);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_6);//设置PLL为48MHz
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource()!=0x08)
{
}
}
else
{
while(1)
{
}
}
}
voidSetSysClockTo72(void)//设置系统时钟为72MHz
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus=RCC_WaitForHSEStartUp();
if(HSEStartUpStatus==SUCCESS)
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_2);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);//设置PLL为72MHz
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource()!=0x08)
{
}
}
else
{
while(1)
{
}
}
}
voidNVIC_Configuration(void)//设置中断向量表基址
{
NVIC_InitTypeDefNVIC_InitStructure;//NVIC初始化结构体,定义初始化NVIC的结构体变量
#ifdefVECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM,0x0);
#else
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
#endif
//NVIC_InitStructure是前面定义的NVIC初始化结构体包括以下几项
NVIC_InitStructure.NVIC_IRQChannel=RCC_IRQChannel;//指定IRQ通道这里指定为RCC全局中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;//该参数设置成员NVIC_IRQChannel中的先占优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;//该参数设置成员NVIC_IRQChannel中的从优先级详见函数说明P167
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//该参数指定在成员NVIC_IRQChannel中定义的IRQ通道被使能还是失能
//取值可以为ENABLE或DISABLE
NVIC_Init(&NVIC_InitStructure);//根据结构体NVIC_InitStructure中指定的参数初始化外设NVIC
}
voidDelay(vu32nCount)
{
for(;nCount!=0;nCount--);
}
#ifdefDEBUG
//assert_failed编写于文件main.c或其他用户C文件中
voidassert_failed(u8*file,u32line)
{
while(1)
{
}
}
#endif