|
void SetSystemClock(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);
if (RCC_WaitForHSEStartUp()== SUCCESS) //SUCCESS
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 0 wait state */
FLASH_SetLatency(FLASH_Latency_2);
//0等待周期,当 0 < SYSCLK < 24MHz ;1等待周期,当24MHz<SYSCLK≤48MHz;2等待周期当48MHz<SYSCLK≤72MHz
/*AHB_CLOCK, HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* APB1,low speed,max_36MHz,PCLK1 = HCLK */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* APB2,high speed,max_72MHz,PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* ADCCLK = PCLK2/4*/
RCC_ADCCLKConfig (RCC_PCLK2_Div4);
/*Config PllSource,HSE*9=72MHz*/
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/*ENABLE PLL_CLK*/
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{}
/* Select the PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while (RCC_GetSYSCLKSource() != 0x08)
{
}
/* Disable the LSE */
RCC_LSEConfig(RCC_LSE_OFF);
/* Enable the Internal Low Speed oscillator */
RCC_LSICmd(ENABLE);
/* Select the LSI as RTC clock source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/* Enable the RTC clock */
RCC_RTCCLKCmd(ENABLE);
/* Enable ALL clocks */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
/* Enable BKP and PWR clocks */
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR|RCC_APB1Periph_SPI2,ENABLE);
/* Enable the Clock Security System */
//RCC_ClockSecuritySystemCmd(ENABLE);
/* Clear the reset flags */
//RCC_ClearFlag();
/* SysTick event each 10 ms with input clock equal to 9MHz (HCLK/8)*/
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
while(SysTick_Config(90000)==1)
{
}
}
}
这个初始化时钟的函数是不可用的 |
|