stm32f105/107互聯(lián)性時(shí)鐘配置參考函數(shù)
/************************************************************************
** Function Name : RCC_Configuration
** Description : 配置時(shí)鐘
** Input Parameters :
** Output Parameters :
= 1 : 保存成功
= 0 : 保存失敗
note :
************************************************************************/
void RCC_Configuration(void)
{
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)
{
// Flash 2 wait state
FLASH_SetLatency(FLASH_Latency_2);
// Enable Prefetch Buffer
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
// HCLK = SYSCLK AHB時(shí)鐘為系統(tǒng)時(shí)鐘 72MHz
RCC_HCLKConfig(RCC_SYSCLK_Div1);
// PCLK2 = HCLK APB2時(shí)鐘為系統(tǒng)時(shí)鐘 72MHz
RCC_PCLK2Config(RCC_HCLK_Div1);
// PCLK1 = HCLK/2 APB1時(shí)鐘為系統(tǒng)時(shí)鐘 72MHz/2=36MHz
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PREDIV2Config(RCC_PREDIV2_Div2);// 8M / 2 = 4M
RCC_PLL2Config(RCC_PLL2Mul_10); // 4M * 10 = 40M
RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2,RCC_PREDIV1_Div5);// 40M / 5 = 8M
// Enable PLL2 wait stable
RCC_PLL2Cmd(ENABLE);
while((RCC->CR & RCC_CR_PLL2RDY) == 0)
{
}
RCC_PLLConfig(RCC_PLLSource_PREDIV1,RCC_PLLMul_9); // PLL 8M * 9 = 72 M
// Enable PLL1
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)
{
}
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO |
RCC_APB2Periph_GPIOA |
RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC |
RCC_APB2Periph_GPIOD |
RCC_APB2Periph_USART1 |
RCC_APB2Periph_SPI1
, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG |
RCC_APB1Periph_USART2 |
RCC_APB1Periph_SPI2 |
RCC_APB1Periph_USART3 |
RCC_APB1Periph_TIM3
//RCC_APB1Periph_TIM4 |
// RCC_APB1Periph_CAN1 |
// RCC_APB1Periph_CAN2
, ENABLE);
#if EnableWdt
RCC_LSICmd(ENABLE);//打開(kāi)LSI
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY)==RESET);//等待直到LSI穩(wěn)定
#endif
}
評(píng)論