Settting up STLink V3 with STM32 / Portenta H7

I have been struggling to setup my StLink V3 with the Portenta H7 breakout board.
Im using the supplied 20pin cable that came with the STLink V3SET kit.

I think i am a fair way in but i keep getting stuck with stlink/st-util/st gdb server errors out of my launch.json file. here is a sample error.

image

I have been over many post and tutes but i just can seem to get it working.

here is my launch.json config.

 "cwd": "${workspaceFolder}",
            "executable": "C:/Users/bucko/OneDrive/aElectronics/Projects/LCD_I2C/.pio/build/portenta_h7_m7/firmware.elf",
            "name": "Debug with ST-Util",
            "request": "launch",
            "type": "cortex-debug",
            "runToEntryPoint": "main",
            "showDevDebugOutput": "none",
            "servertype": "stutil",
            //"gdbpath": "${env:HOME}/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin",
            "armToolchainPath": "C:/Users/bucko/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin",
            "stutilpath": "C:/Users/bucko/.platformio/packages/tool-stm32duino/stlink"
            //"stutilpath": "${env:HOME}/.platformio/packages/tool-stm32duino/texane-stlink"

Here is my .ini file

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino
debug_tool = stlink
lib_deps = 
	https://github.com/maxgerhardt/Arduino_PortentaBreakout/archive/refs/heads/main.zip
	fmalpartida/LiquidCrystal @ ^1.5.0
build_flags = -I include
upload_port = COM5

Can anyone please help. i seem to be going around in circles but i beleive it is to do with my stlink/st gdb packages. For example i dont seem to have a .platformio/packages/tool-stlink/bin/st-util

So this is not using PlatformIO’s built-in debug capabilities at all. You’ve manually added the configuration for the cortex-debug VSCode extension, which is not needed in PlatformIO.

Can you delete the launch.json and let PlatformIO regenerate it cleanly? Ctrl+Shift+P → Rebuild Intellisense.

WIth your existing platformio.ini, PlatformIO should then just invoke OpenOCD with the stlink.cfg configuration (which also applies to ST-Link V3).

Thanks, did as instructed and 3 configs were built. These were here before as well. But non invoke STLink V3.
the launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug",
            "executable": "C:/Users/bucko/OneDrive/aElectronics/Projects/LCD_I2C/.pio/build/portenta_h7_m7/firmware.elf",
            "projectEnvName": "portenta_h7_m7",
            "toolchainBinDir": "C:/Users/bucko/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin",
            "internalConsoleOptions": "openOnSessionStart",
            "preLaunchTask": {
                "type": "PlatformIO",
                "task": "Pre-Debug"
            }
        },
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug (skip Pre-Debug)",
            "executable": "C:/Users/bucko/OneDrive/aElectronics/Projects/LCD_I2C/.pio/build/portenta_h7_m7/firmware.elf",
            "projectEnvName": "portenta_h7_m7",
            "toolchainBinDir": "C:/Users/bucko/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin",
            "internalConsoleOptions": "openOnSessionStart"
        },
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug (without uploading)",
            "executable": "C:/Users/bucko/OneDrive/aElectronics/Projects/LCD_I2C/.pio/build/portenta_h7_m7/firmware.elf",
            "projectEnvName": "portenta_h7_m7",
            "toolchainBinDir": "C:/Users/bucko/.platformio/packages/toolchain-gccarmnoneeabi@1.70201.0/bin",
            "internalConsoleOptions": "openOnSessionStart",
            "loadMode": "manual"
        }
    ]
}

Oh but they should.

Can you upload with this configuration normally? Then you should be able to debug.

yes i can load to the target via default dfu. i have not tried to upload via stlink yet. Do just set upload_protocol = stlink in my ini?

Yes it works via, upload_protocol = stlink. hmmmmm so 1/2 working then

What is the content of the “Debug Console” then when you start the regular PlatformIO debugging task (“PIO Debug”)

Thanks Max
Im not sure what happened but after i got the upload working i was looking at other options. i found configuration that allowed me to " Debug with STLink" , i slected this but it didnt work.
But then my PIO Debug started to work. Not sure why because my .json file hasnt changed.

Anyway thanks for your help, im going to bed now.

Seems like I’m having the same issue but the solution of resetting launch.json isn’t working for me. I’m using an STLink v3 standalone unit, but have also replicated using the STLink built into a Nucleo WL55JC1 board.

For me, I am able to read the chip’s flash and program it via CubeProgrammer over STLink, so I know the connections must be good, but OpenOCD seems to not be able to debug:

Reading symbols from C:\Users\toddr\dev\brainrise\BLT-firmware\.pio\build\portenta_h7_m7\firmware.elf...
done.
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = stlink
PlatformIO: Initializing remote target...
xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2021-10-16-21:19)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : tcl server disabled
Info : telnet server disabled
Info : clock speed 1800 kHz
Info : STLINK V3J11M3 (API v3) VID:PID 0483:374E
Info : Target voltage: 3.269103
Info : stm32h7x.cpu0: Cortex-M7 r1p1 processor detected
Info : stm32h7x.cpu0: target has 8 breakpoints, 4 watchpoints
Error: mem2array: Read @ 0x5c001004, w=4, cnt=1, failed
Error executing event examine-end on target stm32h7x.cpu0:
C:/Users/toddr/.platformio/packages/tool-openocd/scripts/target/stm32h7x.cfg:236: Error:
in procedure 'stm32h7x_dbgmcu_mmw' called at file "C:/Users/toddr/.platformio/packages/tool-openocd/scripts/target/stm32h7x.cfg", line 168
in procedure 'stm32h7x_mmw' called at file "C:/Users/toddr/.platformio/packages/tool-openocd/scripts/target/stm32h7x.cfg", line 260
in procedure 'stm32h7x_mrw' called at file "C:/Users/toddr/.platformio/packages/tool-openocd/scripts/target/stm32h7x.cfg", line 242
at file "C:/Users/toddr/.platformio/packages/tool-openocd/scripts/target/stm32h7x.cfg", line 236
Info : starting gdb server for stm32h7x.cpu0 on pipe
Info : accepting 'gdb' connection from pipe
Error: timed out while waiting for target halted
Error executing event gdb-attach on target stm32h7x.cpu0:

Error: auto_probe failed
Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use 'gdb_memory_map disable'.
Error: attempted 'gdb' connection rejected
Error: error during select: Unknown error
.pioinit:13: Error in sourced command file:

Here’s my platformio.ini environment as well:

[env:portenta_h7_m7]
platform = ststm32
board = portenta_h7_m7
framework = arduino
lib_deps = 
	arduino-libraries/ArduinoBLE@^1.3.4
	arduino-libraries/ArduinoMqttClient@^0.1.7
	256dpi/MQTT@^2.5.1
debug_tool = stlink
build_flags = -D PIO_FRAMEWORK_MBED_RTOS_PRESENT

It seems to work out of the box on MacOS (Ventura 13.2.1). Something must be up with my Windows config somehow