VSCode下STM32开发环境搭建
需要的软件
make-3.81
https://udomain.dl.sourceforge.net/project/gnuwin32/make/3.81/make-3.81.exe
arm-none-eabi-gcc
https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads https://links.jianshu.com/go?to=https%3A%2F%2Fdeveloper.arm.com%2Fopen- source%2Fgnu-toolchain%2Fgnu-rm%2Fdownloads
STM32CubeMX
https://www.st.com/zh/development-tools/stm32cubemx.html
OpenOCD
https://gnutoolchains.com/arm-eabi/openocd/
https://links.jianshu.com/go?to=https%3A%2F%2Fgnutoolchains.com%2Farm- eabi%2Fopenocd%2F
可下载安装版文件自动配置环境变量,或将压缩包解压后,一般都将解压出目录下的“bin”文件夹添加到PATH环境变量即可
检测环境变量配置是否可用,在命令行里运行:(有信息输出则配置成功)
gcc -v
arm-none-eabi-gcc -v
make -v
必须的插件
C/C++ for Visual Studio Code
C/C++ Extension Pack
C/C++ Themes
CMake
Cortex-Debug
debug-tracker-vscode
MemoryView
Peripheral Viewer
RTOS Views
STM32CubeMx自动生成makefile文件,无需cmake再生成,若添加c文件h文件可修改makefile即可,在终端中运行make进行编译:
OpenOCD可用如下命令:
#第一个f参数指定调试器,第二个f参数指定芯片,都到下载得OpenOCD安装目录去找对应文件 #注意xxxx.hex与自己的项目生成的build目录下hex文件对应
openocd -f ./OpenOCD/share/openocd/scripts/interface/cmsis-dap.cfg -f./OpenOCD/share/openocd/scripts/target/stm32f1x.cfg -c “program build/STM32F103CB.hex verify reset exit”
配置在线调试
注意项目工程不能有中文目录,否则运行 openocd 莫名失败,运行调试需要在编译、下载完成后
菜单栏中选择运行和调试,点击 “创建 launch.json 文件”,选择 “Cortex Debug”
再添加具体的OpenOCD调试(添加配置)
需要修改三个参数信息:
- build目录下生成的 xxx.elf 文件名要匹配
- 调试器配置文件(在OpenOCD解压缩后的目录下)
- 芯片型号配置文件(在OpenOCD解压缩后的目录下)
- SVD 文件路径(仿真寄存器描述)获取方式:在Keil.STM32Fxxx_DFP.x.x.x.pack 文件解压缩后的目录 “CMSIS/SVD”
参考配置信息如下:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
“version”: “0.2.0”,
“configurations”: [
{
“cwd”: “${workspaceRoot}”,
“executable”: “./build/STM32F103CB.elf”,
“name”: “Debug with OpenOCD”,
“request”: “launch”,
“type”: “cortex-debug”,
“servertype”: “openocd”,
“configFiles”: [
“./OpenOCD/share/openocd/scripts/interface/cmsis-dap.cfg”,
“./OpenOCD/share/openocd/scripts/target/stm32f1x.cfg”
],
“searchDir”: [],
“runToEntryPoint”: “main”,
“showDevDebugOutput”: “none”,
“svdFile”: “./SVD/STM32F103xx.svd”
}
]
}
点击运行和调试菜单栏,选择调试 “Debug with OpenOCD” 即可在线调试: