自学内容网 自学内容网

OpenOCD之J-Link下载

1.下载USB Dirver Tool.exe,选择J-Link dirver,替换成WinUSB驱动。(⭐USB Dirver Tool工具可将J-Link从WinUSB驱动恢复为默认驱动⭐)

下载方式
①官方网址:https://visualgdb.com/UsbDriverTool/
②笔者的CSDN链接:https://download.csdn.net/download/ZZLLLLLLZ/89902055

在这里插入图片描述
2.打开安装好OpenOCD路径的interface接口脚本文件夹,比如笔者安装OpenOCD路径的interface接口脚本文件夹如下:

D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\interface

3.复制新的一份jlink.cfg,并重命名为jlink-swd.cfg
在这里插入图片描述
4.在jlink-swd.cfg文件的 adapter driver jlink 语句下方添加 transport select swd,如下图所示:
在这里插入图片描述
5.将task.json中的 -f interface处后面的接口文件名修改成上述的jlink-swd.cfg
在这里插入图片描述

 //J-link方式下载
        {
            "type": "shell",
            "label": "flash with J-link",
            "command": "openocd",
            "args": [
                "-f",
                "interface/jlink-swd.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\interface
                "-f",
                "target/stm32f4x.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\target
                "-c",
                // "program build/F401CCU6_demo.elf verify reset exit"
                "program build/${workspaceRootFolderName}.elf verify reset", //将工程根目录名称作为可执行文件名称
                "-c",
                "reset run",
                // "-c",
                // "shutdown",
                "-c",
                "exit"
            ], /*command+args相当于主命令+子命令,也就是openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c "program build/F401CCU6_demo.elf verify reset exit"的效果*/
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "dependsOn": [ //每次执行这个任务,会先build任务,这便是所谓的依赖。
                "build"
            ]
        }

同理 将launch.json中的J-link调试段的 interface 处后面的接口文件名修改成上述的jlink-swd.cfg
在这里插入图片描述

//调试脚本
{
    "configurations": [
        {
            "name": "Debug with CMSIS-DAP-link",
            "cwd": "${workspaceRoot}",
            // "executable": "./build/F401CCU6_demo.elf",
            "executable": "./build/${workspaceRootFolderName}.elf", //将工程根目录名称作为可执行文件名称
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "openocd",
            "device": "STM32F401CCU6",
            "configFiles": [
                "interface/cmsis-dap.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\interface
                "target/stm32f4x.cfg" //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\target
            ],
            "svdFile": "./STM32F401.svd", //选择寄存器文件
            "liveWatch": { //变量窗口激活和设置每秒的采样次数
                "enabled": true,
                "samplesPerSecond": 4
            },
            "searchDir": [],
            "runToEntryPoint": "main",
            "showDevDebugOutput": "none",
            "preLaunchTask": "flash with cmsis-dap-link"
            //每次调试之前,会先下载程序再调试
        },
        {
            "name": "Debug with ST-link",
            "cwd": "${workspaceRoot}",
            // "executable": "./build/F401CCU6_demo.elf",
            "executable": "./build/${workspaceRootFolderName}.elf", //将工程根目录名称作为可执行文件名称
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "openocd",
            "device": "STM32F401CCU6",
            "configFiles": [
                "interface/stlink.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\interface
                "target/stm32f4x.cfg" //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\target
            ],
            "svdFile": "./STM32F401.svd", //选择寄存器文件
            "liveWatch": { //变量窗口激活和设置每秒的采样次数
                "enabled": true,
                "samplesPerSecond": 4
            },
            "searchDir": [],
            "runToEntryPoint": "main",
            "showDevDebugOutput": "none",
            "preLaunchTask": "flash with stlink" //每次调试之前会先下载再调试
        },
        {
            "name": "Debug with J-link",
            "cwd": "${workspaceRoot}",
            "executable": "./build/${workspaceRootFolderName}.elf",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "openocd", //要选择的GDB server
            "device": "STM32F401CCU6",
            "configFiles": [
                "interface/jlink-swd.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\interface
                "target/stm32f4x.cfg" //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\target
            ],
            "interface": "swd",
            "svdFile": "./STM32F401.svd",
            "liveWatch": {
                "enabled": true,
                "samplesPerSecond": 4
            },
            "runToEntryPoint": "main",
            "showDevDebugTimestamps": true,
            // "preLaunchTask": "build",
            "showDevDebugOutput": "none",
            "preLaunchTask": "flash with J-link" //每次调试之前会先下载再调试
       }
    ],
    "version": "2.0.0"
}

6.点击Download——>选择J-link下载,即可下载。
在这里插入图片描述


原文地址:https://blog.csdn.net/ZZLLLLLLZ/article/details/144011770

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!