GD32VW553-IOT 基于 vscode 的 msdk 移植(基于Cmake)

移植说明

  1. 基于官网的MSDK, 将工程先分解出来, 之前的工程是BOOT+APP融合在一起了, 对于APP部分来说, BOOT相关的内容和去除, 这样我们在学习过程中结构会更清晰一点。
  2. 由于目前的MSDK结构比较复杂, 涵盖了很多的模块, 比如cmd、flash、hal、lib、net、os等, 这些模块之间有依赖关系, 需要理清楚这些模块的依赖关系, 然后再进行移植。
  3. 首先参考官方的编译设置, 构建一个初步能跑了CMakLists.txt, 能打印一些简单的版本信息
  4. 考虑到使用这款芯片主要就是用ble和wifi模块,所以直接给出完整功能的Cmake工程,后续需要裁剪直接修改即可
  5. eclipse类型的ide,查找头文件和源文件路径实在太麻烦,搜索又难用的很,最关键的是copilot没法直接aigent了,对于学习来说直接使用对个中细节把握不够清楚,知其然不知其所以然,自己手动移植一遍,也对加深工程中各个模块的相互关系,可以帮助学习

工程结构

  1. 宏定义
bash 复制代码
# C的宏定义
target_compile_definitions(stm32cubemx INTERFACE 
    CFG_RTOS
    PLATFORM_OS_FREERTOS
)
  1. 头文件路径
c 复制代码
# C的头文件
target_include_directories(stm32cubemx INTERFACE
    # MCU specific
    platform/riscv/arch
    platform/riscv/arch/boot
    platform/riscv/arch/lib
    platform/riscv/arch/ll
    platform/riscv/arch/compiler
    platform/src
    platform/src/reg
    platform/src/raw_flash
    platform/src/qspi_flash
    platform/src/dma
    platform/src/time
    platform/src/trng
    platform/src/uart
    platform/src/spi
    platform/src/spi_i2s
    platform/src/nvds
    platform/src/rf
    platform/riscv/gd32vw55x
    platform/riscv/NMSIS/Core/Include
    platform/riscv/NMSIS/DSP/Include
    platform/riscv/NMSIS/DSP/Include/dsp
    platform/GD32VW55x_standard_peripheral
    platform/GD32VW55x_standard_peripheral/Include

    # RTOS specific
    rtos/rtos_wrapper
    rtos/FreeRTOS/Source/include
    rtos/FreeRTOS/Source/portable/riscv32
    rtos/FreeRTOS/config

    # LWIP specific
    lwip/iperf3
    lwip/iperf
    lwip/lwip-2.2.0/src/include
    lwip/lwip-2.2.0/src/include/compat/posix
    lwip/lwip-2.2.0/src/include/lwip
    lwip/lwip-2.2.0/src/include/lwip/apps
    lwip/lwip-2.2.0/port
    lwip/libcoap/include
    lwip/libcoap/port

    # WiFi specific
    wifi_manager
    wifi_manager/wpas

    # FatFS specific
    FatFS/port
    FatFS/src

    # mbedTLS specific
    mbedtls/mbedtls-3.6.2/include
    mbedtls/mbedtls-3.6.2/library
    mbedtls/mbedtls-3.6.2/tests/include/spe

    # BLE specific
    ble/app
    ble/profile
    ble/profile/datatrans
    ble/profile/dis
    ble/profile/sample
    ble/profile/throughput
    ble/profile/bas
    ble/profile/ota

    # util specific
    util/include
    
    # MAIN APP
    app
    app/mqtt_app

    # Config
    config

    # ROM exported headers
    ROM-EXPORT/bootloader
    ROM-EXPORT/halcomm
    ROM-EXPORT/symbol

    # BLE SDK exported headers
    blesw/src/export

    # MAC SW exported headers
    macsw/export
    macsw/import
)
  1. 不同模块的源文件组合
bash 复制代码
# MAIN APP
file(GLOB SRC_APP_0 
    app/main.c 
    app/cmd_shell.c 
    app/atcmd.c 
    app/iperf.c 
    app/iperf3_main.c 
    app/ping.c 
    app/ota_demo.c 
    app/mqtt_cmd.c 
    lwip/libcoap/port/client-coap.c 
    lwip/libcoap/port/server-coap.c
)

