萤火工场 GD32VW553-IOT
分享作者:user202505317214
评测品牌:萤火工场
评测型号:GD32VW553-IOT
发布时间:2025-07-07 10:48:53
0
前言
使用vscode+xmake编译,点灯
开源口碑分享内容

## 一、下载必要的文件

### 编译工具链(可以添加到环境变量PATH)

- xmake: https://github.com/xmake-io/xmake/releases/

- gcc:   https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases

### 烧写工具

- programmer:  https://www.gd32mcu.com/download/agree/box_id/8/document_id/245/path_type/1

### 固件库

https://www.gd32mcu.com/download/agree/box_id/12/document_id/505/path_type/1

## 二、创建项目并编写代码

### 项目结构

│  .clangd

│  xmake.lua

├─App

│      gd32vw55x_it.c

│      gd32vw55x_it.h

│      main.c

│      systick.c

│      systick.h

└─Drivers

   ├─GD32VW55x_standard_peripheral

   │  │  gd32vw55x.h

   │  │  gd32vw55x_libopt.h

   │  │  LICENSE.TXT

   │  │  makefile

   │  │  sources.mk

   │  │  system_gd32vw55x.c

   │  │  system_gd32vw55x.h

   │  │

   │  ├─Include

   │  │      gd32vw55x_adc.h

   │  │      gd32vw55x_cau.h

   │  │      gd32vw55x_crc.h

   │  │      gd32vw55x_dbg.h

   │  │      gd32vw55x_dma.h

   │  │      gd32vw55x_eclic.h

   │  │      gd32vw55x_efuse.h

   │  │      gd32vw55x_exti.h

   │  │      gd32vw55x_fmc.h

   │  │      gd32vw55x_fwdgt.h

   │  │      gd32vw55x_gpio.h

   │  │      gd32vw55x_hau.h

   │  │      gd32vw55x_i2c.h

   │  │      gd32vw55x_pkcau.h

   │  │      gd32vw55x_pmu.h

   │  │      gd32vw55x_qspi.h

   │  │      gd32vw55x_rcu.h

   │  │      gd32vw55x_rtc.h

   │  │      gd32vw55x_spi.h

   │  │      gd32vw55x_syscfg.h

   │  │      gd32vw55x_timer.h

   │  │      gd32vw55x_trng.h

   │  │      gd32vw55x_usart.h

   │  │      gd32vw55x_wwdgt.h

   │  │

   │  └─Source

   │          gd32vw55x_adc.c

   │          gd32vw55x_cau.c

   │          gd32vw55x_cau_aes.c

   │          gd32vw55x_cau_des.c

   │          gd32vw55x_cau_tdes.c

   │          gd32vw55x_crc.c

   │          gd32vw55x_dbg.c

   │          gd32vw55x_dma.c

   │          gd32vw55x_eclic.c

   │          gd32vw55x_efuse.c

   │          gd32vw55x_exti.c

   │          gd32vw55x_fmc.c

   │          gd32vw55x_fwdgt.c

   │          gd32vw55x_gpio.c

   │          gd32vw55x_hau.c

   │          gd32vw55x_hau_sha_md5.c

   │          gd32vw55x_i2c.c

   │          gd32vw55x_pkcau.c

   │          gd32vw55x_pmu.c

   │          gd32vw55x_qspi.c

   │          gd32vw55x_rcu.c

   │          gd32vw55x_rtc.c

   │          gd32vw55x_spi.c

   │          gd32vw55x_syscfg.c

   │          gd32vw55x_timer.c

   │          gd32vw55x_trng.c

   │          gd32vw55x_usart.c

   │          gd32vw55x_wwdgt.c

   │

   ├─RISCV

   │  │  LICENSE.TXT

   │  │

   │  ├─drivers

   │  │      core_compatiable.h

   │  │      core_feature_base.h

   │  │      core_feature_cache.h

   │  │      core_feature_dsp.h

   │  │      core_feature_eclic.h

   │  │      core_feature_fpu.h

   │  │      core_feature_pmp.h

   │  │      core_feature_timer.h

   │  │      nmsis_compiler.h

   │  │      nmsis_core.h

   │  │      nmsis_gcc.h

   │  │      nmsis_version.h

   │  │      riscv_bits.h

   │  │      riscv_encoding.h

   │  │

   │  ├─env_Eclipse

   │  │      entry.S

   │  │      GD32VW553xI.lds

   │  │      GD32VW553xM.lds

   │  │      handlers.c

   │  │      init.c

   │  │      start.S

   │  │      your_printf.c

   │  │

   │  └─stubs

   │          close.c

   │          fstat.c

   │          isatty.c

   │          lseek.c

   │          read.c

   │          sbrk.c

   │          stub.h

   │          write.c

   │          write_hex.c

   │          _exit.c

   │

   └─Utilities

           gd32vw553h_eval.c

           gd32vw553h_eval.h

