当前位置: 首页 > news >正文

VSCode 加Cortex-Debug嵌入式调试方法

简介

当使用ARM Cortex-M微控制器时,Cortex-Debug是一个Visual Studio Code的扩展,以简化调试过程。本文档介绍了如何编写启动配置(launch.json)。

settings.json配置

  • 打开VSCode用户设置文件settings.json: 文件→偏好→设置
  • 选择用户设置:
    在搜索栏中输入" json "(带或不带双引号)。在设置中找到“编辑”链接。然后点击它。这将打开~/.config/Code/User/settings.json文件
  • 将以下行添加到settings.json文件,在大括号{}之间:
{"cortex-debug.openocdPath": "/usr/bin/openocd","cortex-debug.armToolchainPath.linux": "/opt/toolchains/gcc-arm- none-eabi-10.3-2021.10/bin","cortex-debug.armToolchainPath.windows": "C:\\ProgramData\\chocolatey\\bin","cortex-debug.gdbPath.linux": "/opt/toolchains/gcc-arm-none-eabi-10.3-2021.10/bin//arm-none-eabi-gdb","cortex-debug.gdbPath.windows": "C:\\ProgramData\\chocolatey\\bin\\arm-none-eabi-gdb.exe"
}

请注意:您系统上的路径可能不同。确保该路径与文件的实际位置匹配。

  • 保存文件settings.json

launch.json配置

要在VS Code中运行或调试一个简单的应用程序,我们可以在debug start视图中选择run and debug,或者我们可以按F5, VS Code将尝试运行当前活动的文件。

创建启动配置文件是有益的,因为它允许我们配置和保存调试设置的详细信息。VSCode会在启动时调试配置信息。位于工作空间(项目根文件夹)中的.vscode文件夹中的Json文件。

launch.json文件用于在Visual Studio Code中配置调试器。

参数
以下是launch.json中的参数列表。为特定的设备和环境配置它们。

cwd:项目路径
configFiles:要加载的OpenOCD配置文件
device:目标设备标识符
接口:用于连接的调试接口类型(默认为SWD) -用于J-Link和BMP探针。
name:配置名称;显示在启动配置下拉菜单中。
preLaunchTask:在调试会话开始之前运行的任务。指定在tasks.json中定义的任务。
request:配置请求类型。可以是“发射”或“附加”。
runToEntryPoint:如果启用,调试器将运行,直到主函数开始。
serialNumber: J-Link专用参数。J-Link序列号-仅当多个J-Link连接到计算机时需要
servertype: GDB服务器类型—支持jlink、openocd、pyocd、pe、stutil
svdFile:描述微控制器外设的SVD文件的路径;如果没有提供,那么可以根据输入的“设备”选择一个。这可能会根据“设备”自动加载。
swoConfig: SWO/ITM配置。
enabled:开启SWO解码。
cpuFrequency: CPU的目标频率,单位为Hz。
swoffrequency: SWO频率,单位为Hz。
source:SWO数据来源。可以是“探针”直接从调试探针获得,也可以是串行端口设备使用调试探针外部的串行端口。
decoders:SWO解码器配置
label:输出窗口的标签。
port: ITM端口号
  • 打开VSCode启动配置文件launch. json: Run→Add Configuration…
  • 复制以下代码
{"version": "0.2.0","configurations": [{"name": "Debug (OpenOCD)","cwd": "${workspaceRoot}","executable": "${workspaceRoot}/build/blinky.elf","request": "launch","type": "cortex-debug","servertype": "openocd","interface": "swd","device": "TM4C123GH6PM","runToEntryPoint": "main","svdFile": "${workspaceRoot}/svd/TM4C123GH6PM.svd","configFiles": ["board/ek-tm4c123gxl.cfg"],"preLaunchCommands": ["set mem inaccessible-by-default off","monitor reset"],"postLaunchCommands": ["monitor reset init","monitor sleep 200"]}]
}
  • 修改“executable”、“svdFile”和“device”参数并保存
  • svdFile: launch. json中的“svdFile”条目。在Json文件是可选的,但对嵌入式系统调试至关重要,因为它描述了设备的外设寄存器。

例1: Discovery Board / OpenOCD

这是开发板的配置。这基本上是cortex-m-quickstart的默认设置。

launch. json

