跳转到内容
新建笔记

STM32H7 + VS Code + OpenOCD + STLink 完整配置教程

  1. 前置要求
  2. 工具安装
  3. 项目配置文件
  4. 配置步骤
  5. 验证测试
  6. 常见问题
  7. 使用方法

  • STM32H7 开发板(本教程以 STM32H743ZIT6 为例)
  • STLink V2/V3 调试器
  • USB 数据线
  • Windows 10/11
  • VS Code 最新版本
  • Git Bash(可选,用于命令行操作)

作用:编译 STM32 C/C++ 代码

推荐版本:gcc-arm-none-eabi

安装路径示例:D:/program/gcc-arm-none-eabi/

安装步骤:

  1. 下载 ARM GCC 工具链
  2. 解压到指定目录(避免中文路径)
  3. 记录 bin 目录路径,例如:D:/program/gcc-arm-none-eabi/bin

验证安装:

终端窗口
# 打开命令行,测试
D:/program/gcc-arm-none-eabi/bin/arm-none-eabi-gcc.exe --version

作用:调试服务器,连接 GDB 和硬件调试器

推荐版本:xPack OpenOCD

安装路径示例:D:/program/xpack-openocd/

安装步骤:

  1. 下载 xPack OpenOCD
  2. 解压到指定目录(避免中文路径)
  3. 记录 bin 目录路径,例如:D:/program/xpack-openocd/bin

验证安装:

终端窗口
# 打开命令行,测试
D:/program/xpack-openocd/bin/openocd.exe --version

作用:构建系统

安装步骤:

  1. 下载并安装 CMake:https://cmake.org/download/
  2. 下载 Ninja:https://github.com/ninja-build/ninja/releases
  3. 将 CMake 和 Ninja 添加到系统 PATH

验证安装:

终端窗口
cmake --version
ninja --version

打开 VS Code,安装以下扩展:

  1. Cortex-Debug (marus25.cortex-debug)

    • 用于 ARM 调试
    • 扩展 ID: marus25.cortex-debug
  2. C/C++ (ms-vscode.cpptools)

    • C/C++ 语言支持
    • 扩展 ID: ms-vscode.cpptools
  3. CMake Tools (ms-vscode.cmake-tools)

    • CMake 集成
    • 扩展 ID: ms-vscode.cmake-tools
  1. Task Buttons (spencerwmiles.vscode-task-buttons)

    • 在状态栏显示任务快捷按钮
    • 扩展 ID: spencerwmiles.vscode-task-buttons
  2. clangd (llvm-vs-code-extensions.vscode-clangd)

    • 代码智能提示和补全
    • 扩展 ID: llvm-vs-code-extensions.vscode-clangd

作用:Windows 识别 STLink 调试器

安装步骤:

  1. 下载 STLink 驱动程序
  2. 安装驱动
  3. 连接 STLink,确保 Windows 设备管理器中能看到设备

验证:

  • 打开设备管理器
  • 应该能看到 “STMicroelectronics STLink dongle” 或类似设备

项目根目录/
├── .vscode/
│ ├── launch.json # 调试配置
│ ├── tasks.json # 任务配置
│ └── settings.json # 工作区设置
├── build/ # 编译输出目录
│ └── Debug/
│ ├── h7zti6.elf # ELF 可执行文件
│ └── h7zti6.bin # 二进制文件
├── Core/ # STM32CubeMX 生成的核心代码
├── Drivers/ # HAL 驱动
├── openocd.cfg # OpenOCD 配置(调试用)
├── openocd_flash.cfg # OpenOCD 配置(烧录用)
├── CMakeLists.txt # CMake 配置
├── CMakePresets.json # CMake 预设
└── STM32H743XX_FLASH.ld # 链接脚本

配置文件 1: .vscode/launch.json

跳转到“配置文件 1: .vscode/launch.json”

作用:配置 VS Code 调试器

完整内容:

