安装Cortex-Debug插件

安装OpenOCD
安装JLink驱动
通过vscode左侧的调试和运行按钮
选择生成launch文件
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"}
修改该内容使之适配自己的工程:
executable参数为要执行的目标文件devices为当前使用的mcu型号svdFile参数指定对应mcu的.svd文件位置,用于调试的时候查看寄存器的内容。preLaunchTask(调试前执行任务)和postDebugTask(调试结束后执行任务)根据需要添加,实际指的是task.json文件中定义好的任务。将如下内容复制到对应的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"}
需要修改的位置和上面基本一致。
{// 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"}]
}
在调试时可以通过调试启动三角右侧的下拉框进行选择使用哪种方式进行调试。

上一篇:人生励志感悟的句子
下一篇:遇到困难时激励自己的名言