• 1-VSCode搭建GD32开发环境


    一、使用VSCode开发GD32的原因

    1-单片机开发用的最多的IDE为Keil,而Keil为商用软件,并非开源,而且只支持windows环境,介于当前关系,有断供的风险在。

    2-其他IDE类似第1条。

    3-VSCode为开源的编辑器,不存在授权一说,界面比较简约和优雅。可扩展性强。

     

    二、VSCode开发环境搭建

    下面用GD32F303介绍下环境的搭建。

    1-下载VSCode: 参考网址https://code.visualstudio.com/docs/setup/setup-overview

    2-下载编译工具arm-none-eabi-gcc: 点击https://developer.arm.com/downloads/-/gnu-rm

    3-安装工具pyocd: pip3 install pyocd: 安装完毕后检查pyocd版本:pyocd --version,如果遇到PyYAML问题可pip install --ignore-installed PyYAML

    4-安装VSCode扩展Cortex-Debug: 打开VSCode并搜索Cortex-Debug

    5-安装c、c++支持: 打开VSCode并搜索c/c++

    5-下载实例程序: 打开兆易官网https://www.gd32mcu.com,点击资料下载-开发板资料,点击左边GD32F3 MCU,选择GD32F30x Demo Suites

    6-打开实例程序: 解压下载好的GD32F30x Demo Suites。点击GD32303B_START_Demo_Suites,找到 Projects文件夹里的示例01_GPIO_Running_LED。将整个文件夹拖入VSCode.

    7-导入GD3230系列库函数: 点击GD32303B_START_Demo_Suites, 把GD32F30x_Firmware_Library里的CMSIS和GD32F30x_standard_peripheral拖入VSCode

     

    三、生产Makefile文件

    在Linux环境或mac环境下,使用GNU make来构建和管理自己的工程。整个工程的编译只需要一个命令就可以完成编译、连接以至于最后的执行

    1-在本案例里,使用python脚本toMakefile.py来产生makefile文件

    toMakefile.py脚本如下:

    import os

    def main():
    cFileList = []
    hPathList = []
    sFileList = []
    ldFileList = []

    for root,dirs,files in os.walk("./"):
    for file in files:
    if file.endswith(".c"):
    cFile = os.path.join(root,file)#.decode('gbk').encode('utf-8')
    cFileList.append(cFile)
    if file.endswith(".h"):
    hPath = os.path.join(root)#.decode('gbk').encode('utf-8')
    if hPathList.count(hPath) == 0:
    hPathList.append(hPath)
    if file.endswith(".s"):
    sFile = os.path.join(root,file)#.decode('gbk').encode('utf-8')
    sFileList.append(sFile)
    if file.endswith(".ld"):
    ldFile = os.path.join(root,file)#.decode('gbk').encode('utf-8')
    ldFileList.append(ldFile)
    print(cFileList)
    print(hPathList)
    print(sFileList)
    print(ldFileList)

    cFileStr = ""
    hPathStr = ""
    sFileStr = ""
    ldFileStr = ""
    for listStr in cFileList:
    # cFileStr += " \\\n" + listStr
    cFileStr += "C_SOURCES += " + listStr + "\n"
    for listStr in hPathList:
    # hPathStr += " \\\n-I" + listStr
    hPathStr += "C_INCLUDES += -I" + listStr + "\n"
    for listStr in sFileList:
    # sFileStr += " \\\n" + listStr
    sFileStr += "ASM_SOURCES += " + listStr + "\n"
    for listStr in ldFileList:
    # ldFileStr += " \\\n" + listStr
    ldFileStr += "LDSCRIPT += " + listStr + "\n"

    try:
    f = open("./Makefile.template", "r")
    fileStr = f.read()
    f.close()
    fileStr = fileStr.replace("@@C_SOURCES@@", cFileStr)
    fileStr = fileStr.replace("@@C_INCLUDES@@", hPathStr)
    fileStr = fileStr.replace("@@ASM_SOURCES@@", sFileStr)
    fileStr = fileStr.replace("@@LDSCRIPT@@", ldFileStr)
    f = open("./Makefile", "w")
    f.write(fileStr)#.decode('gbk').encode('utf-8'))
    f.close()
    finally:
    f.close()


    if __name__ == '__main__':
    main()

    2-代码编译

    在项目终端下输入make,再回车,之后会看到项目目录出现build文件夹,即编译完成

     

    四、代码调试

    使用USB线连接上开发板,点击VSCode上的运行和调试,再点击开始调试, 即可进入调试状态

     

    五、参考文献

    1-极术社区 LJL 《【GD32F310开发板试用】MAC开发&调试环境搭建》

    2-简书 _空格键_  《使用VS Code开发单片机程序》

     

     

     

     

         

  • 相关阅读:
    Allegro基本规则设置指导书之Electrical Differentail Pair
    css引入
    17.0、C语言——指针详解(3)
    使用python提取轮廓做定制的毛笔字帖
    【小月电子】FPGA开发板(XLOGIC_V1)系统学习教程-LESSON9简易测试系统
    [附源码]计算机毕业设计智能衣橱APPSpringboot程序
    梦开始的地方 —— C语言常用字符函数汇总
    群晖NAS使用Docker部署WPS Office结 合内网穿透实现远程编辑本地文档
    仓库管理系统:GitLab
    电气工程中需要理解的基本原理
  • 原文地址:https://www.cnblogs.com/zhenghaimin/p/16727780.html