我正在尝试在 CLion 中调试 STM32F446ZE 微控制器的 C++ 代码,但没有成功。
我一直在使用VsCode + CortexDebug,没有任何问题。 VsCode 中成功调试会话的示例输出:
openocd -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s /repo
-f /home/user/vscode/extensions/marus25.cortex-debug-1.10.0/support/openocd-helpers.tcl
-f interface/stlink.cfg -f target/stm32f4x.cfg
Open On-Chip Debugger 0.12.0-00017-g26301c4dd (2023-06-05-10:38) [https://github.com/STMicroelectronics/OpenOCD]
Licensed under GNU GPL v2
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 : Listening on port 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
Info : clock speed 2000 kHz
Info : STLINK V2J38M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.248358
Info : [stm32f4x.cpu] Cortex-M4 r0p1 processor detected
Info : [stm32f4x.cpu] target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f4x.cpu on 50000
Info : Listening on port 50000 for gdb connections
Info : accepting 'gdb' connection on tcp/50000
[stm32f4x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x81000000 pc: 0x080044e2 psp: 0x20001700
Info : device id = 0x10006421
Info : flash size = 512 KiB
Info : flash size = 512 bytes
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
[stm32f4x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000970 msp: 0x20020000
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
[stm32f4x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000970 msp: 0x20020000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Padding image section 0 at 0x080001c4 with 60 bytes
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
[stm32f4x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000970 msp: 0x20020000
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
[stm32f4x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000970 msp: 0x20020000
所有断点都有效,响应灵敏,SVD/memview 工作良好。
现在,当我尝试使用 CLion + OpenOCD 下载并使用(据我所知)相同的配置运行时:
/usr/local/bin/openocd -c "tcl_port disabled" -c "gdb_port 3333" -c "telnet_port 4444" -s /usr/local/share/openocd/scripts -f board/stm32f4discovery.cfg -c "init;reset init;" -c "echo (((READY)))"
Open On-Chip Debugger 0.12.0-00017-g26301c4dd (2023-06-05-10:38) [https://github.com/STMicroelectronics/OpenOCD]
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
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : clock speed 2000 kHz
Info : STLINK V2J38M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.249934
Info : [stm32f4x.cpu] Cortex-M4 r0p1 processor detected
Info : [stm32f4x.cpu] target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f4x.cpu on 3333
Info : Listening on port 3333 for gdb connections
[stm32f4x.cpu] halted due to breakpoint, current mode: Thread
xPSR: 0x01000000 pc: 0x08002c76 msp: 0x2001ffa0
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
[stm32f4x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000970 msp: 0x20020000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
(((READY)))
Info : tcl server disabled
Info : Listening on port 4444 for telnet connections
Info : accepting 'gdb' connection on tcp/3333
Info : device id = 0x10006421
Info : flash size = 512 KiB
Info : flash size = 512 bytes
Warn : Prefer GDB command "target extended-remote :3333" instead of "target remote :3333"
Debugger connected to tcp:localhost:3333
使用“openocd.cfg”(也尝试过 board/stm32f4discovery.cfg 和 board/st_nucleo_f4.cfg,结果相同)
source [find interface/stlink-v2.cfg]
source [find target/stm32f4x.cfg]
似乎一切都很顺利,但是...
...MCU 在系统时钟配置上立即崩溃,而在使用 VsCode 和 Cortex 调试时不会发生这种情况。
此时我怀疑gdb+openocd配置有问题,但我无法弄清楚。 我在 OpenOCD 日志中注意到的唯一区别是:
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 : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
如有任何帮助,我们将不胜感激。
奖金: 当在 CLion 中使用带有 st-util 的嵌入式 GDB 时,它可以正常工作,不会崩溃,但速度太慢,以至于无法使用。
同样的问题:我的 ctg 文件是这样的:
# 1. choose st-link/j-link/dap-link etc.##########################################
# adapter driver includes: ftdi, usb_blaster, usbprog, jlink,
# vsllink, rlink, ulink, arm-jtag-ew, hla, osbdm, opendous,
# picoprobe, cmsis-dap, xds110, st-link
adapter driver jlink
# the above line equal to the following line
# source [find interface/jlink.cfg]
# 2. select SWD port: swd, jtag
transport select swd
# 3. set adapter download speed (kHz)
adapter speed 2000
# 4. set flash size(0x100000=1048KB=1MB, 0x00080000=512kB)
# set FLASH_SIZE 0x100000
set FLASH_SIZE 0x080000
# set target type
source [find target/stm32f4x.cfg]
# connect under reset
# reset_config srst_only
运行后出现错误:
[0m[0mOpen On-Chip Debugger 0.12.0 (2023-07-12) [https://github.com/sysprogs/openocd]
Licensed under GNU GPL v2
libusb1 09e75e98b4d9ea7909e8837b7a3f00dda4589dc3
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : J-Link V9 compiled May 7 2021 16:26:12
Info : Hardware version: 9.70
Info : VTarget = 3.243 V
Info : clock speed 2000 kHz
Info : SWD DPIDR 0x2ba01477
Info : [stm32f4x.cpu] Cortex-M4 r0p1 processor detected
Info : [stm32f4x.cpu] target has 6 breakpoints, 4 watchpoints
Info : gdb port disabled
[stm32f4x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xb9337822 msp: 0x4c05b510
** Programming Started **
Info : device id = 0x10076413
Info : flash size = 512 KiB
** Programming Finished **
Error: [stm32f4x.cpu] clearing lockup after double fault
shutdown command invoked