{
"version": "0.2.0",
"configurations": [
{
"name": "调试 STM32H7 (ST-Link)",
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"cwd": "${workspaceFolder}",
"executable": "${workspaceFolder}/build/Debug/h7zti6.elf",
"configFiles": ["${workspaceFolder}/openocd.cfg"],
"toolchainPrefix": "arm-none-eabi",
"armToolchainPath": "D:/program/gcc-arm-none-eabi/bin",
"openOCDPath": "D:/program/xpack-openocd/bin/openocd.exe",
"svdFile": "",
"runToEntryPoint": "main",
"showDevDebugOutput": "raw",
"postRestartCommands": ["break main", "continue"]
},
{
"name": "附加调试 STM32H7 (ST-Link)",
"type": "cortex-debug",
"request": "attach",
"servertype": "openocd",
"cwd": "${workspaceFolder}",
"executable": "${workspaceFolder}/build/Debug/h7zti6.elf",
"configFiles": ["${workspaceFolder}/openocd.cfg"],
"toolchainPrefix": "arm-none-eabi",
"armToolchainPath": "D:/program/gcc-arm-none-eabi/bin",
"openOCDPath": "D:/program/xpack-openocd/bin/openocd.exe",
"svdFile": "",
"showDevDebugOutput": "raw"
}
]
}

需要修改的部分:

  1. executable: 修改为你的 ELF 文件名(替换 h7zti6.elf)
  2. armToolchainPath: 修改为你的 ARM GCC 路径
  3. openOCDPath: 修改为你的 OpenOCD 路径

配置文件 2: .vscode/tasks.json

跳转到“配置文件 2: .vscode/tasks.json”

作用:配置编译、烧录、擦除等任务

完整内容:

{
"version": "2.0.0",
"tasks": [
{
"label": "🔨 编译项目",
"type": "shell",
"command": "cmake",
"args": [
"--build",
"build/Debug",
"--config",
"Debug"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"problemMatcher": [
"$gcc"
],
"detail": "编译 Debug 版本",
"dependsOn": "配置 CMake"
},
{
"label": "配置 CMake",
"type": "shell",
"command": "cmake",
"args": [
"--preset",
"Debug"
],
"group": "build",
"presentation": {
"echo": true,
"reveal": "silent",
"panel": "shared"
},
"detail": "配置 CMake Debug 构建"
},
{
"label": "🔥 擦除Flash (ST-Link)",
"type": "shell",
"command": "D:/program/xpack-openocd/bin/openocd.exe",
"args": [
"-f",
"${workspaceFolder}/openocd_flash.cfg",
"-c",
"init; reset halt; flash erase_address 0x08000000 0x100000; shutdown"
],
"group": "test",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new",
"clear": true
},
"detail": "使用 ST-Link 擦除 STM32H7 Flash Bank1 (1MB)"
},
{
"label": "🔥 擦除整个Flash (ST-Link)",
"type": "shell",
"command": "D:/program/xpack-openocd/bin/openocd.exe",
"args": [
"-f",
"${workspaceFolder}/openocd_flash.cfg",
"-c",
"init; reset halt; stm32h7x mass_erase 0; shutdown"
],
"group": "test",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new",
"clear": true
},
"detail": "使用 ST-Link 擦除 STM32H7 整个 Flash (2MB,包括 Bank1+Bank2)"
},
{
"label": "⬇️ 烧录程序 (ST-Link)",
"type": "shell",
"command": "D:/program/xpack-openocd/bin/openocd.exe",
"args": [
"-f",
"${workspaceFolder}/openocd_flash.cfg",
"-c",
"init; reset halt; flash write_image erase build/Debug/h7zti6.bin 0x08000000; verify_image build/Debug/h7zti6.bin 0x08000000; reset run; shutdown"
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": "test",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new",
"clear": true
},
"detail": "使用 ST-Link 烧录二进制文件到 STM32H7"
},
{
"label": "⬇️ 烧录程序-ELF (ST-Link)",
"type": "shell",
"command": "D:/program/xpack-openocd/bin/openocd.exe",
"args": [
"-f",
"${workspaceFolder}/openocd_flash.cfg",
"-c",
"program build/Debug/h7zti6.elf verify reset exit"
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": "test",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new",
"clear": true
},
"detail": "使用 ST-Link 烧录 ELF 文件到 STM32H7(推荐)"
},
{
"label": "🔧 检测连接 (ST-Link)",
"type": "shell",
"command": "D:/program/xpack-openocd/bin/openocd.exe",
"args": [
"-f",
"${workspaceFolder}/openocd_flash.cfg",
"-c",
"init; targets; reset halt; mdw 0x1FF1E800 3; shutdown"
],
"group": "test",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new",
"clear": true
},
"detail": "使用 ST-Link 检测 OpenOCD 连接状态并读取 STM32H7 芯片 ID"
},
{
"label": "🚀 编译+烧录 (ST-Link)",
"dependsOrder": "sequence",
"dependsOn": [
"🔨 编译项目",
"⬇️ 烧录程序-ELF (ST-Link)"
],
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new",
"clear": true
},
"detail": "完整流程:编译+烧录 ELF(推荐)"
},
{
"label": "🚀 编译+擦除+烧录 (ST-Link)",
"dependsOrder": "sequence",
"dependsOn": [
"🔨 编译项目",
"🔥 擦除Flash (ST-Link)",
"⬇️ 烧录程序 (ST-Link)"
],
"group": "test",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new",
"clear": true
},
"detail": "完整流程:编译+擦除+烧录 BIN"
},
{
"label": "🔄 擦除+烧录 (ST-Link)",
"dependsOrder": "sequence",
"dependsOn": [
"🔥 擦除Flash (ST-Link)",
"⬇️ 烧录程序 (ST-Link)"
],
"group": "test",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "new",
"clear": true
},
"detail": "使用 ST-Link 擦除 Flash 后烧录现有程序"
},
{
"label": "🧹 清理编译",
"type": "shell",
"command": "cmake",
"args": [
"--build",
"build/Debug",
"--target",
"clean"
],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"panel": "shared"
},
"detail": "清理编译产物"
},
{
"label": "🔄 重新配置 CMake",
"type": "shell",
"command": "rm",
"args": [
"-rf",
"build"
],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"panel": "shared"
},
"detail": "删除 build 目录,强制重新配置"
}
]
}

