• 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
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

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

    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"
            }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

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

    完整的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"
            }
        ]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

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

  • 相关阅读:
    分数限制下,选好专业还是选好学校?过来人跟你说
    Mysql 索引原理
    【ARFoundation学习笔记】2D图像检测跟踪
    操作系统的发展与分类
    阿里云轻量应用服务器有月流量限制吗?
    SpringSecurity入门
    koa + http-proxy-middleware 搭建一个带转发的静态服务器
    MySQL:已提交读和可重复读的实现原理 | MVCC(多版本并发控制)——笔记自用
    LeetCode每日一题(1162. As Far from Land as Possible)
    js【详解】数据类型原理(含变量赋值详解-浅拷贝)
  • 原文地址:https://blog.csdn.net/xiaoyuanwuhui/article/details/128085237