基于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
}
参考资料
原文地址:http://www.cnblogs.com/Ahtelek/p/VScode-Configuration-STM32.html
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,请务用于商业用途!
3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员!
8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载
声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性