我们开发ARM一般会使用Keil MDK,IAR等工具,但有时这些工具又不满足我们的需求,现在给大家介绍另一种方案
类型工具
代码编辑器VS Code
编译器arm-none-eabi-gcc
调试器arm-none-eabi-gdb
ARM Debug工具openOCD
VS Code插件Cortex-Debug(用于读取launch.json配置文件进行开始调试)
-C/C++(C代码提示、自动补全等)
-Arm assembly(ARM汇编代码提示、自动补全等)

1.VS Code安装

前往官网Visual Studio Code - Code Editing. Redefined下载并安装

2.插件安装

在插件商店搜索并安装C/C++, Cortex-Debug, Arm assembly

3.编译工具链

Arm GNU Toolchain Downloads

下载后解压到某个目录,之后会在VS Code中配置这个目录

4.ARM Debug工具

此工具配合Cortex-Debug使用
OpenOCD工具在github上有镜像仓库,可访问此仓库下载最新的发布OpenOCD

同样下载后解压到某一目录,之后会在VS Code中配置这个目录

5.配置VS Code工程

形如其他GCC工程类似,可以使用makefile来自动构建,当然也可以使用其他方法
下面用STM32工程为例:
先用STM32CubeMX生成Makefile工程,使用VS Code打开工程

(1)配置代码自动提示

c_cpp_properties.json文件
添加"compilerPath"属性,值为:编译工具链目录/bin/arm-none-eabi-gcc
示例:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "USE_HAL_DRIVER",
                "STM32H750xx",
                "mfloat-abi=hard",
                "__GNUC__"
            ],
            "cStandard": "c17",
            "cppStandard": "c++17",
            "compilerPath": "D:\\program\\gcc-arm-11.2-2022.02-mingw-w64-i686-arm-none-eabi\\bin\\arm-none-eabi-gcc.exe",
            "intelliSenseMode": "windows-gcc-arm"
        },
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "USE_HAL_DRIVER",
                "STM32H750xx",
                "mfloat-abi=hard",
                "__GNUC__"
            ],
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-arm"
        }
    ],
    "version": 4
}

(2)配置调试

launch.json文件示例:

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Cortex Debug(Linux)",
            "cwd": "${workspaceRoot}/bsp/stm32h750-art-pi",
            "preLaunchTask": "build",
            "executable": "build/stm32h750-art-pi.elf",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "openocd",
            "interface": "swd",
            "device": "STM32H750XB",
            "configFiles": [
                "interface/stlink.cfg",
                "target/stm32h7x.cfg"
            ]
        },
        {
            "name": "Cortex Debug(Windows)",
            "cwd": "${workspaceRoot}/bsp/stm32h750-art-pi",
            "preLaunchTask": "build",
            "executable": "build/stm32h750-art-pi.elf",
            "request": "launch",
            "showDevDebugOutput": "both",
            "armToolchainPath": "D:\\program\\gcc-arm-11.2-2022.02-mingw-w64-i686-arm-none-eabi\\bin",
            "type": "cortex-debug",
            "servertype": "openocd",
            "serverpath": "D:\\program\\openocd-v0.11.0-i686-w64-mingw32\\bin\\openocd.exe",
            "interface": "swd",
            "device": "STM32H750XB",
            "configFiles": [
                "interface/stlink.cfg",
                "target/stm32h7x.cfg"
            ]
        }
    ]
}
最后修改:2022 年 04 月 28 日
如果觉得我的文章对你有用,请随意赞赏