需要修改的部分:

  1. 所有 "command": "D:/program/xpack-openocd/bin/openocd.exe" - 修改为你的 OpenOCD 路径
  2. 所有包含 h7zti6.bin 和 h7zti6.elf 的地方 - 修改为你的项目名称

配置文件 3: .vscode/settings.json

跳转到“配置文件 3: .vscode/settings.json”

作用:工作区设置和任务快捷按钮

完整内容:

{
"files.associations": {
"*.h": "c",
"*.c": "c"
},
// clangd 配置
"clangd.arguments": [
"--compile-commands-dir=./",
"--clang-tidy",
"--completion-style=detailed",
"--header-insertion=iwyu",
"--background-index",
"--suggest-missing-includes"
],
"clangd.fallbackFlags": ["-std=gnu11", "-Wall"],
// 编辑器配置
"editor.semanticHighlighting.enabled": true,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
// Task Buttons 扩展配置
"VsCodeTaskButtons.showCounter": true,
"VsCodeTaskButtons.tasks": [
{
"label": "$(gear) STM32H7 开发",
"tasks": [
{
"label": "🔨 编译项目",
"task": "🔨 编译项目",
"description": "编译 Debug 版本的 STM32H7 项目"
},
{
"label": "🚀 编译+烧录 (推荐)",
"task": "🚀 编译+烧录 (ST-Link)",
"description": "完整流程:编译+烧录 ELF(推荐)"
},
{
"label": "⬇️ 烧录程序-ELF",
"task": "⬇️ 烧录程序-ELF (ST-Link)",
"description": "使用 ST-Link 烧录 ELF 文件到 STM32H7"
},
{
"label": "⬇️ 烧录程序-BIN",
"task": "⬇️ 烧录程序 (ST-Link)",
"description": "使用 ST-Link 烧录二进制文件到 STM32H7"
},
{
"label": "🔥 擦除Flash (Bank1)",
"task": "🔥 擦除Flash (ST-Link)",
"description": "使用 ST-Link 擦除 STM32H7 Flash Bank1 (1MB)"
},
{
"label": "🔥 擦除整个Flash",
"task": "🔥 擦除整个Flash (ST-Link)",
"description": "使用 ST-Link 擦除 STM32H7 整个 Flash (2MB)"
},
{
"label": "🔄 擦除+烧录",
"task": "🔄 擦除+烧录 (ST-Link)",
"description": "使用 ST-Link 擦除Flash后烧录现有程序"
},
{
"label": "🔧 检测连接",
"task": "🔧 检测连接 (ST-Link)",
"description": "使用 ST-Link 检测 OpenOCD 连接状态"
},
{
"label": "🧹 清理编译",
"task": "🧹 清理编译",
"description": "清理编译产物"
},
{
"label": "🔄 重新配置",
"task": "🔄 重新配置 CMake",
"description": "删除 build 目录,强制重新配置"
}
],
"tooltip": "STM32H7 开发任务菜单"
},
{
"label": "🚀 编译+烧录",
"task": "🚀 编译+烧录 (ST-Link)",
"tooltip": "快速编译并烧录程序到 STM32H7",
"color": "default"
}
],
// CMake Tools 配置
"cmake.configureOnOpen": false,
"cmake.buildDirectory": "${workspaceFolder}/build/Debug"
}

