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

Arduino IDE调试STM32失败:libusb_open()报LIBUSB_ERROR_ACCESS错误求助

问题排查与解决方案

一、解决libusb_open() failed with LIBUSB_ERROR_ACCESS权限问题

这个错误是Windows系统限制ST-LINK设备访问权限导致的,可按以下步骤处理:

  • 以管理员身份启动Arduino IDE:右键Arduino图标选择「以管理员身份运行」,规避系统权限拦截。
  • 检查并修复ST-LINK驱动:打开设备管理器,查看「通用串行总线设备」下的ST-LINK设备(可能显示为STMicroelectronics STLink Virtual COM Port或ST-LINK Debug),若有黄色感叹号,卸载驱动后通过STM32CubeProgrammer重新安装,或直接更新ST官方提供的ST-LINK驱动包。
  • 释放占用ST-LINK的进程:打开任务管理器,结束STM32CubeProgrammer、OpenOCD相关进程,避免设备端口被占用。

二、解决单步调试无效、全局变量不更新问题

1. 确认调试配置正确性

  • 在Arduino IDE中,进入「工具 > 调试工具」,确保选中ST-LINK (SWD),且开发板设置为Nucleo F103RB。
  • 切换上传方式:调试前需将「工具 > 上传方式」改为ST-LINK (SWD),而非单独的STM32CubeProgrammer (SWD)——普通上传模式不会生成调试符号,会导致断点失效、变量无法监控。

2. 关闭编译优化并检查变量定义

  • 禁用编译优化:进入「工具 > 编译优化级别」,选择-O0 (无优化)。高优化级别会让编译器删减循环逻辑或变量引用,导致调试异常。
  • 确保全局变量可调试:避免将全局变量声明为const,示例可调试代码:
    int loopCount = 0;
    
    void setup() {
      pinMode(LED_BUILTIN, OUTPUT);
    }
    
    void loop() {
      loopCount++;
      digitalWrite(LED_BUILTIN, HIGH);
      delay(1000);
      digitalWrite(LED_BUILTIN, LOW);
      delay(1000);
    }
    

3. 重置调试会话与硬件

  • 冷重启开发板:断开电源10秒后重新连接,再启动调试会话,可修复ST-LINK异常调试状态。
  • 调试界面重启:在Arduino调试面板点击「重启」按钮,而非重新上传,确保调试器重新挂载到MCU。

4. 升级ST-LINK固件

从日志看当前ST-LINK固件版本为V2J45M31,若问题仍存在,可通过STM32CubeProgrammer升级固件:连接开发板后打开软件,进入「ST-LINK」选项卡点击「升级固件」。


相关日志参考

上传日志

Sketch uses 11024 bytes (8%) of program storage space. Maximum is 131072 bytes.
Global variables use 1136 bytes (5%) of dynamic memory, leaving 19344 bytes for local variables. Maximum is 20480 bytes.
Selected interface: swd
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.14.0                  
      -------------------------------------------------------------------

ST-LINK SN  : 066FFF504857788667214513
ST-LINK FW  : V2J45M31
Board       : NUCLEO-F103RB
Voltage     : 3.25V
SWD freq    : 4000 KHz
Connect mode: Under Reset
Reset mode  : Hardware reset
Device ID   : 0x410
Revision ID : Rev X
Device name : STM32F101/F102/F103 Medium-density
Flash size  : 128 KBytes
Device type : MCU
Device CPU  : Cortex-M3
BL Version  : --


`Memory Programming ...
Opening and parsing file: Blink.ino.bin
  File          : Blink.ino.bin
  Size          : 11.05 KB 
  Address       : 0x08000000 


Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 11]
Download in Progress:


File download complete
Time elapsed during download operation: 00:00:00.825`

调试会话日志

RUNNING Program ... 
  Address:      : 0x8000000
Application is running, Please Hold on...
Start operation achieved successfully
xPack Open On-Chip Debugger 0.12.0+dev-01685-gb9224c0c0-dirty (2024-08-02-19:51)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
DEPRECATED! use 'gdb port', not 'gdb_port'
DEPRECATED! use 'tcl port' not 'tcl_port'
CDRTOSConfigure
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
Info : clock speed 1000 kHz
Info : STLINK V2J45M31 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.250952
Info : [stm32f1x.cpu] Cortex-M3 r1p1 processor detected
Info : [stm32f1x.cpu] target has 6 breakpoints, 4 watchpoints
Info : [stm32f1x.cpu] Examination succeed
Info : [stm32f1x.cpu] starting gdb server on 50000
Info : Listening on port 50000 for gdb connections
Info : accepting 'gdb' connection on tcp/50000
[stm32f1x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x81000000 pc: 0x08000210 msp: 0x20004fe0
Info : device id = 0x20036410
Info : flash size = 128 KiB
[stm32f1x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08001e94 msp: 0x20005000
[stm32f1x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08001e94 msp: 0x20005000
[stm32f1x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08001e94 msp: 0x20005000
[stm32f1x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08001e94 msp: 0x20005000

权限错误日志

xPack Open On-Chip Debugger 0.12.0+dev-01685-gb9224c0c0-dirty (2024-08-02-19:51)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
DEPRECATED! use 'gdb port', not 'gdb_port'
DEPRECATED! use 'tcl port' not 'tcl_port'
CDRTOSConfigure
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 50008 for tcl connections
Info : Listening on port 50009 for telnet connections
Info : clock speed 1000 kHz
Error: libusb_open() failed with LIBUSB_ERROR_ACCESS
Error: open failed


[2025-01-10T15:52:56.288Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session closed
GDB server session ended. This terminal will be reused, waiting for next session to start...

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 02:32:33