Hi fpiSTM.
The first board on which I tried was a home made board. I connected STLink with the board via SWDIO SWCLK. I tried also to connect reset pin of the STLink with target reset, but still the same error.
So I moved to a BluePill board and Blink sketch. Same connections as above (SWDIO, SWCLK and reset) and still the same error.
[2023-04-01T18:13:55.117Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session connected. You can switch to "DEBUG CONSOLE" to see GDB interactions.
/home/luca/.arduino15/packages/STMicroelectronics/tools/xpack-openocd/0.12.0-1/bin/openocd -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s /home/luca/Arduino/Blink -f /home/luca/Programmi/arduino-ide_2.0.3_Linux_64bit/resources/app/plugins/cortex-debug/extension/support/openocd-helpers.tcl -f /tmp/arduino-sketch-1D6FDBDFE15223D462CC37CDCB623A6D/openocd.cfg
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:03)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
CDRTOSConfigure
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 : Listening on port 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
Info : clock speed 1000 kHz
Info : STLINK V2J30S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.174951
Info : [stm32f1x.cpu] Cortex-M3 r1p1 processor detected
Info : [stm32f1x.cpu] target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f1x.cpu on 50000
Info : Listening on port 50000 for gdb connections
Info : accepting 'gdb' connection on tcp/50000
[stm32f1x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x81000000 pc: 0x08004476 msp: 0x20004fe0
Info : device id = 0x20036410
Info : flash size = 64 KiB
Error: timed out while waiting for target halted
Error: timed out while waiting for target halted
Error executing event gdb-flash-erase-start on target stm32f1x.cpu:
TARGET: stm32f1x.cpu - Not halted
Error: Target not halted
Error: failed erasing sectors 0 to 27
Error: flash_erase returned -304
Error: timed out while waiting for target halted
shutdown command invoked
[2023-04-01T18:13:58.631Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session closed
GDB server session ended. This terminal will be reused, waiting for next session to start...
My PC configuration: Linux 64 bit (Kubuntu), Arduino IDE 2.0.3 and 2.0.4. On both Arduino IDE version there is the same error.
I remember that I didn't use reset pin connection on my first debug experiments.
Luca