作用:OpenOCD 调试配置(不含 init 命令,用于 VS Code 调试)

完整内容:

# OpenOCD 配置文件 - STM32H743ZIT6 (ST-Link)
# 接口配置 - ST-Link (自动检测版本)
source [find interface/stlink.cfg]
# 目标芯片配置 - STM32H7x 系列
source [find target/stm32h7x.cfg]
# 适配器速度设置 (kHz)
adapter speed 4000
# 复位配置
reset_config srst_only srst_nogate

需要修改的部分:

  • source [find target/stm32h7x.cfg] - 根据你的芯片型号修改
    • STM32H7: stm32h7x.cfg
    • STM32F1: stm32f1x.cfg
    • STM32F4: stm32f4x.cfg
    • STM32F7: stm32f7x.cfg
    • 等等

配置文件 5: openocd_flash.cfg

跳转到“配置文件 5: openocd_flash.cfg”

作用:OpenOCD 烧录配置(含 init 命令,用于命令行烧录)

完整内容:

# OpenOCD 配置文件 - STM32H743ZIT6 (ST-Link) - 用于烧录
# 接口配置 - ST-Link (自动检测版本)
source [find interface/stlink.cfg]
# 目标芯片配置 - STM32H7x 系列
source [find target/stm32h7x.cfg]
# 适配器速度设置 (kHz)
adapter speed 4000
# 复位配置
reset_config srst_only srst_nogate
# 初始化
init

重要说明:

  • openocd.cfg(调试用):不含 init 命令
  • openocd_flash.cfg(烧录用):包含 init 命令
  • 两个文件的区别仅在于最后是否有 init 命令

按照 工具安装 章节,完成以下安装:

  1. ✅ ARM GCC 工具链
  2. ✅ OpenOCD
  3. ✅ CMake 和 Ninja
  4. ✅ VS Code 扩展
  5. ✅ STLink 驱动

步骤 2: 创建/打开 STM32 项目

跳转到“步骤 2: 创建/打开 STM32 项目”

如果是新项目:

  1. 使用 STM32CubeMX 创建项目
  2. 配置时钟、外设等
  3. 生成代码,选择 CMake 作为工具链

如果是现有项目:

  1. 直接打开项目文件夹

步骤 3: 创建 .vscode 目录

跳转到“步骤 3: 创建 .vscode 目录”

在项目根目录创建 .vscode 文件夹:

终端窗口
mkdir .vscode

在项目根目录和 .vscode 目录中创建以下文件:

根目录:

  • openocd.cfg
  • openocd_flash.cfg

.vscode 目录:

  • launch.json
  • tasks.json
  • settings.json

复制上述配置文件的内容到对应文件中。

步骤 5: 修改配置文件中的路径

跳转到“步骤 5: 修改配置文件中的路径”

必须修改的地方:

  1. launch.json:

    "executable": "${workspaceFolder}/build/Debug/你的项目名.elf",
    "armToolchainPath": "你的ARM GCC路径/bin",
    "openOCDPath": "你的OpenOCD路径/bin/openocd.exe"
  2. tasks.json:

    • 所有 "command": "D:/program/xpack-openocd/bin/openocd.exe" 改为你的路径
    • 所有 h7zti6.bin 和 h7zti6.elf 改为你的项目名
  3. openocd.cfg 和 openocd_flash.cfg:

    • 根据芯片型号修改 source [find target/stm32xxxx.cfg]

确保项目根目录有以下文件:

  • CMakeLists.txt
  • CMakePresets.json(可选,但推荐)

如果使用 STM32CubeMX 生成,这些文件应该已经存在。

  1. 打开 VS Code
  2. 打开项目文件夹
  3. 按 Ctrl+Shift+B 执行默认编译任务
  4. 或运行任务:🔨 编译项目

首次编译会自动配置 CMake。


跳转到“测试 1: 检测 STLink 连接”
  1. 连接 STLink 到电脑和开发板
  2. 给开发板上电
  3. 在 VS Code 中按 Ctrl+Shift+P
  4. 输入 “Tasks: Run Task”
  5. 选择 🔧 检测连接 (ST-Link)

预期结果:

