gdb 无法连接到 stm32 上的 OpenOCD
Gdb can't connect to OpenOCD on stm32
尝试在 STM32L476 Nucleo-64 板上调试我的示例 blink_led 代码,但 gdb 无法连接到 OpenOCD(连接几乎立即断开并出现错误)。我在这里和那里阅读了大量帖子,但其中 none 有帮助。尝试使用 -c 向 OpenOCD 添加命令,但行为没有改变。
我的代码在 Eclipse 的 Release 和 Debug 配置中编译。我可以使用拖放来刷新 bin 文件(而该板具有内置的 STLink 附加组件)并且看起来代码在板上完美运行(LED 闪烁)。
使用以下版本在Centos7上交叉编译:
- 工具链(gdb):gcc-arm-none-eabi-8-2018-q4-major
- OpenOCD:0.10.0-11-20190118-1134
由于使用 eclipse 不起作用,我尝试了命令行,
(我在这个环境中不是经验丰富的开发人员,所以我找不到比 stm32l4discovery.cfg 更接近我的 stm32l476 板的任何配置文件,如果使用它可能有一些问题请告诉我)
./bin/openocd -f scripts/board/stm32l4discovery.cfg -c "init"
开始了,
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
然后启动 GDB:
./arm-none-eabi-gdb ~/eclipse-workspace/test-blink-led/Debug/test-blink-led.elf
然后 运行 在 gdb 中执行以下命令:
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
Remote connection closed
因为它显示 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
所以那些每天在类似平台上做这件事的极客们,谁能帮助我,告诉我我哪里做错了。缺少任何编译时标志是否会导致此问题?
这几天我都在摸不着头脑,所以请告诉我你的提示。
其中一个原因可能是您的 STLINK 固件看起来很旧(如您的日志所示,STLINK V2J28M17)。我建议下载 STSW-LINK007 应用程序来升级固件。该软件是一个多平台 Java 应用程序。它在 Debian GNU/Linux.
中完美运行
目前,我使用另一个 gdb 服务器 texane/stlink 来执行我的 GDB 调试任务,在某些 Nucleo 和自定义板上没有任何问题。我使用 target extended-remote
命令加入服务器的端口。也许您也可以尝试在 OpenOCD 下使用此命令进行连接。
试试看
远程登录本地主机 4444
它对我有用,而 3333 没有
尝试在 STM32L476 Nucleo-64 板上调试我的示例 blink_led 代码,但 gdb 无法连接到 OpenOCD(连接几乎立即断开并出现错误)。我在这里和那里阅读了大量帖子,但其中 none 有帮助。尝试使用 -c 向 OpenOCD 添加命令,但行为没有改变。
我的代码在 Eclipse 的 Release 和 Debug 配置中编译。我可以使用拖放来刷新 bin 文件(而该板具有内置的 STLink 附加组件)并且看起来代码在板上完美运行(LED 闪烁)。
使用以下版本在Centos7上交叉编译:
- 工具链(gdb):gcc-arm-none-eabi-8-2018-q4-major
- OpenOCD:0.10.0-11-20190118-1134
由于使用 eclipse 不起作用,我尝试了命令行,
(我在这个环境中不是经验丰富的开发人员,所以我找不到比 stm32l4discovery.cfg 更接近我的 stm32l476 板的任何配置文件,如果使用它可能有一些问题请告诉我)
./bin/openocd -f scripts/board/stm32l4discovery.cfg -c "init"
开始了,
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
然后启动 GDB:
./arm-none-eabi-gdb ~/eclipse-workspace/test-blink-led/Debug/test-blink-led.elf
然后 运行 在 gdb 中执行以下命令:
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
Remote connection closed
因为它显示 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
所以那些每天在类似平台上做这件事的极客们,谁能帮助我,告诉我我哪里做错了。缺少任何编译时标志是否会导致此问题?
这几天我都在摸不着头脑,所以请告诉我你的提示。
其中一个原因可能是您的 STLINK 固件看起来很旧(如您的日志所示,STLINK V2J28M17)。我建议下载 STSW-LINK007 应用程序来升级固件。该软件是一个多平台 Java 应用程序。它在 Debian GNU/Linux.
中完美运行目前,我使用另一个 gdb 服务器 texane/stlink 来执行我的 GDB 调试任务,在某些 Nucleo 和自定义板上没有任何问题。我使用 target extended-remote
命令加入服务器的端口。也许您也可以尝试在 OpenOCD 下使用此命令进行连接。
试试看 远程登录本地主机 4444
它对我有用,而 3333 没有