查看: 647|回复: 2

[分享] 在VSCode中使用J-Link调试

[复制链接]
  • TA的每日心情
    开心
    2024-3-26 15:16
  • 签到天数: 266 天

    [LV.8]以坛为家I

    3301

    主题

    6548

    帖子

    0

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    32041
    最后登录
    2024-4-28
    发表于 2023-8-31 11:23:10 | 显示全部楼层 |阅读模式
    在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)。
    13.png
    通过Run and Debug按钮 ,选择“Cortex Debug”, 在项目文件夹的.vscode目录中创建launch.json文件。
    14.png
    改编.json文件,如下:

    1. {
    2.     // Use IntelliSense to learn about possible attributes.
    3.     // Hover to view descriptions of existing attributes.
    4.     // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    5.     "version": "0.2.0",
    6.     "configurations": [
    7.       {
    8.       "type": "cortex-debug",
    9.       "request": "launch",
    10.       "name": "Debug J-Link",
    11.       "cwd": "${workspaceRoot}",
    12.    "executable": "${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Output/Debug/Start_emPower.elf",
    13.        "serverpath": "D:/Program Files /SEGGER/JLink_V788e/JLinkGDBServerCL.exe",
    14.        "servertype": "jlink",
    15.        "device": "MK66FN2M0xxx18",
    16.        "interface": "jtag",
    17.        "serialNumber": "", //If you have more than one J-Link probe, add the serial number here.
    18.     "jlinkscript":"${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Setup/Kinetis_K66_Target.js",
    19.      "runToMain": true,
    20.      "svdFile": "${workspaceRoot}/SVD/MK66F18.svd"
    21.     }
    22. ]
    23. }
    复制代码
    “serverpath”应该是你的J-Link GDB服务器的具体安装目录。如果电脑连接了多个J-Link,需添加J-Link序列号。如果只调试一个目标,可以把这个条目注释掉。

    在项目BSP/SEGGER/K66FN2M0_emPower目录下,使用SES打开Start_SEGGER_emPower.emProject工程,构建生成Start_emPower.elf。
    16.png
    注意:
    解压下载的NXP MK66F器件的SVD后,MK66F18.svd文件位于Keil. kinetis_k60_dfp .1.5.0/ SVD下。将此文件夹复制到emPower文件夹。
    17.png
    最后一步是设置ARM GDB工具链。按F1,输入“config”。从下拉菜单中选择C/ c++:Edit Configurations (JSON)
    18.png
    在JSON配置文件中,需要添加编译器路径,如下:

    1. {
    2.      "configurations": [
    3.     {
    4.       "name": "Win32",
    5.       "includePath": [
    6.       "${workspaceFolder}/**",
    7.      "${workspaceFolder}/GUI/Inc"
    8.   ],
    9.   "defines": [
    10.       "_DEBUG",
    11.       "UNICODE",
    12.       "_UNICODE"
    13.   ],
    14.   "intelliSenseMode": "gcc-x64",
    15.   "compilerPath": " D:\\Program Files (x86)\\GNU Arm Embedded Toolchain\\10 2020-q4-major\bin\\arm-none-eabi-gcc.exe"
    16.   }
    17.   ],
    18. "version": 4
    19. }
    复制代码
    最终结果:
    19.png
    在setting文件中,我们必须指定armToolchainPath。按F1并键入“settings”,选择“Open settings (JSON)”:
    20.png
    "cortex-debug.armToolchainPath": "C:\\Tool\\C\\Arm\\7_2018-q2-update\\bin"一行

    应该指向arm-none-eabi-gdb.exe所在的文件夹:
    15.png
    现在设置已经全部完成。可以通过按F5或从RUN菜单→Start Debugging来开始调试。

    进入调试后,输出如下:
    21.png
    在左侧面板上可以查看调试变量(局部,全局和静态),调用堆栈,断点,MCU外设和内核寄存器等调试项目所需的信息。

    现在可以在Visual Studio Code中调试目标应用程序了。

    当你添加和设置用于调试和编译的扩展时,Visual Studio Code是一个很好的选择。在上述配置中,我们添加了“request”:“launch”选项,但如果希望连接到运行中的目标上,你可以简单地将其设置为“request”:“attach”。或者,可以添加一个extra.json文件连接到目标。通过上述配置,即可以在Visual Studio Code下使用J-Link调试了。




    签到签到
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2024-4-10 22:38
  • 签到天数: 1335 天

    [LV.10]以坛为家III

    88

    主题

    4292

    帖子

    12

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    9049
    最后登录
    2024-4-13
    发表于 2023-8-31 14:27:00 | 显示全部楼层
    我现在在公司电脑上面安装这一套开源的编译工具。
    但私下使用keil来调试代码。
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    昨天 08:31
  • 签到天数: 196 天

    [LV.7]常住居民III

    0

    主题

    363

    帖子

    0

    高级会员

    Rank: 4

    积分
    864
    最后登录
    2024-4-28
    发表于 2023-9-1 17:03:39 | 显示全部楼层
    "runToMain": true,
    这个可以改成
    "runToEntryPoint": "main",
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2024-4-29 07:54 , Processed in 0.130939 second(s), 23 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表