Info : STLINK V2J43S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.199483
Info : [stm32h7x.cpu0] Cortex-M7 r1p1 processor detected
...
Info : Device: STM32H74x/75x
Info : flash size probed value 2048k

运行任务:🔨 编译项目

预期结果:

  • 编译成功
  • 在 build/Debug/ 目录生成 .elf 和 .bin 文件

运行任务:🚀 编译+烧录 (ST-Link)

预期结果:

Info : Device: STM32H74x/75x
Info : flash size probed value 2048k
...
Info : Padding image section 0 at 0x08000298 with 8 bytes
shutdown command invoked
  1. 按 F5 启动调试
  2. 或点击左侧调试图标,选择 “调试 STM32H7 (ST-Link)”

预期结果:

  • 调试工具栏出现
  • 程序停在 main 函数
  • 可以设置断点、单步执行等

问题 1: 找不到 openocd 命令

跳转到“问题 1: 找不到 openocd 命令”

错误信息:

'openocd' 不是内部或外部命令

解决方案:

  1. 检查 tasks.json 中的 OpenOCD 路径是否正确
  2. 使用绝对路径:D:/program/xpack-openocd/bin/openocd.exe
  3. 确保路径中没有中文字符

问题 2: libusb_open() failed with LIBUSB_ERROR_ACCESS

跳转到“问题 2: libusb_open() failed with LIBUSB_ERROR_ACCESS”

错误信息:

Error: libusb_open() failed with LIBUSB_ERROR_ACCESS
Error: open failed

可能原因:

  1. STLink 正被其他程序占用(STM32CubeIDE、Keil、STLink Utility 等)
  2. 驱动问题
  3. 权限问题

解决方案:

  1. 关闭所有可能占用 STLink 的程序
  2. 重新插拔 STLink USB 线
  3. 等待 3-5 秒后重试
  4. 以管理员身份运行 VS Code
  5. 重新安装 STLink 驱动

问题 3: No flash at address 0x08100000

跳转到“问题 3: No flash at address 0x08100000”

错误信息:

Error: No flash at address 0x08100000

原因: STM32H7 双 Bank 模式,每个 Bank 1MB,擦除范围超出了单个 Bank

解决方案:

  • 使用 🔥 擦除Flash (ST-Link) 擦除单个 Bank (1MB)
  • 或使用 🔥 擦除整个Flash (ST-Link) 擦除整个芯片 (2MB)

问题 4: OpenOCD: GDB Server Quit Unexpectedly

跳转到“问题 4: OpenOCD: GDB Server Quit Unexpectedly”

错误信息:

OpenOCD: GDB Server Quit Unexpectedly

可能原因:

  1. openocd.cfg 包含了 init 命令(调试时不应包含)
  2. STLink 被占用

解决方案:

  1. 确保 openocd.cfg(调试用)不含 init 命令
  2. 确保 openocd_flash.cfg(烧录用)包含 init 命令
  3. 检查 STLink 连接

问题 5: 编译错误 - 找不到工具链

跳转到“问题 5: 编译错误 - 找不到工具链”

错误信息:

CMake Error: CMake was unable to find a build program

解决方案:

  1. 确保 CMake 和 Ninja 已安装并在 PATH 中
  2. 检查 cmake/gcc-arm-none-eabi.cmake 中的工具链路径
  3. 重新运行 配置 CMake 任务

问题 6: 调试时找不到符号表

跳转到“问题 6: 调试时找不到符号表”

错误信息:

No symbol table is loaded

解决方案:

  1. 确保编译时使用了 Debug 模式(包含调试符号)
  2. 检查 launch.json 中的 executable 路径是否正确
  3. 确保 ELF 文件存在:build/Debug/项目名.elf

  1. 编译:按 Ctrl+Shift+B
  2. 烧录:运行任务 🚀 编译+烧录 (ST-Link)
  3. 调试:按 F5
  1. 按 Ctrl+Shift+P
  2. 输入 “Tasks: Run Task”
  3. 选择需要的任务

方法 3: 使用状态栏按钮(需要 Task Buttons 扩展)

跳转到“方法 3: 使用状态栏按钮(需要 Task Buttons 扩展)”
  • 点击齿轮图标 $(gear) STM32H7 开发
  • 选择任务

启动调试:

  • 按 F5
  • 或点击左侧调试图标,点击绿色播放按钮

