{"id":5970,"date":"2024-08-24T20:01:01","date_gmt":"2024-08-24T12:01:01","guid":{"rendered":""},"modified":"2024-08-24T20:01:01","modified_gmt":"2024-08-24T12:01:01","slug":"gd32f303\u65f6\u949f\u914d\u7f6e_gd32\u5b9a\u65f6\u5668\u4e2d\u65ad","status":"publish","type":"post","link":"https:\/\/mushiming.com\/5970.html","title":{"rendered":"gd32f303\u65f6\u949f\u914d\u7f6e_gd32\u5b9a\u65f6\u5668\u4e2d\u65ad"},"content":{"rendered":"

static void system_clock_120m_hxtal(void)
{
\n
    uint32_t timeout = 0U;
    uint32_t stab_flag = 0U;<\/p>\n

    \/* enable HXTAL *\/
    RCU_CTL0 |= RCU_CTL0_HXTALEN;\/\/1\uff1a\u4f7f\u80fd\u5916\u90e8 4 ~ 32 MHz \u6676\u4f53\u632f\u8361\u5668 <\/p>\n

    \/* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT *\/
    do{
\n
        timeout++;
        stab_flag = (RCU_CTL0 & RCU_CTL0_HXTALSTB); \/\/1\uff1aHXTAL \u632f\u8361\u5668\u5df2\u7a33\u5b9a 
    }
    while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
    \/* if fail *\/
    if(0U == (RCU_CTL0 & RCU_CTL0_HXTALSTB)){
\n
        return;
    }
    \/* HXTAL is stable *\/
    \/* AHB = SYSCLK *\/
    RCU_CFG0 |= RCU_AHB_CKSYS_DIV1; \/\/++AHB \u9884\u5206\u9891\u9009\u62e9 \uff1a\u9009\u62e9 CK_SYS \u7cfb\u7edf\u65f6\u949f\u4e0d\u5206\u9891
    \/* APB2 = AHB\/2 *\/
    RCU_CFG0 |= RCU_APB2_CKAHB_DIV2; \/\/++APB2 \u9884\u5206\u9891\u9009\u62e9 \uff1a\u9009\u62e9 AHB \u65f6\u949f 2 \u5206\u9891 
    \/* APB1 = AHB\/2 *\/
    RCU_CFG0 |= RCU_APB1_CKAHB_DIV2; \/\/++APB1 \u9884\u5206\u9891\u9009\u62e9 \uff1a\u9009\u62e9 AHB \u65f6\u949f 2 \u5206\u9891 <\/p>\n

    
        \/* PLL = HXTAL \/2 * 27 = 108 MHz *\/
    RCU_CFG0 &= ~(RCU_CFG0_PLLSEL | RCU_CFG0_PLLMF | RCU_CFG0_PLLMF4 | RCU_CFG0_PLLDV);
        \/\/++RCU_CFG1_PLLPRESEL     PLL \u65f6\u949f\u6e90\u9884\u9009 \uff1a0:\uff1aHXTAL \u9009\u4e3a PLL \u65f6\u949f\u6e90
        \/\/++RCU_CFG1_PLLMF5  PLL \u500d\u9891\u56e0\u5b50  \u7684\u7b2c\u4e94\u4f4d 
    RCU_CFG1 &= ~(RCU_CFG1_PLLPRESEL | RCU_CFG1_PLLMF5); 
    RCU_CFG1 |= RCU_PLL_PREDV2;\/\/++PLL \u7684\u8f93\u5165 2 \u5206\u9891 
        \/\/++1\uff1a\u9009\u62e9 HXTAL \u4e3a PLL \u65f6\u949f \u6e90 
        \/\/++ RCU_PLL_MUL27  (PLL \u65f6\u949f\u6e90 x 27
    \/\/RCU_CFG0 |= (RCU_CFG0_PLLSEL | RCU_PLL_MUL27);\/\/PLL \u65f6\u949f\u6e90\u9009\u62e9 \uff1a
        \/\/++\u6ce8\u610f\uff1a\u7531\u4e8e\u5916\u90e8\u6676\u632f\u6539\u4e3a12M\u4e86\uff0c\u6240\u4ee5\u8fd9\u91cc\u7684 PLL\u500d\u9891\u6539\u4e3a 20
        \/\/++ 12\/2*20 = 120
        RCU_CFG0 |= (RCU_CFG0_PLLSEL | RCU_PLL_MUL20);\/\/PLL \u65f6\u949f\u6e90\u9009\u62e9 \uff1a<\/p>\n

    \/* enable PLL *\/
    RCU_CTL0 |= RCU_CTL0_PLLEN;<\/p>\n

    \/* wait until PLL is stable *\/
    while(0U == (RCU_CTL0 & RCU_CTL0_PLLSTB)){
\n
    }<\/p>\n

    \/* select PLL as system clock *\/ \/\/++\u9009\u62e9 PLL \u4f5c\u4e3a CK_SYS \u7cfb\u7edf\u65f6\u949f\u6e90 
    RCU_CFG0 &= ~RCU_CFG0_SCS;
    RCU_CFG0 |= RCU_CKSYSSRC_PLL;<\/p>\n

    \/* wait until PLL is selected as system clock *\/
    while(0U == (RCU_CFG0 & RCU_SCSS_PLL)){
\n
    }
}<\/p>\n","protected":false},"excerpt":{"rendered":"gd32f303\u65f6\u949f\u914d\u7f6e_gd32\u5b9a\u65f6\u5668\u4e2d\u65adstaticvoidsystem_clock_120m_hxtal(void){uint32_ttimeout=0U;uint32_tstab_flag=0U;\/*enab...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5970"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=5970"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5970\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=5970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=5970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=5970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}