# Platform specific
file(GLOB SRC_LIB_0 
    platform/GD32VW55x_standard_peripheral/Source/*.c
    platform/riscv/gd32vw55x/system_gd32vw55x.c
    platform/riscv/gd32vw55x/gd32vw55x_it.c

    platform/riscv/env/handlers.c
    platform/riscv/env/env_init.c

    platform/riscv/env/entry.S
    platform/riscv/env/start.S

    platform/riscv/arch/lib/lib_hook.c

    platform/src/uart/ble_uart.c
    platform/src/dma/dma.c
    platform/src/dsp.c
    platform/src/gd32vw55x_platform.c
    platform/src/init_rom.c
    platform/src/uart/log_uart.c
    platform/src/nvds/nvds_flash.c
    platform/src/plf_assert.c
    platform/src/qspi_flash/qspi_flash_api.c
    platform/src/raw_flash/raw_flash_api.c
    platform/src/spi_i2s/spi_i2s.c
    platform/src/spi/spi.c
    platform/src/time/systime.c
    platform/src/uart/trace_uart.c
    platform/src/trng/trng.c
    platform/src/uart/uart.c
    platform/src/wakelock.c
)

# util specific
file(GLOB SRC_LIB_1 
    util/src/*.c
)

# RTOS specific
file(GLOB SRC_LIB_2 
    rtos/FreeRTOS/Source/portable/Common/tickless_sleep.c
    rtos/FreeRTOS/Source/croutine.c
    rtos/FreeRTOS/Source/event_groups.c
    rtos/FreeRTOS/Source/list.c
    rtos/FreeRTOS/Source/queue.c
    rtos/FreeRTOS/Source/stream_buffer.c
    rtos/FreeRTOS/Source/tasks.c
    rtos/FreeRTOS/Source/timers.c
    rtos/FreeRTOS/Source/portable/MemMang/heap_4.c
    rtos/FreeRTOS/Source/portable/riscv32/port.c
    rtos/FreeRTOS/Source/portable/riscv32/portasm.S
    rtos/rtos_wrapper/wrapper_freertos.c
)

# BLE specific
file(GLOB SRC_LIB_3
    ble/profile/bas/ble_bass.c
    ble/profile/datatrans/ble_datatrans_cli.c
    ble/profile/datatrans/ble_datatrans_srv.c
    ble/profile/dis/ble_diss.c
    ble/profile/ota/ble_ota_cli.c
    ble/profile/ota/ble_ota_srv.c
    ble/profile/ble_profile_utils.c
    ble/profile/throughput/ble_throughput_cli.c
    ble/profile/throughput/ble_throughput_srv.c
    ble/profile/sample/ble_sample_cli.c
    ble/profile/sample/ble_sample_srv.c
)

# FatFS specific
file(GLOB SRC_LIB_4 
    FatFS/port/fatfs.c
    FatFS/src/diskio.c
    FatFS/src/ff.c
    FatFS/src/ffsystem.c
    FatFS/src/ffunicode.c
)

# LWIP specific
file(GLOB SRC_LIB_5 
    lwip/lwip-2.2.0/src/core/altcp_alloc.c
    lwip/lwip-2.2.0/src/core/altcp_tcp.c
    lwip/lwip-2.2.0/src/core/altcp_tcp.c
    lwip/lwip-2.2.0/src/core/dns.c
    lwip/lwip-2.2.0/src/core/def.c
    lwip/lwip-2.2.0/src/core/inet_chksum.c
    lwip/lwip-2.2.0/src/core/init.c
    lwip/lwip-2.2.0/src/core/ip.c
    lwip/lwip-2.2.0/src/core/mem.c
    lwip/lwip-2.2.0/src/core/memp.c
    lwip/lwip-2.2.0/src/core/netif.c
    lwip/lwip-2.2.0/src/core/pbuf.c
    lwip/lwip-2.2.0/src/core/raw.c
    lwip/lwip-2.2.0/src/core/stats.c
    lwip/lwip-2.2.0/src/core/sys.c
    lwip/lwip-2.2.0/src/core/tcp_in.c
    lwip/lwip-2.2.0/src/core/tcp_out.c
    lwip/lwip-2.2.0/src/core/tcp.c
    lwip/lwip-2.2.0/src/core/timeouts.c
    lwip/lwip-2.2.0/src/core/udp.c

    lwip/lwip-2.2.0/src/apps/altcp_tls/altcp_tls_mbedtls_mem.c
    lwip/lwip-2.2.0/src/apps/altcp_tls/altcp_tls_mbedtls.c
    lwip/lwip-2.2.0/src/apps/http/fs.c
    lwip/lwip-2.2.0/src/apps/http/httpd.c
    lwip/lwip-2.2.0/src/apps/lwiperf/lwiperf.c
    lwip/lwip-2.2.0/src/apps/mqtt/mqtt.c
    lwip/lwip-2.2.0/src/apps/mqtt/mqtt5.c

    lwip/lwip-2.2.0/src/api/api_lib.c
    lwip/lwip-2.2.0/src/api/api_msg.c
    lwip/lwip-2.2.0/src/api/err.c
    lwip/lwip-2.2.0/src/api/netbuf.c
    lwip/lwip-2.2.0/src/api/netdb.c
    lwip/lwip-2.2.0/src/api/netifapi.c
    lwip/lwip-2.2.0/src/api/sockets.c
    lwip/lwip-2.2.0/src/api/tcpip.c

    lwip/lwip-2.2.0/src/core/ipv4/autoip.c
    lwip/lwip-2.2.0/src/core/ipv4/dhcp.c
    lwip/lwip-2.2.0/src/core/ipv4/etharp.c
    lwip/lwip-2.2.0/src/core/ipv4/icmp.c
    lwip/lwip-2.2.0/src/core/ipv4/igmp.c
    lwip/lwip-2.2.0/src/core/ipv4/ip4_addr.c
    lwip/lwip-2.2.0/src/core/ipv4/ip4_frag.c
    lwip/lwip-2.2.0/src/core/ipv4/ip4.c

    lwip/lwip-2.2.0/src/core/ipv6/*.c

    lwip/lwip-2.2.0/port/dhcpd.c
    lwip/lwip-2.2.0/port/dnsd.c
    lwip/lwip-2.2.0/port/httpd_post.c
    lwip/lwip-2.2.0/port/sys_arch.c
    lwip/lwip-2.2.0/port/wifi_netif.c

    lwip/lwip-2.2.0/src/netif/ethernet.c

    lwip/lwip-2.2.0/demo/lwip_sockets_demo.c
)

# WiFi specific
file(GLOB SRC_LIB_6 
    wifi_manager/*.c
)

# CoAP specific
file(GLOB SRC_LIB_7 lwip/libcoap/src/*.c)
list(FILTER SRC_LIB_7 EXCLUDE REGEX ".*/(coap_io_contiki|coap_io_riot|coap_gnutls|coap_mbedtls|coap_openssl|coap_oscore|coap_proxy|coap_sha1|coap_tinydtls|coap_wolfssl)\\.c$")

# ble specific
file(GLOB SRC_LIB_8 ble/app/*.c)
list(FILTER SRC_LIB_8 EXCLUDE REGEX ".*/(atcmd_ble)\\.c$")

# mbedTLS specific
file(GLOB SRC_LIB_9
    mbedtls/demo/*.c
    mbedtls/mbedtls-3.6.2/library/*.c
)

target_sources(stm32cubemx INTERFACE
    ${SRC_APP_0}

    ${SRC_LIB_0}
    ${SRC_LIB_1}
    ${SRC_LIB_2}
    ${SRC_LIB_3}
    ${SRC_LIB_4}
    ${SRC_LIB_5}
    ${SRC_LIB_6}
    ${SRC_LIB_7}
    ${SRC_LIB_8}
    ${SRC_LIB_9}
)
  1. 需要静态链接的库和库所在路径,对应-l和-L参数
c 复制代码
# Link directories setup, -L
target_link_directories(stm32cubemx INTERFACE
    lib
    platform/riscv/NMSIS/Library/DSP/GCC
)
# Add linked libraries, -l
target_link_libraries(stm32cubemx INTERFACE
    ble
    # ble_max 
    # ble_min
    rftest 
    rf 
    wifi 
    wpas 
    m 
    nmsis_dsp_rv32imafcbp 
    iperf3
)

实际的文件路径

  1. 官方是mbl+msdk放在一个工程下面,只做msdk部分的话,有一些是可以去除的,如下图所示,基本都是从官方工程里面直接copy出来的

编译下载

  1. 和官方的几无区别,完美移植成功
  2. 后续就可以自己大刀阔斧的增删改查了
  3. 简单尝试了几个基本的命令,都非常成功

BLE命令尝试

  1. 在串口助手的终端模式下,输入图示指令,广播之后,通过手机蓝牙即可发现芯片ble,可以直接连接

github链接

https://github.com/1508912767/gd32vw553_app

相关推荐
BY组态20 小时前
【教程】如何使用Ricon组态系统快速构建监控画面
物联网·iot·web组态·组态
BY组态1 天前
【对比分析】Ricon组态系统 vs 传统组态软件
运维·物联网·web组态·组态
monsion1 天前
OpenCode 学习指南
人工智能·vscode·架构
非鱼䲆鱻䲜1 天前
vscode开发stm32添加新的头文件路径和包含源文件
ide·vscode·stm32·cmake·包含头文件·包含源文件
liurunlin8882 天前
Go环境搭建(vscode调试)
开发语言·vscode·golang
zhaoshuzhaoshu2 天前
BLE(蓝牙低功耗)连接过程详解
物联网·蓝牙·无线
搜佛说2 天前
下一代跨语言原生操作系统商业计划书
物联网·软件工程
BY组态2 天前
Ricon组态系统在实际项目中的应用案例分享
物联网·web组态·组态
Willliam_william2 天前
QEMU学习之路(11)— 使用VSCode调试qemu-system-riscv64
ide·vscode·学习
TroubleMakerQi2 天前
[虚拟机环境配置]07_Ubuntu中安装vscode教程
linux·人工智能·vscode·ubuntu