You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode用JLink调试Cortex-M0(XMC1302)时卡在等待GDB连接

问题

在Windows 10环境下首次使用VSCode搭配JLink V9调试Infineon XMC1302(Cortex-M0)嵌入式MCU的C程序,设备通过SWD(2线+GND)连接,遇到以下问题:

  • 启动调试(F5)时,VSCode提示无法启动JLink GDB Server,报错Error: spawn JLinkGDBServerCL.exe ENOENT
  • 手动在命令行启动JLinkGDBServerCL.exe后,程序卡在“Waiting for GDB connection...”

已确认JLink可正常烧录Hex文件及读取Flash,也尝试过手动执行VSCode相关命令、使用GUI版JLinkGDBServer,但问题仍未解决。

附VSCode配置片段

settings.json片段

{
    "cmake.showOptionsMovedNotification": false,
    "git.enableSmartCommit": true,
    "git.confirmSync": false,
    "cmake.configureOnOpen": true,
    "[cpp]": {
        "editor.defaultFormatter": "ms-vscode.cpptools"
    },
    "cmake.pinnedCommands": [
        "workbench.action.tasks.configureTaskRunner",
        "workbench.action.tasks.runTask"
    ],
    "arduino.useArduinoCli": true,
    "clangd.detectExtensionConflicts": false,
    "cortex-debug.JLinkGDBServerPath.windows": "C:/Program Files/SEGGER/JLink_V812/JLinkGDBServerCL.exe", 
    "cortex-debug.JLinkGDBServerPath": "C:/Program Files (x86)/SEGGER/JLink_V612a/JLinkGDBServerCL.exe",
    "makefile.configureOnOpen": true
}

launch.json片段

"configurations": [
        {
            "name": "Launch (JLink)",
            "type": "cortex-debug",
            "request": "launch",
            "cwd": "${workspaceFolder}",
            "executable": "build/last_config/mtb-example-xmc-gpio-toggle.elf",
            "servertype": "jlink",
            //"device": "XMC1302-T028x0064",
            "device": "XMC1302-T038x0064",
            // : "2000",
            "interface": "swd",
            "serialNumber": "",
            "preLaunchCommands": [
                // Program via the hex file to get complete coverage
                "exec-file build/last_config/mtb-example-xmc-gpio-toggle.hex"
            ],
            "overrideRestartCommands": [
                "starti"
            ],
            // svdFile is optional, it can be very large.
            "svdFile": "../mtb_shared/mtb-xmclib-cat3/release-v4.4.0/CMSIS/Infineon/SVD/XMC1300.svd",
            "breakAfterReset": true,
            "runToEntryPoint": "main",    // Specifies application entry point name where program will halt
            "preLaunchTask": "Build", // Set this to run a task from tasks.json before
                                                     // starting a debug session
            "showDevDebugOutput": "raw" 
        },
解决建议

针对Error: spawn JLinkGDBServerCL.exe ENOENT报错

  • 清理路径配置冲突:settings.json中同时设置了cortex-debug.JLinkGDBServerPath.windows和cortex-debug.JLinkGDBServerPath,Windows环境下优先读取带.windows的配置项。先确认C:/Program Files/SEGGER/JLink_V812/JLinkGDBServerCL.exe路径是否真实存在、文件未被误删,然后删除其中一个冗余配置,保留对应实际安装版本的正确路径。
  • 验证路径格式:确保路径用正斜杠/或双反斜杠\\,避免单反斜杠的转义问题。
  • 检查JLink版本兼容性:JLink V9硬件建议搭配较新的JLink软件版本,V8.12版本兼容,但如果路径正确仍报错,可重新安装JLink软件,勾选“添加到系统PATH”选项,让系统能直接识别JLinkGDBServerCL.exe。

针对手动启动JLinkGDBServer后卡在“Waiting for GDB connection...”

  • 明确GDB端口配置:默认JLink GDB Server用2331端口,若launch.json未指定,需确保该端口未被其他程序占用。可在launch.json中添加"gdbPort": 2331明确指定端口。
  • 删除冗余的预启动命令:executable字段已经指定了elf文件,cortex-debug会自动处理程序下载,无需再通过preLaunchCommands中的exec-file加载hex,建议删除这条命令避免冲突。
  • 确认设备型号匹配:launch.json中device设置为XMC1302-T038x0064,需和实际硬件型号完全一致,可通过JLink Commander执行connect命令验证设备型号是否被正确识别。
  • 检查SWD连接稳定性:重新插拔SWD线,确保SWDIO、SWCLK、GND引脚连接正确,避免接触不良(烧录正常不代表调试连接完全稳定)。
  • 释放JLink硬件资源:关闭其他占用JLink的程序(如JLink GUI、Keil等),再尝试调试。

内容的提问来源于stack exchange,提问作者mstrens

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 13:23:15