STM32 & ST-LINK - Cannot connect to MCU after successful programming

I managed to solve that problem. If anybody encounters similar problem, here's what I've done:

I used ST-Link v2 and ST-Link Utility. In setting, I set "Connect under reset" and SWD interface (I'm not sure about frequency).
Then I press the reset button on my board and clicked "Target" -> "Erase chip" and just after clicking I released the button - It erased the chip so I can now reprogram my MCU.


Anyway, if you need to use SWD pins as output, then add some delay at the beginning of the program or use some jumper to disable/enable setting these pins as outputs.


For connect under reset to work the ST-Link must have control over the reset pin, if you tie it to ground the ST-Link has no chance to get the target running and gain access to it.


If you pull the BOOT0 pin high during power up, the MCU will start into the internal bootloader and you can gain access using several serial protocols (see the reference manual for more details).

Inside the bootloader the SWD pins should be available to gain access, but I'm not 100% sure on this.

The ST Flash Loader Demonstrator is a tool which allows you to erase / program the micro using the UART interface. If you can't access any of the UARTs of your micro, this solution won't work for you.


if you're using stmcubemx, u need to configure the serial wire on stmcube pinout tab. on pinout tab, click SYS and change debug option to serial wire. it fix my problem, and maybe your problem too.