欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

在Vscode中轻松搭建并使用Jlink+OpenOCD进行STM32的下载与调试环境配置指南

最编程 2024-02-19 11:14:45
...

对于 Mingw 的安装比较困难,国内的网无法正常在线下载组件,

需要手动下载 x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z 版本的软件包,添加环境变量,并将 mingw32-make.exe 名字改成 make.exe。

对于 OpenOCD,需要使用 Zadig 工具安装 Jlink 驱动。

Vscode 工程的 Makefile 也要更改:

#省略
INTERFACE_CFG="D:\work\tool\OpenOCD-20231002-0.12.0\share\openocd\scripts\interface\jlink_swd.cfg"
TARGET_CFG="D:\work\tool\OpenOCD-20231002-0.12.0\share\openocd\scripts\target\stm32g4x.cfg"

#省略
#######################################
clean:
#	-rm -fR $(BUILD_DIR)
	-del /q $(BUILD_DIR)

down: 
	openocd -f $(INTERFACE_CFG) -f $(TARGET_CFG) -c init -c halt -c \
	"program $(BUILD_DIR)/$(TARGET).hex" -c reset -c shutdown 

#######################################

参考以下的文章:

在window下使用 VScode 搭建 ARM 开发环境—— 详细版_抛弃ide — 在window下使用vscode搭建arm开发环境-****博客

对于使用 OpenOCD 进行 Debug:

需要修改 Vscode 工程 .vscode 路径下的 launch.json 文件

    {
      "cwd": "${workspaceRoot}",
      "executable": "./build/ee.elf",
      "name": "Debug Microcontroller",
      "request": "launch",
      "type": "cortex-debug",
      "showDevDebugOutput": false,
      "servertype": "openocd",
      "configFiles": [
        "D:/work/tool/OpenOCD-20231002-0.12.0/share/openocd/scripts/interface/jlink_swd.cfg",
        "D:/work/tool/OpenOCD-20231002-0.12.0/share/openocd/scripts/target/stm32g4x.cfg"
      ]
    },

参考以下文章:

VsCode+OpenOCD 开发stm32系列_vscode openocd-****博客