1、下载vscode
2、下载openocd
3、下载GNU Tools ARM Embedded
操作:
调试: F5
下载: make flash
清楚:make clean
复位:make reset , 复位之前需要断开openocd, 所以直接输入这个命令是复位不成功的, 这也是为什么下载之前需要杀掉Openocd.exe的原因
需要几个配置文件,路径分别:
stlink.cfg :........\OpenOCD-20200310-0.10.0\share\openocd\scripts\interface\stlink.cfg
STM32WB5x.svd:C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.3\arm\config\debugger\ST\STM32WB5x.svd
stm32wbx.cfg : ......\OpenOCD-20200310-0.10.0\share\openocd\scripts\target\stm32wbx.cfg
Makefile,这个是从STM32CubeMX自动生成的,添加的信息如下
#######################################
# download file
#######################################
flash:
taskkill /f /im openocd.exe
STM32_Programmer_CLI -c port=SWD -hardRst
STM32_Programmer_CLI -c port=SWD -d ./build/123123.hex -v -s 0x08000000
reset:
STM32_Programmer_CLI -c port=SWD -hardRst
#taskkill /f /im openocd.exe
新建文件:openocd.cfg
source [find stlink.cfg]
source [find stm32wbx.cfg]
launch.json 配置
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"miDebuggerPath": "C:/Program Files (x86)/GNU Tools ARM Embedded/9 2019-q4-major/bin/arm-none-eabi-gdb.exe",
"targetArchitecture": "arm",
"program": "${workspaceRoot}/build/123123.elf",
"setupCommands": [
{
"text": "file 'C:/Users/15652/Desktop/STM32TWST/123123/build/123123.elf'"
},
{
"text": "target remote localhost:3333" //连接Openocd
},
{
"text": "monitor reset halt" //复位
},
{
"text": "load" //加载文件
},
{
"text": "break main" //跳转main
}
],
"preLaunchTask": "debug", //调试开始之前,运行debug
"postDebugTask": "stop_debug", //调试结束之后,运行stop_debug
"launchCompleteCommand": "None",
"externalConsole": true,
"cwd": "${workspaceRoot}"
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "debug",
"options": {
"cwd": "${workspaceRoot}"
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"args": [],
"linux": {
"command": "make"
},
"osx": {
"command": "make"
},
"windows": {
"command": "make.exe"
},
"dependsOn": [
"openocd"
]
},
{
"label": "openocd",
"type": "shell",
"command": "./debug.bat",
},
{
"label": "download",
"type": "shell",
"command": "make update",
"problemMatcher": [
"$gcc"
],
},
{
"label": "stop_debug",
"type": "shell",
"command": "make reset",
"problemMatcher": [],
}
]
}
debug.bat
@echo off
tasklist|findstr /i "openocd.exe" > nul
if ERRORLEVEL 1 (
echo openocd is closed,open it.
start cmd /k "openocd"
)
::else (
::echo openocd hasbeen open, close and restart.
::close openocd
::taskkill /f /im openocd.exe
::delay 200ms
::choice /t 0.5 /d y /n >nul
::start cmd /k "openocd"
::)