基于VScode搭建STM32运行环境
所需软件
- vscode: 是我们的代码编辑器
- STM32CubeMX: 是我们配置和初始化的软件
- OpenOCD: 是开源片上调试器, 他下载完是一个压缩包, 需要配置环境
- arm-none-eabi-gcc: 是编译器, 需要配置环境
- make: 是编译工具
- stmf4: SVD 文件
插件
- Arm Assembly
- C/C++
- C/C++ Snippets
- Cortex-Debug
生成一个 STM32CubeMX 工程
设置生成为makefile文件
用vscode打开这个生成的工程文件
在终端运行make -j4
, 以4核心编译代码
配置下载
task文件
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "download",
"type": "shell",
"command": "openocd",
"args": [
"-f",
"C:/Users/Administrator/Documents/Tools/OpenOCD/share/openocd/scripts/interface/stlink-v2.cfg",
"-f",
"C:/Users/Administrator/Documents/Tools/OpenOCD/share/openocd/scripts/target/stm32f4x.cfg",
"-c",
"program build/a.elf verify reset exit"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$gcc"
}
]
}
使用快捷方式 ctrl+shift+b
执行download
Cortex Debug配置
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"cwd": "${workspaceRoot}",
"executable": "./build/a.elf",
"name": "STM32 Debug",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "STM32F407VE",
"configFiles": [
"C:/Users/Administrator/Documents/Tools/OpenOCD/share/openocd/scripts/interface/stlink-v2.cfg",
"C:/Users/Administrator/Documents/Tools/OpenOCD/share/openocd/scripts/target/stm32f4x.cfg",
],
"svdFile": "./STM32F407.svd"
},
]
}
C/C++报错
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/Drivers/STM32F4xx_HAL_Driver/Inc",
"${workspaceFolder}/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy",
"${workspaceFolder}/Drivers/CMSIS/Device/ST/STM32F4xx/Include",
"${workspaceFolder}/Drivers/CMSIS/Include",
"${workspaceFolder}/Drivers/CMSIS/Include",
"${workspaceFolder}/Core/Inc",
"C:\\Program Files (x86)\\GNU Arm Embedded Toolchain\\10 2021.10\\arm-none-eabi\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"USE_HAL_DRIVER",
"STM32F407xx"
],
"compilerPath": "C:\\Program Files (x86)\\GNU Arm Embedded Toolchain\\10 2021.10\\bin\\arm-none-eabi-gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x86"
}
],
"version": 4
}