Black Pill V3.1 upload failure using STLINK/V2 after coding error

I’m just starting some development with a Black Pill STM32F411CE V3.1. Not very familiar with STM CPUs. Using an STLINK/V2 (genuine ST one) for all comms, not using the USB port at all.

Was getting on fine with some test code toggling PA5 and PC13 (the LED). But, then made a silly mistake. On making a change, set PA13 as one of the output ports, not PC13. PA13 - I notice - is one the the SWD port pins.

The result is now, I cannot upload any code at all, it fails on trying to upload. It says:

Uploading .pio\build\blackpill_f411ce\firmware.elf
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
debug_level: 1

hla_swd
Error: init mode failed (unable to connect to the target)
in procedure 'program'
** OpenOCD init failed **
shutdown command invoked

*** [upload] Error 1

I assume this is because the code currently in flash has configured PA13 as an output and the STLINK cannot talk to it.

Cannot find a way out of this. Can anyone help?

My platformio.ini is:

[env:blackpill_f411ce]
platform = ststm32
board = blackpill_f411ce
framework = stm32cube
upload_protocol = stlink
debug_tool = stlink

UPDATE:

Booting with boot0 held down seemed to do it. Don’t know if that is the ‘correct’ approach.