当使用ARM Cortex-M微控制器时,Cortex-Debug是一个Visual Studio Code的扩展,以简化调试过程。本文档介绍了如何编写启动配置(launch.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"
}
请注意:您系统上的路径可能不同。确保该路径与文件的实际位置匹配。
要在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端口号
{
"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"
]
}
]
}
这是开发板的配置。这基本上是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 }
]
}
}
]
}
将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 }
]
}
},
]
}
添加构建(编译、链接等)任务(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": [],
}
]
}
{
"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
}