RISC-V MCU中文社区

(SES+JLink+最小系统板)开发实践

发表于 GD32VF103 MCU 2021-03-11 14:57:40
0
3841
0
环境参数:
  • Windows 10
  • JLink:V10 /6.84b
  • SES:5.40a
  • 最小系统:RTThread_DevBoard

硬件连接

焊接好RTThread版本GD32VF103VBT6最小系统板,参照电路原理图连接JTAG调试通讯引脚。
焊接时没有注意到此处关于BUG的说明,并没有做处理。BUG是关于仿真器硬件复位相关的,如果不用则没有影响。
软件配置

    启动rvstar_quick_start项目。

时钟配置
    板子出厂并没有焊接外部晶振,通过查阅GD32VF103用户手册确认芯片可以使用内部时钟作为系统时钟源。官方针对RV-STAR开发板的Demo例程是采用外部晶振作为系统时钟源的。因此需要对系统时钟配置函数进行调整。
    
    修改文件system_clock_config函数如下所示,这里为了对比方便将两种方式写在一起用条件编译将其区分,也可以单独将内部时钟配置方式提取出来实现system_clock_108m_irc8m函数并在system_clock_config函数修改调用。

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

    #ifdef  RTThread_DevBoard
    /* enable IRC8MEN */
    RCU_CTL |= RCU_CTL_IRC8MEN;

    /* wait until IRC8MEN is stable or the startup time is longer than
     * IRC8M_STARTUP_TIMEOUT */
    do {
        timeout++;
        stab_flag = (RCU_CTL & RCU_CTL_IRC8MSTB);
    } while ((0U == stab_flag) && (IRC8M_STARTUP_TIMEOUT != timeout));

    /* if fail */
    if (0U == (RCU_CTL & RCU_CTL_IRC8MSTB)) {
        while (1) {
        }
    }
    #else
    /* enable HXTAL */
    RCU_CTL |= RCU_CTL_HXTALEN;

    /* wait until HXTAL is stable or the startup time is longer than
     * HXTAL_STARTUP_TIMEOUT */
    do {
        timeout++;
        stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
    } while ((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));

    /* if fail */
    if (0U == (RCU_CTL & RCU_CTL_HXTALSTB)) {
        while (1) {
        }
    }
    /* HXTAL is stable */

    #endif
    /* AHB = SYSCLK */
    RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
    /* APB2 = AHB/1 */
    RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
    /* APB1 = AHB/2 */
    RCU_CFG0 |= RCU_APB1_CKAHB_DIV2;

    /* CK_PLL = (CK_PREDIV0) * 27 = 108 MHz */
    RCU_CFG0 &= ~(RCU_CFG0_PLLMF | RCU_CFG0_PLLMF_4);
#ifdef  RTThread_DevBoard
    RCU_CFG0 |= (RCU_PLLSRC_IRC8M_DIV2 | RCU_PLL_MUL27);
#else
    RCU_CFG0 |= (RCU_PLLSRC_HXTAL | RCU_PLL_MUL27);
#endif

    #ifdef  RTThread_DevBoard
    #else
    if (HXTAL_VALUE == 25000000) {
        /* CK_PREDIV0 = (CK_HXTAL)/5 *8 /10 = 4 MHz */
        RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PREDV1 | RCU_CFG1_PLL1MF |
                      RCU_CFG1_PREDV0);
        RCU_CFG1 |= (RCU_PREDV0SRC_CKPLL1 | RCU_PREDV1_DIV5 | RCU_PLL1_MUL8 |
                     RCU_PREDV0_DIV10);

        /* enable PLL1 */
        RCU_CTL |= RCU_CTL_PLL1EN;
        /* wait till PLL1 is ready */
        while (0U == (RCU_CTL & RCU_CTL_PLL1STB)) {
        }

        /* enable PLL1 */
        RCU_CTL |= RCU_CTL_PLL2EN;
        /* wait till PLL1 is ready */
        while (0U == (RCU_CTL & RCU_CTL_PLL2STB)) {
        }
    } else if (HXTAL_VALUE == 8000000) {
        RCU_CFG1 &= ~(RCU_CFG1_PREDV0SEL | RCU_CFG1_PREDV1 | RCU_CFG1_PLL1MF |
                      RCU_CFG1_PREDV0);

        RCU_CFG1 |= (RCU_PREDV0SRC_HXTAL | RCU_PREDV0_DIV2 | RCU_PREDV1_DIV2 |
                     RCU_PLL1_MUL20 | RCU_PLL2_MUL20);

        /* enable PLL1 */
        RCU_CTL |= RCU_CTL_PLL1EN;
        /* wait till PLL1 is ready */
        while (0U == (RCU_CTL & RCU_CTL_PLL1STB)) {
        }

        /* enable PLL2 */
        RCU_CTL |= RCU_CTL_PLL2EN;
        /* wait till PLL1 is ready */
        while (0U == (RCU_CTL & RCU_CTL_PLL2STB)) {
        }
    }
    #endif
    /* enable PLL */
    RCU_CTL |= RCU_CTL_PLLEN;

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

    /* select PLL as system clock */
    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)) {
    }
}
串口配置
    RTThread_DevBoard和RV-STAR使用的是同款100引脚GD32VF103VBT6,因此在软件是配上只需在RV-STAR工程的基础之上对功能引脚进行重新定义即可。板载CH330N USB转UART芯片,根据开发板电路图确认串口通讯引脚。
    串口初始化函数是在_premain_init()中被调用。
    修改驱动文件gd32vf103c_start.h

#ifdef  RTThread_DevBoard
/* RT-Thread board UART com port */
#define GD32_COM0                        USART0
#define GD32_COM_CLK                     RCU_USART0
#define GD32_COM_TX_PIN                  GPIO_PIN_9
#define GD32_COM_RX_PIN                  GPIO_PIN_10
#define GD32_COM_TX_GPIO_PORT            GPIOA
#define GD32_COM_RX_GPIO_PORT            GPIOA
#define GD32_COM_TX_GPIO_CLK             RCU_GPIOA
#define GD32_COM_RX_GPIO_CLK             RCU_GPIOA
#else
/* rvstar board UART com port */
#define GD32_COM0                        UART4
#define GD32_COM_CLK                     RCU_UART4
#define GD32_COM_TX_PIN                  GPIO_PIN_12
#define GD32_COM_RX_PIN                  GPIO_PIN_2
#define GD32_COM_TX_GPIO_PORT            GPIOC
#define GD32_COM_RX_GPIO_PORT            GPIOD
#define GD32_COM_TX_GPIO_CLK             RCU_GPIOC
#define GD32_COM_RX_GPIO_CLK             RCU_GPIOD
#endif
调试运行
打开串口终端工具(2种方式)

    文中代码是在RV-STAR项目的基础上修改的,修改部分以条件编译进行区分,因此在工程设置中增加宏定义RTThread_DevBoard。
    设置调试器选项为J-Link。
    启动调试,可以正常停在断点处。
    继续运行正常打印Print信息。

第4次编辑上传,总报非法图片错误,报错之后编辑记录全部清除QAQ,不知道这次能不能成功。。。
喜欢0
用户评论
moo

moo 实名认证

懒的都不写签名

积分
问答
粉丝
关注
  • RV-STAR 开发板
  • RISC-V处理器设计系列课程
  • 培养RISC-V大学土壤 共建RISC-V教育生态
RV-STAR 开发板