• 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

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

  • 相关阅读:
    最简单 导航栏 html css
    专业硕士招生占比将达到三分之二,那么跟学术硕士有哪些区别?
    分类预测|基于贝叶斯优化长短期记忆网络的数据分类预测Matlab程序 多特征输入多类别输出 BO-LSTM 附赠预测新数据
    【毕业设计】基于 STM32 的自动泊车系统 -智能小车 - 物联网单片机
    openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
    Redux 4.2 版本发布由createStore --》configureStore
    官网下载mysql 8.0.27及安装
    jsp初学
    【无标题】三分钟快速实现MQTT网关远程连接三菱系列PLC
    NumPy数值计算基础实训
  • 原文地址:https://blog.csdn.net/xiaoyuanwuhui/article/details/128085237