尝试在 STM32L476 Nucleo-64 板上调试我的示例眨眼 LED 代码,但 gdb 无法连接到 OpenOCD(连接几乎立即因错误而断开)。我到处读过很多帖子,但没有一个有帮助。尝试使用 -c 添加命令到 OpenOCD,但行为没有改变。
我的代码在 Eclipse 的发布和调试配置中进行编译。我可以使用拖放功能刷新 bin 文件(虽然该板具有内置 STLink 插件),并且看起来代码在板上完美运行(LED 闪烁)。
在Centos7上使用以下版本进行交叉编译:
由于使用 eclipse 不起作用,我尝试了命令行,
(我在这个环境中不是经验丰富的开发人员,所以我找不到比 stm32l4discovery.cfg 更接近我的 stm32l476 板的配置文件,如果使用它可能出现一些问题,请告诉我)
./bin/openocd -f scripts/board/stm32l4discovery.cfg -c "init"
Run Code Online (Sandbox Code Playgroud)
开始,
GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-18-11:37)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 500 kHz
adapter_nsrst_delay: 100
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : clock speed 500 kHz
Info : STLINK V2J28M17 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.244386
Info : stm32l4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Run Code Online (Sandbox Code Playgroud)
然后启动GDB:
./arm-none-eabi-gdb ~/eclipse-workspace/test-blink-led/Debug/test-blink-led.elf
Run Code Online (Sandbox Code Playgroud)
然后在 gdb 中运行以下命令:
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
Remote connection closed
Run Code Online (Sandbox Code Playgroud)
如图所示,gdb 连接立即断开,OpenOCD 提示以下错误:
Info : accepting 'gdb' connection on tcp/3333
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080022e6 msp: 0x20017ff8
Info : device id = 0x10076415
Warn : STM32 flash size failed, probe inaccurate - assuming 1024k flash
Info : flash size = 1024kbytes
Error: auto_probe failed
Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use 'gdb_memory_map disable'.
Error: attempted 'gdb' connection rejected
Error: jtag status contains invalid mode value - communication failure
Polling target stm32l4x.cpu failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 100ms
Run Code Online (Sandbox Code Playgroud)
因此,对于那些每天在类似平台上这样做的极客来说,任何人都可以帮助我并告诉我我哪里做错了。缺少任何编译时标志是否可能会导致此问题?
我已经挠头好几天了,所以请让我得到你的提示。
原因之一可能是您的 STLINK 固件看起来相当旧(如您的日志所示,STLINK V2J28M17)。我建议下载STSW-LINK007应用程序来升级固件。该软件是一个多平台 Java 应用程序。它在 Debian GNU/Linux 中完美运行。
目前,我使用另一个 gdb 服务器texane/stlink来执行 GDB 调试任务,在某些 Nucleo 和自定义板上没有任何问题。我使用target extended-remote
命令加入服务器的端口。也许您也可以尝试在 OpenOCD 下使用此命令进行连接。