vscode开发STM32(三)---调试篇

vscode开发STM32(三)—调试篇

前提条件

安装Cortex-Debug插件
在这里插入图片描述
安装OpenOCD
安装JLink驱动

配置调试

通过vscode左侧的调试和运行按钮在这里插入图片描述选择生成launch文件

配置JLink使用JLinkGDB进行调试

将如下内容添加到launch文件合适的位置

{
            "name": "Cortex Debug-jlink",
            "cwd": "${workspaceRoot}/",
            "executable": "${workspaceFolder}/build/${workspaceFolderBasename}.elf",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "jlink", //要选择的GDB server
            "device": "STM32F405RG",
            "interface": "swd",
            "runToEntryPoint": "main",
            "showDevDebugTimestamps": true,
            // "svdFile": "${workspaceRoot}/STM32F103.svd",
            // "preLaunchTask": "build",
            // "postDebugTask": "run"
        }

修改该内容使之适配自己的工程:

  1. executable参数为要执行的目标文件
  2. devices为当前使用的mcu型号
  3. svdFile参数指定对应mcu的.svd文件位置,用于调试的时候查看寄存器的内容。
  4. preLaunchTask(调试前执行任务)和postDebugTask(调试结束后执行任务)根据需要添加,实际指的是task.json文件中定义好的任务。

配置stlink使用openOCD进行调试

将如下内容复制到对应的launch文件中

{
            "name": "Cortex Debug-stlink",
            "cwd": "${workspaceRoot}/",
            "executable": "${workspaceFolder}/build/${workspaceFolderBasename}.elf",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "openocd", //要选择的GDB server
            "device": "STM32F405RG", //
            "interface": "swd",
            "configFiles": [
                // "${workspaceRoot}/openocd.cfg"
                "interface/stlink-v2.cfg",
                "target/stm32f4x.cfg",
            ],
            "runToEntryPoint": "main",
            "showDevDebugTimestamps": true,
            // "svdFile": "${workspaceRoot}/STM32F103.svd",
            "preLaunchTask": "build",
            "postDebugTask": "run"
        }

需要修改的位置和上面基本一致。

完整的launch文件内容

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [  
        {
            "name": "Cortex Debug-jlink",
            "cwd": "${workspaceRoot}/",
            "executable": "${workspaceFolder}/build/${workspaceFolderBasename}.elf",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "jlink", //要选择的GDB server
            "device": "STM32F405RG",
            "interface": "swd",
            "runToEntryPoint": "main",
            "showDevDebugTimestamps": true,
            // "svdFile": "${workspaceRoot}/STM32F103.svd",
            // "preLaunchTask": "build",
            // "postDebugTask": "run"
        },
        {
            "name": "Cortex Debug-stlink",
            "cwd": "${workspaceRoot}/",
            "executable": "${workspaceFolder}/build/${workspaceFolderBasename}.elf",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "openocd", //要选择的GDB server
            "device": "STM32F405RG", //
            "interface": "swd",
            "configFiles": [
                // "${workspaceRoot}/openocd.cfg"
                "interface/stlink-v2.cfg",
                "target/stm32f4x.cfg",
            ],
            "runToEntryPoint": "main",
            "showDevDebugTimestamps": true,
            // "svdFile": "${workspaceRoot}/STM32F103.svd",
            "preLaunchTask": "build",
            "postDebugTask": "run"
        }
    ]
}

在调试时可以通过调试启动三角右侧的下拉框进行选择使用哪种方式进行调试。
在这里插入图片描述

  • 4
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值