cancel
Showing results for 
Search instead for 
Did you mean: 

Erasing flash with vFlashErase packet - "Error executing event gdb-attach on target"

chriskuku
Senior III

I'm trying to program an STM32H503 target attached to STM32CubeIDE through the SWD header of a Nucleo-F411RE. It fails to connect (see log below):

Open On-Chip Debugger 0.12.0+dev-00623-g0ba753ca7 (2025-04-30-14:20) [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 V2J46M33 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.231434
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 0x6ba02477
Info : [STM32H503CBTx.ap0] Examination succeed
Info : [STM32H503CBTx.cpu] Cortex-M33 r0p4 processor detected
Info : [STM32H503CBTx.cpu] target has 8 breakpoints, 4 watchpoints
STM32H503CBTx.cpu in Non-Secure state
STM32H503CBTx TrustZone disabled
STM32H503CBTx.cpu work-area address is set to 0x20000000
STM32H503CBTx.cpu work-area is enabled
Info : [STM32H503CBTx.cpu] Examination succeed
Info : gdb port disabled
Info : starting gdb server for STM32H503CBTx.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 STM32H503CBTx.cpu:
/Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/gdb_helper.tcl:18: Error: TARGET: STM32H503CBTx.cpu - Not halted
in procedure 'gdb_attach_hook' called at file "/Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/target/stm32h5x.cfg", line 379
in procedure 'first_gdb_attach_hook' called at file "/Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.debug.openocd_2.3.100.202501240831/resources/openocd/st_scripts/gdb_helper.tcl", line 18
Info : device idcode = 0x10036474 (STM32H50xx - Rev Y : 0x1003)
Info : Product State = 0xED : 'Open'
Info : flash size = 128kbytes
Info : flash mode : dual-bank
Info : device idcode = 0x10036474 (STM32H50xx - Rev Y : 0x1003)
Info : Product State = 0xED : 'Open'
Info : flash size = 128kbytes
Info : flash mode : dual-bank
Info : New GDB Connection: 1, Target STM32H503CBTx.cpu, state: running
Warn : GDB connection 1 on target STM32H503CBTx.cpu not halted
undefined debug reason 8 (UNDEFINED) - target needs reset
Error: Failed to read memory at 0x00000000
Info : accepting 'gdb' connection on tcp/3333
Info : New GDB Connection: 2, Target STM32H503CBTx.cpu, state: running
Warn : GDB connection 2 on target STM32H503CBTx.cpu not halted
undefined debug reason 8 (UNDEFINED) - target needs reset
Error: Failed to read memory at 0x00000000
Error: timed out while waiting for target halted
Error executing event gdb-flash-erase-start on target STM32H503CBTx.cpu:
TARGET: STM32H503CBTx.cpu - Not halted
Error: Target not halted
Error: failed erasing sectors 0 to 2
Error: flash_erase returned -304
Info : dropped 'gdb' connection
shutdown command invoked
Info : dropped 'gdb' connection

 

1 REPLY 1
Ghofrane GSOURI
ST Employee

Hello @chriskuku 

To resolve this issue , ensure all SWD lines (SWDIO, SWCLK, GND, 3.3V, and especially NRST) are correctly connected and that the target is properly powered. Use short, reliable wires and verify the voltage at the target VDD pin. In STM32CubeIDE, set the debugger to "Connect under reset" mode . Update your STLINK firmware and STM32CubeIDE to the latest versions. If the target is protected or locked, use STM32CubeProgrammer to check and remove any readout protection or to perform a full chip erase.

THX

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.