1)PLL倍频这样改:
8M:
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9);//8*9=72
12M:
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL6);//12*6=72
库函数:void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t RCC_PLLMul)
例:RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_6);
2)stm32f10x.h中修改:
8M:
#define HSE_Value ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
12M:
#define HSE_Value ((uint32_t)12000000) /*!< Value of the External oscillator in Hz */
void RCC_Configuration(void)
{
/* RCC system reset(for debug purpose) */
RCC_DeInit();
RCC_HSICmd(ENABLE); //打开内部高速时钟
//等待HSI准备好
while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //开启FLASH预取指功能
//FLASH时序控制
//推荐值:SYSCLK = 0~24MHz Latency=0
// SYSCLK = 24~48MHz Latency=1
// SYSCLK = 48~72MHz Latency=2
FLASH_SetLatency(FLASH_Latency_2);
RCC_HCLKConfig(RCC_SYSCLK_Div1); //设置HCLK(AHB时钟)=SYSCLK
RCC_PCLK2Config(RCC_HCLK_Div1); //PCLK2(APB2) = HCLK
RCC_PCLK1Config(RCC_HCLK_Div1); //PCLK1(APB1) = HCLK
//PLL设置 SYSCLK/2 * 12 = 4*12 = 48MHz
RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_12);
//启动PLL
RCC_PLLCmd(ENABLE);//如果PLL被用于系统时钟,不能被DISABLE
//等待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);
}