### 创建项目操作步骤

1. 在项目目录下创建App和Drivers文件夹

2. 将固件库中的Firmware文件夹中的两个文件夹和固件库中的Utilities文件夹复制到Drivers中

3. 将固件库中的Template文件夹中的gd32vw55x_libopt.h复制到Drivers/GD32VW55x_standard_peripheral中

4. 将固件库中的Template文件夹中的其他头文件和源文件添加到App中

5. 在项目目录下添加xmake.lua, sdkdir改为riscv-gcc路径

add_rules("mode.debug", "mode.release")
add_rules("plugin.compile_commands.autoupdate", {outputdir = "build"})

toolchain("riscv-gcc")
    set_kind("standalone")
    set_sdkdir("D:/xpack-riscv-none-elf-gcc")
    add_cxflags("-march=rv32imafd", "-mabi=ilp32d")
    add_cxflags("-ffunction-sections", "-fdata-sections")
    add_cxflags("-Wall", "-Wextra")
    add_asflags("-march=rv32imafd", "-mabi=ilp32d")
    add_cxflags("-ffunction-sections", "-fdata-sections")
    add_ldflags("-march=rv32imafd", "-mabi=ilp32d")
    add_ldflags("-nostartfiles", "-Wl,--gc-sections", "--specs=nano.specs", "--specs=nosys.specs")

target("spl")
    set_kind("static")
    set_toolchains("riscv-gcc")
    add_defines("USE_STDPERIPH_DRIVER")
    add_files("Drivers/Utilities/*.c", "Drivers/GD32VW55x_standard_peripheral/*.c", "Drivers/GD32VW55x_standard_peripheral/Source/*.c", "Drivers/RISCV/env_Eclipse/*.S", "Drivers/RISCV/env_Eclipse/*.c", "Drivers/RISCV/stubs/*.c")
    add_includedirs("Drivers/Utilities", "Drivers/GD32VW55x_standard_peripheral", "Drivers/GD32VW55x_standard_peripheral/Include", "Drivers/RISCV/drivers", "Drivers/RISCV/stubs", { public = true })
    add_ldflags("-T Drivers/RISCV/env_Eclipse/GD32VW553xM.lds")

target("test.elf")
    set_kind("binary")
    set_toolchains("riscv-gcc")
    set_languages("c23")
    add_files("App/*.c")
    add_includedirs("App")
    add_deps("spl")
    -- 构建后生成hex和bin文件
    after_build(function (target)
        os.execv("riscv-none-elf-objcopy", {"-O", "ihex", target:targetfile(), target:targetfile() .. ".hex"})
        os.execv("riscv-none-elf-objcopy", {"-O", "binary", target:targetfile(), target:targetfile() .. ".bin"})
    end)

### 编写点灯程序

#include "gd32vw55x.h"
#include "systick.h"

int main(void)
{
    systick_config();

    /* enable the LED clock */
    rcu_periph_clock_enable(RCU_GPIOA);

    /* configure LED GPIO port */
    gpio_mode_set(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_4);

    while(1) {
        gpio_bit_set(GPIOA, GPIO_PIN_4);
        delay_1ms(1000);

        gpio_bit_reset(GPIOA, GPIO_PIN_4);
        delay_1ms(1000);
    }
}

### xmake构建

xmake f -p cross -a riscv -m debug
xmake

### 添加.clangd文件以使clangd正常工作(可选的操作)

CompileFlags:
    Remove: [-m*]

## 三、使用烧录工具烧录

使用xmake构建生成的bin文件烧录

全部评论
暂无评论
0/144