This seems to be related to MBED 6.6 and stlink/jlink issue, can you please check this solution ?
After editing your MBED framework, you may need to keep “reset” button pushed on your Nucleo before uploading the new program to get stlink upload protocol working (or switch to upload_protocol = mbed once before working with stlink again).
It seems this is not a Mbed problem, I have the same issue when using the Arduino framework. On Mbed Studio I have no upload problem.
It is really annoying that PlatformIO becomes more and more a problem rather than a solution.
Well the question is whether OpenOCD returns a non-zero error code because it failed or if PlatformIO cannot interpret the output or return code directly.
Can you please do a “Verbose Build” and copy the OpenOCD invocation like. Then open a PIO CLI and copy-paste that line, but prefix it with the folder path of the openocd binary. E.g. the output might look something like