MM32F013x内部集成了48Mhz的RC时钟,同时也有PLL,所以,这里采用PLL倍频内部RC时钟的方式,产生72MHZ的系统时钟。
上代码:
void clk_init(void)
{
u8 temp=0;
RCC->CR |= RCC_CR_HSION;
while(!(RCC->CR & RCC_CR_HSIRDY));
// HSI/4 is the input clock for pll
RCC->CFGR &= ~RCC_CFGR_PLLSRC;
//set pll mul
RCC->CR &= ~RCC_CR_PLLDIV;// PLLDIV=0,M=1
RCC->CR &= ~(0x1f << 26);//PLLMUL=5,N=6
RCC->CR |= (6 - 1) << 26;
RCC->CFGR |= RCC_CFGR_HPRE_DIV1;//AHB factor
RCC->CFGR |= RCC_CFGR_PPRE1_DIV2;//APB1 factor
RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;//APB2 factor
FLASH->ACR = FLASH_ACR_LATENCY_2 | FLASH_ACR_PRFTBE;//important
//enable pll
RCC->CR |= RCC_CR_PLLON;
while(!(RCC->CR & RCC_CR_PLLRDY));
// select pll as system clock
RCC->CFGR &= ~RCC_CFGR_SW;
RCC->CFGR |= RCC_CFGR_SW_PLL;
//wait unitl system clock is switched to pll
while(temp != 0x02)
{
temp = RCC->CFGR >> 2;
temp &= 0x03;
}
}