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

STM32 NUCLEOF103RB调试报‘Unable to stat debugging’错误求助

STM32 NUCLEOF103RB VSCode调试连接失败问题排查

在VSCode中使用STM32 VSC扩展开发,调试STM32 NUCLEOF103RB时出现Unable to start debugging错误:

  • 终端显示编译任务成功完成,但调试器无法连接debug server
  • 已尝试重新插拔开发板,调试时板载ST-LINK指示灯正常红绿交替闪烁,但程序无法上传
  • 已允许调试器访问网络,排除Windows Defender拦截问题
  • 调试器直接崩溃,相关信息如下:

DEBUG CONSOLE输出

1: (72) LaunchOptions{"name":"Launch","type":"cppdbg","request":"launch","cwd":"D:\\Programs\\ENV\\STM32_plugged\\CUBER\\WIN_TS_IV\\TRY_V","program":"D:\\Programs\\ENV\\STM32_plugged\\CUBER\\WIN_TS_IV\\TRY_V\\build\\debug\\build\\TRY_V.elf","MIMode":"gdb","miDebuggerPath":"C:/ST/STM32CubeIDE_1.13.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.1.202309131626/tools/bin/arm-none-eabi-gdb.exe","miDebuggerServerAddress":"localhost:3333","debugServerPath":"C:/ST/STM32CubeIDE_1.13.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.1.0.202305091550/tools/bin/ST-LINK_gdbserver.exe","debugServerArgs":"--stm32cubeprogrammer-path C:/ST/STM32CubeIDE_1.13.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.1.0.202305091550/tools/bin --swd --port-number 3333","serverStarted":"Waiting for connection on port .*//.//.//.","stopAtConnect":true,"postRemoteConnectCommands":[{"text":"load build/debug/build/TRY_V.elf"}],"logging":{"engineLogging":true},"preLaunchTask":"Build","__configurationTarget":6,"configSource":"workspaceFolder","debugType":"debug","__sessionId":"48b983e1-61a7-44a6-891d-b74ba9ff307b"}

我的launch.json文件

{
  "version": "0.2.0",
  "configurations": [
   
    {
      "name": "Launch",
      "type": "cppdbg",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "program": "${command:cmake.launchTargetPath}",
      "MIMode": "gdb",
      "miDebuggerPath": "C:/ST/STM32CubeIDE_1.13.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.1.202309131626/tools/bin/arm-none-eabi-gdb.exe",
      "miDebuggerServerAddress": "localhost:3333",
      "debugServerPath": "C:/ST/STM32CubeIDE_1.13.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.1.0.202305091550/tools/bin/ST-LINK_gdbserver.exe",
      "debugServerArgs": "--stm32cubeprogrammer-path C:/ST/STM32CubeIDE_1.13.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.1.0.202305091550/tools/bin --swd --port-number 3333",
      "serverStarted": "Waiting for connection on port .*//.//.//.",
      "stopAtConnect": true,
      "postRemoteConnectCommands": [
        {
          "text": "load build/debug/build/TRY_V.elf"
        }
      ],
      "logging": {
        "engineLogging": true
      },
      "preLaunchTask": "Build"
    }
  ]
}

排查建议

  • 修正serverStarted正则匹配:当前配置的"Waiting for connection on port .*//.//.//."存在转义错误,ST-LINK GDB Server实际输出为Waiting for connection on port 3333...,建议改为"Waiting for connection on port \\d+..."或更简单的"Waiting for connection on port",避免因匹配失败导致VSCode误判server未启动。
  • 调整postRemoteConnectCommands路径:load build/debug/build/TRY_V.elf为相对路径,若与cwd(工作区根目录)不匹配会导致GDB找不到文件,可替换为绝对路径或使用变量"load ${command:cmake.launchTargetPath}"。
  • 手动启动ST-LINK GDB Server测试:直接运行debugServerPath中的程序并携带参数,排查server本身是否正常。命令示例:
    "C:/ST/STM32CubeIDE_1.13.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.win32_2.1.0.202305091550/tools/bin/ST-LINK_gdbserver.exe" --stm32cubeprogrammer-path "C:/ST/STM32CubeIDE_1.13.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.win32_2.1.0.202305091550/tools/bin" --swd --port-number 3333
    
    启动失败会显示具体错误,比如驱动问题、开发板连接异常。
  • 验证ELF文件完整性:用arm-none-eabi-objdump检查编译生成的ELF文件是否有效,命令示例:
    "C:/ST/STM32CubeIDE_1.13.2/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.win32_1.1.1.202309131626/tools/bin/arm-none-eabi-objdump.exe" -h D:\Programs\ENV\STM32_plugged\CUBER\WIN_TS_IV\TRY_V\build\debug\build\TRY_V.elf
    
  • 简化launch.json配置:暂时去掉stopAtConnect和postRemoteConnectCommands,让VSCode自动处理程序下载,测试是否能成功连接。调整后的配置片段:
    "stopAtConnect": false,
    "postRemoteConnectCommands": []
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 14:20:58