调试操作:

  • F5 - 继续运行
  • F10 - 单步跨越(Step Over)
  • F11 - 单步进入(Step Into)
  • Shift+F11 - 单步跳出(Step Out)
  • Ctrl+Shift+F5 - 重启调试
  • Shift+F5 - 停止调试

断点操作:

  • 点击行号左侧设置/取消断点
  • 右键断点可设置条件断点

查看变量:

  • 鼠标悬停在变量上
  • 查看左侧”变量”面板
  • 在”监视”面板添加表达式

快速烧录(推荐):

运行任务:🚀 编译+烧录 (ST-Link)

仅烧录(不编译):

运行任务:⬇️ 烧录程序-ELF (ST-Link)

完整擦除后烧录(遇到问题时使用):

运行任务:🚀 编译+擦除+烧录 (ST-Link)

openocd.cfg 修改:

source [find target/stm32f1x.cfg]
adapter speed 1000 # F1 速度较慢

擦除 Flash:

终端窗口
# STM32F103RET6 (512KB)
flash erase_address 0x08000000 0x80000

openocd.cfg 修改:

source [find target/stm32f4x.cfg]
adapter speed 2000

擦除 Flash:

终端窗口
# STM32F407VGT6 (1MB)
flash erase_address 0x08000000 0x100000

openocd.cfg 修改:

source [find target/stm32g0x.cfg] # 或 stm32g4x.cfg
adapter speed 2000

不同系列的芯片 ID 读取地址不同,用于 🔧 检测连接 任务:

系列芯片 ID 地址
STM32F10x1FFFF7E0
STM32F40x1FFF7A10
STM32F70x1FF0F420
STM32H70x1FF1E800
STM32G00x1FFF7590
STM32G40x1FFF7590
STM32L40x1FFF7590

不同芯片的 Flash 大小不同,用于擦除任务:

芯片型号Flash 大小Bank 配置擦除大小(十六进制)
STM32F103C8T664KB单 Bank0x10000
STM32F103RET6512KB单 Bank0x80000
STM32F407VGT61MB单 Bank0x100000
STM32F746ZGT61MB单 Bank0x100000
STM32H743ZIT62MB双 Bank (1MB+1MB)0x100000 (单Bank)
STM32H750VBT6128KB单 Bank0x20000

附录:完整工具链路径示例

跳转到“附录:完整工具链路径示例”
"armToolchainPath": "D:/program/gcc-arm-none-eabi/bin"
"openOCDPath": "D:/program/xpack-openocd/bin/openocd.exe"

示例 2: 使用 STM32CubeIDE 自带工具链

跳转到“示例 2: 使用 STM32CubeIDE 自带工具链”
"armToolchainPath": "C:/ST/STM32CubeIDE_1.12.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.100.202210260954/tools/bin"
"openOCDPath": "C:/ST/STM32CubeIDE_1.12.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.openocd.win32_2.0.100.202109301221/tools/bin/openocd.exe"
"armToolchainPath": "C:/Tools/ARM/gcc-arm-none-eabi-10.3-2021.10/bin"
"openOCDPath": "C:/Tools/OpenOCD/bin/openocd.exe"

配置完成后,请逐项检查:

  • ARM GCC 工具链已安装
  • OpenOCD 已安装
  • CMake 和 Ninja 已安装
  • STLink 驱动已安装
  • VS Code 扩展已安装(Cortex-Debug、C/C++、CMake Tools)
  • .vscode/launch.json 已创建并修改路径
  • .vscode/tasks.json 已创建并修改路径
  • .vscode/settings.json 已创建
  • openocd.cfg 已创建(不含 init)
  • openocd_flash.cfg 已创建(含 init)
  • launch.json 中的 executable 已修改为项目名
  • launch.json 中的 armToolchainPath 已修改
  • launch.json 中的 openOCDPath 已修改
  • tasks.json 中所有 OpenOCD 路径已修改
  • tasks.json 中所有 ELF/BIN 文件名已修改
  • openocd.cfg 中的芯片型号已修改
  • 检测连接成功(显示芯片信息)
  • 编译成功(生成 ELF 和 BIN 文件)
  • 烧录成功(程序写入 Flash)
  • 调试成功(程序停在 main 函数)


文档版本:1.0 最后更新:2026-01-20 适用芯片:STM32H743ZIT6(可适配其他 STM32 系列) 测试环境:Windows 11, VS Code 1.85+, OpenOCD 0.12.0


来源:CSDN 原文,首次发布于 2026-01-20。