openocd下载stm32程序【使用jlink】
打开cmd
如果没有配置环境变量,则需需要先配置环境变量
下载zadig
option->list all device打钩
option->ignore Hubs or Composite Parents打钩
选择j-link
install driver
将需要下载的文件拷贝到openocd工作的文件夹下
OpenOCD-20211118-0.11.0\share\openocd\scripts
在这个目录下新建一个文件夹,命名为outputfile,
在文件夹中放入要烧写的hex,并命名为origin.hex
命令
openocd -c "adapter driver jlink" -c"transport select swd" -c "adapter speed 1000" -f"target/stm32f1x.cfg" -c "program outputfile/origin.hex" -c reset -c shutdown
Clion使用openocd脚本
打开OpenOCD-20211118-0.11.0\share\openocd\scripts\board
新建一个脚本,建议用0开头,这样非常好找配置文件,例如0_stm32f103_dowm.cfg
脚本文件内容如下:
adapter driver jlink
transport select swd
source [find target/stm32f1x.cfg]
adapter speed 2000
vscode使用openocd下载脚本
vscode新建一个tasks.json
注意:
1.vscode下面路径分隔符不是"\",而是“/"
2.命令格式和cmd里面的不同
3.hex,写相对路径即可,(相对于vscode工作区的目录)
内容如下:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello",
},
{
"type": "shell",
"label": "download",
"command": "openocd",
"args": [
"-c",
"adapter driver jlink",
"-c",
"transport select swd",
"-c",
" adapter speed 1000",
"-f"
"target/stm32f1x.cfg",
"-c",
// "program ${workspaceFolder}\\com.quest.firmware.bc.reader\\build\\debug\\BC_Reader_STM32F1_debug.hex",
"program com.quest.firmware.bc.reader/build/debug/BC_Reader_STM32F1_debug.hex",
"-c",
"reset",
"-c",
"shutdown"
],
"problemMatcher": [
"$gcc"
],
"group": "build",
"dependsOn": "Build"
}
]
}
运行vscode脚本
vscode顶上有个终端(T)->运行任务->download