OpenOCD debugging - unable to connect to target

Hi there,

I am currently using the following setup for PIO:

platform = ststm32
board = nucleo_l4r5zi
framework = arduino
upload_protocol = mbed
lib_deps = 5504, 5502

I am having trouble with debugging, I have debugged this board before using platformIO but I am having trouble now I am using a different platform (was using mbed before and had success).

I get the following error when trying to debug:

/Users/nic/.gdbinit:1: Error in sourced command file:
No symbol table is loaded.  Use the "file" command.
Error: init mode failed (unable to connect to the target)
.pioinit:10: Error in sourced command file:

Sometimes I get a popup saying that it failed to launch GDB. I should mention that uploading via STLink does not work either. I assume that PIO uses a local GDB executable and doesnt rely on a system installation?

Thanks for your help in advance.

By some magic I have fixed it.

I deleted upload_protocol from the config (so its on the default value which is stlink)

I then tried to upload and got a connection error, so I tried again to upload but this time I held down the physical RESET button on the board during the upload - this gave me a new error:

Error: timed out while waiting for target halted
TARGET: stm32l4x.cpu - Not halted
in procedure ‘program’

embedded:startup.tcl:480: Error: ** Unable to reset target **

It seemed to actually connect, but it could not reset the device, so I tried a third time (I did not hold down the reset button), and the upload worked fine. I then launched the debug, and it worked perfectly.