VSCode+OpenOCD+STM32CubeMX开发与调试STM32单片机环境
需要的东西
需要的软件:
名称 | 备注 | 下载地址 |
---|---|---|
gcc-arm-none-eabi | 编译代码 | https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads |
make | 管理代码编译顺序 | http://gnuwin32.sourceforge.net/packages/make.htm http://www.equation.com/servlet/equation.cmd?fa=make |
openocd | 烧录与调试 | https://gnutoolchains.com/arm-eabi/openocd/ |
vscode | 编辑代码 | https://code.visualstudio.com/ |
stlink驱动 | 或者其他调试器驱动,取决于你的调试器型号 | www.st.com/en/development-tools/stsw-link009.html |
stm32cubemx | 用来生成stm32初始工程 | https://www.st.com/zh/development-tools/stm32cubemx.html |
前面三个需要以配置环境变量的形式安装,后面的有安装包. |
VSCode插件
名称 | 备注 |
---|---|
C/C++ | 编译代码 |
Cortex-Debug | 配合OpenOCD调试与烧录 |
需要的硬件:
STM32开发板 STLINK(或其他usb转jtag工具)
新建工程需要添加的文件
VSCode配置文件(放在.vscode目录):
launch.json
{
"version": "0.2.0",
"configurations": [
{//本地调试
"name": "Local Debug",
"cwd": "${workspaceRoot}",
"executable": "./build/${workspaceRootFolderName}.elf",
"request": "launch",
"type": "cortex-debug",
"preLaunchTask": "build",
"servertype": "openocd",
//"device": "STM32H750VB", //这个不是很重要,写不写应该无所谓
"configFiles": [
"openocd.cfg"
]
},
{ //另一种调试方案,需要用StartOCD单独打开OCD.调试的时候不会进入startup_xxx.s文件,支持通过网络调试
//有一个美中不足之处:需要在装载文件的地方手工指定全路径
"name": "Remote Debug",
"type": "cppdbg",
"request": "launch",
"miDebuggerPath": "arm-none-eabi-gdb.exe",
"targetArchitecture": "arm",
"program": "${workspaceFolder}/build/${workspaceRootFolderName}.elf",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "装载文件",
"text": "file 'E:/projects/Folder/${workspaceRootFolderName}/build/${workspaceRootFolderName}.elf'",
//"ignoreFailures": true //忽略异常
},
{
"text": "target remote localhost:3333"
},
{
"text": "monitor reset"
},
{
"text": "monitor halt"
},
{
"text": "load"
}
],
"launchCompleteCommand": "None",
"externalConsole": true,
"cwd": "${workspaceFolder}"
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make -j8"
},
{
"label": "startocd",
"type": "shell",
"command": "cmd StartOCD.bat"
}
]
}
Openocd配置文件(放在工程根目录)
openocd.cfg
# 需要根据jtag工具修改
source [find interface/stlink.cfg]
# 需要根据要调试的芯片修改
source [find target/stm32h7x.cfg]
# use hardware reset, connect under reset
# connect_assert_srst needed if low power mode application running (WFI...)
# reset_config srst_only srst_nogate connect_assert_srst
reset_config none
StartOCD.bat
clear
openocd -f openocd.cfg -c init -c "reset halt"
::一些配置以及烧录语句,根据情况使用:
::-c "flash write_image erase E:/projects/Folder/STM32H7Template/build/STM32H7Template.bin 0x8000000"
::-c "stm32h7x unlock 0"
"随笔"类型下的内容为原创,转载请注明来源. http://www.cnblogs.com/DragonStart/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?