STM32F103出现CPU could not be halted问题的解决方案

本文介绍了一种解决使用JLink时遇到无法读取CPU寄存器的问题的方法。通过修改HAL_MspInit函数中的配置,用__HAL_AFIO_REMAP_SWJ_NOJTAG替代__HAL_AFIO_REMAP_SWJ_DISABLE,成功解决了JLink警告及错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述:

**JLink Warning: CPU could not be halted

***JLink Error: Can not read register 15 (R15) while CPU is running
***JLink Error: Can not read register 16 (XPSR) while CPU is running
***JLink Error: Can not read register 0 (R0) while CPU is running
***JLink Error: Can not read register 1 (R1) while CPU is running
***JLink Error: Can not read register 2 (R2) while CPU is running
***JLink Error: Can not read register 3 (R3) while CPU is running
***JLink Error: Can not read register 4 (R4) while CPU is running
***JLink Error: Can not read register 5 (R5) while CPU is running
***JLink Error: Can not read register 6 (R6) while CPU is running
***JLink Error: Can not read register 7 (R7) while CPU is running
***JLink Error: Can not read register 8 (R8) while CPU is running
***JLink Error: Can not read register 9 (R9) while CPU is running
***JLink Error: Can not read register 10 (R10) while CPU is running
***JLink Error: Can not read register 11 (R11) while CPU is running
***JLink Error: Can not read register 12 (R12) while CPU is running
***JLink Error: Can not read register 13 (R13) while CPU is running
***JLink Error: Can not read register 14 (R14) while CPU is running
***JLink Error: Can not read register 15 (R15) while CPU is running
***JLink Error: Can not read register 16 (XPSR) while CPU is running
***JLink Error: Can not read register 17 (MSP) while CPU is running
***JLink Error: Can not read register 18 (PSP) while CPU is running

***JLink Error: Can not read register 20 (CFBP) while CPU is running


解决方案

将HAL_MspInit()的__HAL_AFIO_REMAP_SWJ_DISABLE();注释掉,换成
__HAL_AFIO_REMAP_SWJ_NOJTAG();

Open On-Chip Debugger 0.12.0+dev-00623-g0ba753ca7 (2025-04-30-14:17) [https://github.com/STMicroelectronics/OpenOCD] Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : Listening on port 6666 for tcl connections Info : Listening on port 4444 for telnet connections Info : STLINK V2J46S7 (API v2) VID:PID 0483:3748 Info : Target voltage: 3.285562 Info : Unable to match requested speed 8000 kHz, using 4000 kHz Info : Unable to match requested speed 8000 kHz, using 4000 kHz Info : clock speed 4000 kHz Info : stlink_dap_op_connect(connect) Info : SWD DPIDR 0x1ba01477 Info : [STM32F103C8Tx.cpu] Cortex-M3 r1p1 processor detected Info : [STM32F103C8Tx.cpu] target has 6 breakpoints, 4 watchpoints Info : [STM32F103C8Tx.cpu] Examination succeed Info : starting gdb server for STM32F103C8Tx.cpu on 3333 Info : Listening on port 3333 for gdb connections Info : accepting 'gdb' connection on tcp/3333 Error: timed out while waiting for target halted Error executing event gdb-attach on target STM32F103C8Tx.cpu: C:/ST/STM32CubeIDE_1.19.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/gdb_helper.tcl:18: Error: TARGET: STM32F103C8Tx.cpu - Not halted in procedure 'gdb_attach_hook' called at file "C:/ST/STM32CubeIDE_1.19.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/target/stm32f1x.cfg", line 184 in procedure 'first_gdb_attach_hook' called at file "C:/ST/STM32CubeIDE_1.19.0/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/gdb_helper.tcl", line 18 Info : device id = 0x00006410 Info : flash size = 128 KiB Warn : GDB connection 1 on target STM32F103C8Tx.cpu not halted undefined debug reason 8 (UNDEFINED) - target needs reset Info : accepting 'gdb' connection on tcp/3333 Warn : GDB connection 2 on target STM32F103C8Tx.cpu not halted undefined debug reason 8 (UNDEFINED) - target needs reset Error: timed out while waiting for target halted Error executing event gdb-flash-erase-start on target STM32F103C8Tx.cpu: TARGET: STM32F103C8Tx.cpu - Not halted Error: Target not halted Error: failed erasing sectors 0 to 4 Error: flash_erase returned -304 Info : dropped 'gdb' connection shutdown command invoked Info : dropped 'gdb' connection
最新发布
07-11
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

高咩咩在人间

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值