It works.
跳转到“It works.”目录
跳转到“目录”前置要求
跳转到“前置要求”硬件要求
跳转到“硬件要求”- STM32H7 开发板(本教程以 STM32H743ZIT6 为例)
- STLink V2/V3 调试器
- USB 数据线
软件要求
跳转到“软件要求”- Windows 10/11
- VS Code 最新版本
- Git Bash(可选,用于命令行操作)
工具安装
跳转到“工具安装”1. ARM GCC 工具链
跳转到“1. ARM GCC 工具链”作用:编译 STM32 C/C++ 代码
推荐版本:gcc-arm-none-eabi
安装路径示例:D:/program/gcc-arm-none-eabi/
安装步骤:
- 下载 ARM GCC 工具链
- 官方:https://developer.arm.com/downloads/-/gnu-rm
- 或使用 STM32 官方打包版本
- 解压到指定目录(避免中文路径)
- 记录 bin 目录路径,例如:
D:/program/gcc-arm-none-eabi/bin
验证安装:
# 打开命令行,测试D:/program/gcc-arm-none-eabi/bin/arm-none-eabi-gcc.exe --version2. OpenOCD
跳转到“2. OpenOCD”作用:调试服务器,连接 GDB 和硬件调试器
推荐版本:xPack OpenOCD
安装路径示例:D:/program/xpack-openocd/
安装步骤:
- 下载 xPack OpenOCD
- 官方:https://github.com/xpack-dev-tools/openocd-xpack/releases
- 选择 Windows x64 版本
- 解压到指定目录(避免中文路径)
- 记录 bin 目录路径,例如:
D:/program/xpack-openocd/bin
验证安装:
# 打开命令行,测试D:/program/xpack-openocd/bin/openocd.exe --version3. CMake 和 Ninja
跳转到“3. CMake 和 Ninja”作用:构建系统
安装步骤:
- 下载并安装 CMake:https://cmake.org/download/
- 下载 Ninja:https://github.com/ninja-build/ninja/releases
- 将 CMake 和 Ninja 添加到系统 PATH
验证安装:
cmake --versionninja --version4. VS Code 扩展
跳转到“4. VS Code 扩展”打开 VS Code,安装以下扩展:
必需扩展:
跳转到“必需扩展:”-
Cortex-Debug (marus25.cortex-debug)
- 用于 ARM 调试
- 扩展 ID:
marus25.cortex-debug
-
C/C++ (ms-vscode.cpptools)
- C/C++ 语言支持
- 扩展 ID:
ms-vscode.cpptools
-
CMake Tools (ms-vscode.cmake-tools)
- CMake 集成
- 扩展 ID:
ms-vscode.cmake-tools
推荐扩展:
跳转到“推荐扩展:”-
Task Buttons (spencerwmiles.vscode-task-buttons)
- 在状态栏显示任务快捷按钮
- 扩展 ID:
spencerwmiles.vscode-task-buttons
-
clangd (llvm-vs-code-extensions.vscode-clangd)
- 代码智能提示和补全
- 扩展 ID:
llvm-vs-code-extensions.vscode-clangd
5. STLink 驱动
跳转到“5. STLink 驱动”作用:Windows 识别 STLink 调试器
安装步骤:
- 下载 STLink 驱动程序
- 安装驱动
- 连接 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" } ]}需要修改的部分:
executable: 修改为你的 ELF 文件名(替换h7zti6.elf)armToolchainPath: 修改为你的 ARM GCC 路径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 目录,强制重新配置" } ]}需要修改的部分:
- 所有
"command": "D:/program/xpack-openocd/bin/openocd.exe"- 修改为你的 OpenOCD 路径 - 所有包含
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"}配置文件 4: openocd.cfg
跳转到“配置文件 4: openocd.cfg”作用: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 - 等等
- STM32H7:
配置文件 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: 安装所有工具
跳转到“步骤 1: 安装所有工具”按照 工具安装 章节,完成以下安装:
- ✅ ARM GCC 工具链
- ✅ OpenOCD
- ✅ CMake 和 Ninja
- ✅ VS Code 扩展
- ✅ STLink 驱动
步骤 2: 创建/打开 STM32 项目
跳转到“步骤 2: 创建/打开 STM32 项目”如果是新项目:
- 使用 STM32CubeMX 创建项目
- 配置时钟、外设等
- 生成代码,选择 CMake 作为工具链
如果是现有项目:
- 直接打开项目文件夹
步骤 3: 创建 .vscode 目录
跳转到“步骤 3: 创建 .vscode 目录”在项目根目录创建 .vscode 文件夹:
mkdir .vscode步骤 4: 创建配置文件
跳转到“步骤 4: 创建配置文件”在项目根目录和 .vscode 目录中创建以下文件:
根目录:
openocd.cfgopenocd_flash.cfg
.vscode 目录:
launch.jsontasks.jsonsettings.json
复制上述配置文件的内容到对应文件中。
步骤 5: 修改配置文件中的路径
跳转到“步骤 5: 修改配置文件中的路径”必须修改的地方:
-
launch.json:
"executable": "${workspaceFolder}/build/Debug/你的项目名.elf","armToolchainPath": "你的ARM GCC路径/bin","openOCDPath": "你的OpenOCD路径/bin/openocd.exe" -
tasks.json:
- 所有
"command": "D:/program/xpack-openocd/bin/openocd.exe"改为你的路径 - 所有
h7zti6.bin和h7zti6.elf改为你的项目名
- 所有
-
openocd.cfg 和 openocd_flash.cfg:
- 根据芯片型号修改
source [find target/stm32xxxx.cfg]
- 根据芯片型号修改
步骤 6: 检查 CMake 配置
跳转到“步骤 6: 检查 CMake 配置”确保项目根目录有以下文件:
CMakeLists.txtCMakePresets.json(可选,但推荐)
如果使用 STM32CubeMX 生成,这些文件应该已经存在。
步骤 7: 首次编译
跳转到“步骤 7: 首次编译”- 打开 VS Code
- 打开项目文件夹
- 按
Ctrl+Shift+B执行默认编译任务 - 或运行任务:
🔨 编译项目
首次编译会自动配置 CMake。
验证测试
跳转到“验证测试”测试 1: 检测 STLink 连接
跳转到“测试 1: 检测 STLink 连接”- 连接 STLink 到电脑和开发板
- 给开发板上电
- 在 VS Code 中按
Ctrl+Shift+P - 输入 “Tasks: Run Task”
- 选择
🔧 检测连接 (ST-Link)
预期结果:
Info : STLINK V2J43S7 (API v2) VID:PID 0483:3748Info : Target voltage: 3.199483Info : [stm32h7x.cpu0] Cortex-M7 r1p1 processor detected...Info : Device: STM32H74x/75xInfo : flash size probed value 2048k测试 2: 编译项目
跳转到“测试 2: 编译项目”运行任务:🔨 编译项目
预期结果:
- 编译成功
- 在
build/Debug/目录生成.elf和.bin文件
测试 3: 烧录程序
跳转到“测试 3: 烧录程序”运行任务:🚀 编译+烧录 (ST-Link)
预期结果:
Info : Device: STM32H74x/75xInfo : flash size probed value 2048k...Info : Padding image section 0 at 0x08000298 with 8 bytesshutdown command invoked测试 4: 调试程序
跳转到“测试 4: 调试程序”- 按
F5启动调试 - 或点击左侧调试图标,选择 “调试 STM32H7 (ST-Link)”
预期结果:
- 调试工具栏出现
- 程序停在
main函数 - 可以设置断点、单步执行等
常见问题
跳转到“常见问题”问题 1: 找不到 openocd 命令
跳转到“问题 1: 找不到 openocd 命令”错误信息:
'openocd' 不是内部或外部命令解决方案:
- 检查 tasks.json 中的 OpenOCD 路径是否正确
- 使用绝对路径:
D:/program/xpack-openocd/bin/openocd.exe - 确保路径中没有中文字符
问题 2: libusb_open() failed with LIBUSB_ERROR_ACCESS
跳转到“问题 2: libusb_open() failed with LIBUSB_ERROR_ACCESS”错误信息:
Error: libusb_open() failed with LIBUSB_ERROR_ACCESSError: open failed可能原因:
- STLink 正被其他程序占用(STM32CubeIDE、Keil、STLink Utility 等)
- 驱动问题
- 权限问题
解决方案:
- 关闭所有可能占用 STLink 的程序
- 重新插拔 STLink USB 线
- 等待 3-5 秒后重试
- 以管理员身份运行 VS Code
- 重新安装 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可能原因:
openocd.cfg包含了init命令(调试时不应包含)- STLink 被占用
解决方案:
- 确保
openocd.cfg(调试用)不含init命令 - 确保
openocd_flash.cfg(烧录用)包含init命令 - 检查 STLink 连接
问题 5: 编译错误 - 找不到工具链
跳转到“问题 5: 编译错误 - 找不到工具链”错误信息:
CMake Error: CMake was unable to find a build program解决方案:
- 确保 CMake 和 Ninja 已安装并在 PATH 中
- 检查
cmake/gcc-arm-none-eabi.cmake中的工具链路径 - 重新运行
配置 CMake任务
问题 6: 调试时找不到符号表
跳转到“问题 6: 调试时找不到符号表”错误信息:
No symbol table is loaded解决方案:
- 确保编译时使用了 Debug 模式(包含调试符号)
- 检查
launch.json中的executable路径是否正确 - 确保 ELF 文件存在:
build/Debug/项目名.elf
使用方法
跳转到“使用方法”日常开发工作流
跳转到“日常开发工作流”方法 1: 使用快捷键
跳转到“方法 1: 使用快捷键”- 编译:按
Ctrl+Shift+B - 烧录:运行任务
🚀 编译+烧录 (ST-Link) - 调试:按
F5
方法 2: 使用任务菜单
跳转到“方法 2: 使用任务菜单”- 按
Ctrl+Shift+P - 输入 “Tasks: Run Task”
- 选择需要的任务
方法 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)适配其他 STM32 芯片
跳转到“适配其他 STM32 芯片”STM32F1 系列
跳转到“STM32F1 系列”openocd.cfg 修改:
source [find target/stm32f1x.cfg]adapter speed 1000 # F1 速度较慢擦除 Flash:
# STM32F103RET6 (512KB)flash erase_address 0x08000000 0x80000STM32F4 系列
跳转到“STM32F4 系列”openocd.cfg 修改:
source [find target/stm32f4x.cfg]adapter speed 2000擦除 Flash:
# STM32F407VGT6 (1MB)flash erase_address 0x08000000 0x100000STM32G0/G4 系列
跳转到“STM32G0/G4 系列”openocd.cfg 修改:
source [find target/stm32g0x.cfg] # 或 stm32g4x.cfgadapter speed 2000芯片 ID 地址对照表
跳转到“芯片 ID 地址对照表”不同系列的芯片 ID 读取地址不同,用于 🔧 检测连接 任务:
| 系列 | 芯片 ID 地址 |
|---|---|
| STM32F1 | 0x1FFFF7E0 |
| STM32F4 | 0x1FFF7A10 |
| STM32F7 | 0x1FF0F420 |
| STM32H7 | 0x1FF1E800 |
| STM32G0 | 0x1FFF7590 |
| STM32G4 | 0x1FFF7590 |
| STM32L4 | 0x1FFF7590 |
Flash 容量对照表
跳转到“Flash 容量对照表”不同芯片的 Flash 大小不同,用于擦除任务:
| 芯片型号 | Flash 大小 | Bank 配置 | 擦除大小(十六进制) |
|---|---|---|---|
| STM32F103C8T6 | 64KB | 单 Bank | 0x10000 |
| STM32F103RET6 | 512KB | 单 Bank | 0x80000 |
| STM32F407VGT6 | 1MB | 单 Bank | 0x100000 |
| STM32F746ZGT6 | 1MB | 单 Bank | 0x100000 |
| STM32H743ZIT6 | 2MB | 双 Bank (1MB+1MB) | 0x100000 (单Bank) |
| STM32H750VBT6 | 128KB | 单 Bank | 0x20000 |
附录:完整工具链路径示例
跳转到“附录:完整工具链路径示例”示例 1: 标准安装路径
跳转到“示例 1: 标准安装路径”"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"示例 3: 自定义路径
跳转到“示例 3: 自定义路径”"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 函数)
参考资源
跳转到“参考资源”- OpenOCD 官方文档:http://openocd.org/documentation/
- Cortex-Debug 扩展文档:https://github.com/Marus/cortex-debug
- ARM GCC 工具链:https://developer.arm.com/downloads/-/gnu-rm
- STM32 官方资源:https://www.st.com/en/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus.html
文档版本:1.0 最后更新:2026-01-20 适用芯片:STM32H743ZIT6(可适配其他 STM32 系列) 测试环境:Windows 11, VS Code 1.85+, OpenOCD 0.12.0
来源:CSDN 原文,首次发布于 2026-01-20。