2025-09-13 7:57 AM
I'm trying out semihosting with openocd in STM32CubeIDE. For this purpose I added the call
initialise_monitor_handles();
in main.c as the second call after HAL_Init();
I have STLINK(gdb server) configured. The program goes into that call (initialise_monitor_handles) but never returns.
Trying OpenOCD gives another error:
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.224068
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
Error: Failed to read memory at 0x00000000
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