在线时间4069 小时
UID3441752
注册时间2017-11-21
NXP金币752712
TA的每日心情 | 开心 2024-3-26 15:16 |
---|
签到天数: 266 天 [LV.8]以坛为家I
管理员
- 积分
- 32041
- 最后登录
- 2024-4-28
|
在VSCode中使用J-Link调试
使用J-Link调试
Visual Studio Code是微软推出的免费的源代码编辑器,通过插件,可以实现GDB +J-Link+GDBServer方式在VSCode中调试嵌入式系统。
在本文中,我们将介绍如何通过J-Link向Cortex内核微控制器添加调试功能。示例使用SEGGER的emPower v2.0评估板,其MCU为NXP的MK66FN2M8xxx18。请注意,以下配置将重新刷新目标应用,复位并连接到调试。如果希望添加该选项到正在运行的目标板,只需更改launch.json 中的"request": "launch"为"request": "attach"。
系统需求
1、Visual Studio Code(https://code.visualstudio.com/)
2、GNU ARM嵌入式工具链(https://developer.arm.com/tools- ... in/gnu-rm/downloads)
3、Visual Studio代码插件
· C/ C++ for Visual Studio Code
· Cortex-Debug
· C/ C++ Intellisense可选
4、NXP MK66F器件的SVD(https://keilpack.azureedge.net/p ... _K60_DFP.1.5.0.pack)
Windows系统设置
安装完VSCode及相应插件后,首先打开Visual Studio Code。
打开项目文件夹
在File菜单下选择Open Folder并选择下载的emPower项目文件夹(https://www.segger.com/downloads ... texM_EmbeddedStudio)。
通过Run and Debug按钮 ,选择“Cortex Debug”, 在项目文件夹的.vscode目录中创建launch.json文件。
改编.json文件,如下:
- {
- // 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": [
- {
- "type": "cortex-debug",
- "request": "launch",
- "name": "Debug J-Link",
- "cwd": "${workspaceRoot}",
- "executable": "${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Output/Debug/Start_emPower.elf",
- "serverpath": "D:/Program Files /SEGGER/JLink_V788e/JLinkGDBServerCL.exe",
- "servertype": "jlink",
- "device": "MK66FN2M0xxx18",
- "interface": "jtag",
- "serialNumber": "", //If you have more than one J-Link probe, add the serial number here.
- "jlinkscript":"${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Setup/Kinetis_K66_Target.js",
- "runToMain": true,
- "svdFile": "${workspaceRoot}/SVD/MK66F18.svd"
- }
- ]
- }
复制代码 “serverpath”应该是你的J-Link GDB服务器的具体安装目录。如果电脑连接了多个J-Link,需添加J-Link序列号。如果只调试一个目标,可以把这个条目注释掉。
在项目BSP/SEGGER/K66FN2M0_emPower目录下,使用SES打开Start_SEGGER_emPower.emProject工程,构建生成Start_emPower.elf。
注意:
解压下载的NXP MK66F器件的SVD后,MK66F18.svd文件位于Keil. kinetis_k60_dfp .1.5.0/ SVD下。将此文件夹复制到emPower文件夹。
最后一步是设置ARM GDB工具链。按F1,输入“config”。从下拉菜单中选择C/ c++:Edit Configurations (JSON)
在JSON配置文件中,需要添加编译器路径,如下:
- {
- "configurations": [
- {
- "name": "Win32",
- "includePath": [
- "${workspaceFolder}/**",
- "${workspaceFolder}/GUI/Inc"
- ],
- "defines": [
- "_DEBUG",
- "UNICODE",
- "_UNICODE"
- ],
- "intelliSenseMode": "gcc-x64",
- "compilerPath": " D:\\Program Files (x86)\\GNU Arm Embedded Toolchain\\10 2020-q4-major\bin\\arm-none-eabi-gcc.exe"
- }
- ],
- "version": 4
- }
复制代码 最终结果:
在setting文件中,我们必须指定armToolchainPath。按F1并键入“settings”,选择“Open settings (JSON)”:
"cortex-debug.armToolchainPath": "C:\\Tool\\C\\Arm\\7_2018-q2-update\\bin"一行
应该指向arm-none-eabi-gdb.exe所在的文件夹:
现在设置已经全部完成。可以通过按F5或从RUN菜单→Start Debugging来开始调试。
进入调试后,输出如下:
在左侧面板上可以查看调试变量(局部,全局和静态),调用堆栈,断点,MCU外设和内核寄存器等调试项目所需的信息。
现在可以在Visual Studio Code中调试目标应用程序了。
当你添加和设置用于调试和编译的扩展时,Visual Studio Code是一个很好的选择。在上述配置中,我们添加了“request”:“launch”选项,但如果希望连接到运行中的目标上,你可以简单地将其设置为“request”:“attach”。或者,可以添加一个extra.json文件连接到目标。通过上述配置,即可以在Visual Studio Code下使用J-Link调试了。
|
|