GD32F350时钟频率配置,超频到120M

static void system_clock_120m_hxtal(void)
{
    uint32_t timeout = 0U;
    uint32_t stab_flag = 0U;

    /* enable HXTAL */
    RCU_CTL0 |= RCU_CTL0_HXTALEN;//1:使能外部 4 ~ 32 MHz 晶体振荡器 

    /* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
    do{
        timeout++;
        stab_flag = (RCU_CTL0 & RCU_CTL0_HXTALSTB); //1:HXTAL 振荡器已稳定 
    }
    while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
    /* if fail */
    if(0U == (RCU_CTL0 & RCU_CTL0_HXTALSTB)){
        return;
    }
    /* HXTAL is stable */
    /* AHB = SYSCLK */
    RCU_CFG0 |= RCU_AHB_CKSYS_DIV1; //++AHB 预分频选择 :选择 CK_SYS 系统时钟不分频
    /* APB2 = AHB/2 */
    RCU_CFG0 |= RCU_APB2_CKAHB_DIV2; //++APB2 预分频选择 :选择 AHB 时钟 2 分频 
    /* APB1 = AHB/2 */
    RCU_CFG0 |= RCU_APB1_CKAHB_DIV2; //++APB1 预分频选择 :选择 AHB 时钟 2 分频 

    
        /* PLL = HXTAL /2 * 27 = 108 MHz */
    RCU_CFG0 &= ~(RCU_CFG0_PLLSEL | RCU_CFG0_PLLMF | RCU_CFG0_PLLMF4 | RCU_CFG0_PLLDV);
        //++RCU_CFG1_PLLPRESEL     PLL 时钟源预选 :0::HXTAL 选为 PLL 时钟源
        //++RCU_CFG1_PLLMF5  PLL 倍频因子  的第五位 
    RCU_CFG1 &= ~(RCU_CFG1_PLLPRESEL | RCU_CFG1_PLLMF5); 
    RCU_CFG1 |= RCU_PLL_PREDV2;//++PLL 的输入 2 分频 
        //++1:选择 HXTAL 为 PLL 时钟 源 
        //++ RCU_PLL_MUL27  (PLL 时钟源 x 27
    //RCU_CFG0 |= (RCU_CFG0_PLLSEL | RCU_PLL_MUL27);//PLL 时钟源选择 :
        //++注意:由于外部晶振改为12M了,所以这里的 PLL倍频改为 20
        //++ 12/2*20 = 120
        RCU_CFG0 |= (RCU_CFG0_PLLSEL | RCU_PLL_MUL20);//PLL 时钟源选择 :

    /* enable PLL */
    RCU_CTL0 |= RCU_CTL0_PLLEN;

    /* wait until PLL is stable */
    while(0U == (RCU_CTL0 & RCU_CTL0_PLLSTB)){
    }

    /* select PLL as system clock */ //++选择 PLL 作为 CK_SYS 系统时钟源 
    RCU_CFG0 &= ~RCU_CFG0_SCS;
    RCU_CFG0 |= RCU_CKSYSSRC_PLL;

    /* wait until PLL is selected as system clock */
    while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
    }
}

你可能感兴趣的:(GD32F350时钟频率配置,超频到120M)