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

Win10下OpenOCD调试STM32时GDB意外断开问题求助

问题现象

Windows 10环境下,使用STLink、OpenOCD配合VSCode调试Bluepill(STM32F103C8)开发板时,弹出错误提示:

OpenOCD GDB Server Quit Unexpectedly. See gdb-server output for more details.

终端输出运行日志:

Open On-Chip Debugger 0.11.0 (2021-11-18) [https://github.com/sysprogs/openocd]
Licensed under GNU GPL v2
libusb1 09e75e98b4d9ea7909e8837b7a3f00dda4589dc3
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
CDRTOSConfigure
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
Info : Listening on port 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
Info : clock speed 1000 kHz
Info : STLINK V2J36S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.186911
Info : stm32f1x.cpu: Cortex-M3 r1p1 processor detected
Info : stm32f1x.cpu: target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f1x.cpu on 50000
Info : Listening on port 50000 for gdb connections
[2022-06-07T02:43:25.028Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session closed
GDB server session ended. This terminal will be reused, waiting for next session to start...

当前使用的launch.json配置如下:

{
    "version": "0.2.0",
    "configurations": 
    [
        {
            "name": "GDB",
            "cwd": "${workspaceFolder}",
            "executable": "./Test/Build/snake.elf",
            "request": "launch",
            "type": "cortex-debug",
            "runToEntryPoint": "main",
            "servertype": "openocd",
            "device": "STM32f103C8",
            "interface": "swd",
            "configFiles": 
            [
                "interface/stlink.cfg",
                "target/stm32f1x.cfg"
            ]
        }
    ]
}
排查解决思路

从日志判断,OpenOCD已经成功识别STLink、检测到STM32F1内核,GDB服务端口也正常完成监听,服务是在等待GDB连接阶段意外退出的,按以下优先级逐一排查:

  • 检查Cortex-Debug插件配置的OpenOCD路径是否正确,优先使用插件自带的OpenOCD版本,避免第三方编译分支版本(比如日志里的sysprogs编译版本)和插件通信逻辑不兼容
  • 检查STLink驱动是否正确安装,Windows下不要使用系统默认加载的STLink驱动,换成WinUSB版本驱动即可:打开Zadig工具选中已连接的STLink设备,将驱动替换为WinUSB后重新插拔调试器
  • 修正launch.json配置冲突:当前配置同时指定了interface: swd和configFiles里的interface/stlink.cfg,容易出现参数覆盖问题,直接删掉interface字段;同时补充"showDevDebugOutput": true字段打开完整调试日志,能直接看到GDB连接阶段的具体报错信息
  • 排查端口占用问题:OpenOCD默认使用的50000、50001、50002端口如果被之前异常退出的OpenOCD进程占用,会导致新启动的服务直接退出,打开任务管理器结束所有残留的openocd.exe进程后再重试
  • 校验elf文件有效性:确认./Test/Build/snake.elf路径下的文件真实存在,是编译生成的带完整调试信息的有效elf文件,文件路径不要包含中文、特殊空格或全角字符
  • 降低SWD通信速率:在配置里追加OpenOCD启动参数,把初始通信速率降到100kHz,排除接线过长、引脚接触不良导致的通信中断,配置参考:
    "openOCDLaunchCommands": [
        "adapter speed 100"
    ]
    
  • 检查开发板供电:日志里检测到目标电压3.18V略低于常规3.3V工作电压,确认STLink的3.3V供电引脚接触良好,或者给开发板外接稳定独立供电后再尝试连接

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.01 03:03:39