{"version": "0.2.0","configurations": [{"type": "cortex-debug","request": "launch","name": "Debug (OpenOCD)","servertype": "openocd","cwd": "${workspaceRoot}","preLaunchTask": "cargo build","runToMain": true,"executable": "./target/thumbv7em-none-eabihf/debug/project-name","device": "STM32F303VCT6","configFiles": ["interface/stlink-v2-1.cfg","target/stm32f3x.cfg"],"svdFile": "${workspaceRoot}/.vscode/STM32F303.svd","swoConfig": {"enabled": true,"cpuFrequency": 8000000,"swoFrequency": 2000000,"source": "probe","decoders": [{ "type": "console", "label": "ITM", "port": 0 }]}}]
}

例2:Nucleo-F429ZI Board / J-Link

将Nucleo-F429的STLink固件升级为JLink。因此,对于我的核与J-Link固件,我更改设置“servertype”为“jlink”和“interface”为“swd”。

{"version": "0.2.0","configurations": [{"type": "cortex-debug","request": "launch","name": "Debug (J-Link)","cwd": "${workspaceRoot}","executable": "./target/thumbv7em-none-eabihf/debug/project-name","servertype": "jlink","device": "STM32F429ZI","interface": "swd","serialNumber": "","preLaunchTask": "cargo build","runToMain": true,"svdFile": "${workspaceRoot}/.vscode/STM32F429.svd","swoConfig": {"enabled": true,"cpuFrequency": 8000000,"swoFrequency": 2000000,"source": "probe","decoders": [{ "type": "console", "label": "ITM", "port": 0 }]}},]
}

结合Makefile设置调试方法

添加构建(编译、链接等)任务(tasks.json)

ctrl+shift+p打开命令行,输入Tasks: Run task==》 Create tasks.json file from template, 生成默认的tasks.json文件。

{// 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"}]
}

工程采用makefile编译则,改为

{"version": "2.0.0","tasks": [{"label": "make all","type": "shell","command": "make all","group": {"kind": "build","isDefault": true},"problemMatcher": "$gcc"}]
}

或者

{"version": "2.0.0","tasks": [{"type": "shell","label": "build","command": "cd C:/project/debug; make","args": [],	}]
}

配置c_cpp_properties.json

{"configurations": [{"name": "Win32","includePath": ["${workspaceFolder}/**","${workspaceFolder}\\libs\\nnom\\inc","${workspaceFolder}\\libs\\nnom\\inc\\layers"],"defines": ["_DEBUG","UNICODE","_UNICODE"],"compilerPath": "D:\\soft\\Qt5.6.2\\Tools\\mingw492_32\\bin\\gcc.exe","cStandard": "c99","cppStandard": "c++14","intelliSenseMode": "windows-gcc-x86"}],"version": 4
}
http://www.lryc.cn/news/268294.html

相关文章:

  • etcd-workbench一款免费好用的ETCD客户端,支持SSHTunnel、版本对比等功能
  • 华为ipv6配置之ospf案例
  • Design patterns--装饰模式
  • 卷积神经网络 反向传播
  • java面试题20
  • 【Java面试题】redis的过期策略有哪些
  • for参数 命令语句 变量
  • CentOS 8的新特性
  • vue2、vue3状态管理之vuex、pinia
  • axios进行图片上传组件封装
  • 2312llvm,用匹配器构建clang工具
  • 12.26ARM作业
  • Objectiv-C设计模式笔记
  • AI安全综述
  • 计算机网络概述(下)——“计算机网络”
  • anaconda创建环境时安装默认的第三方库
  • STM32 cubeMX 光敏电阻AD转化实验
  • AutoSAR(基础入门篇)3.2-Autosar中RTE的Ports【S/R】与【C/S】
  • 安装kafka
  • [MySQL] MySQL 高级(进阶) SQL 语句
  • 创建springboot项目
  • “双十一、二” 业务高峰如何扛住?韵达快递选择 TDengine
  • STM32L432+LIS3DH【加速度传感器】:端侧AI
  • VCG Mesh刚性旋转(变换矩阵)
  • R语言【base】——system.file() 在软件包等中查找文件的完整文件名。
  • HTML制作暴雨特效
  • cesium实现区域贴图及加载多个gif动图
  • blackbox黑盒监控部署(k8s内)tensuns专用
  • “C语言“——scanf()、getchar() 、putchar()、之间的关系
  • Spring Boot3 Web开发技术