Uploading to STM32F1 fails because debug port is disabled

I have a custom setup where debug port is disabled. I use ST-LINK for uploading. PlatformIO cannot connect to the board after initial upload because debug port is disabled in Arduino startup sequence.

At the same time, ST-LINK Utility connects and uploads the firmware if the mode is set to “Connect under reset”. Is it possible with OpenOCD and PlatformIO?

You can change the OpenOCD config file that’s used during the upload. Located under C:\Users\xxx\.platformio\packages\tool-openocd\scripts\target\stm32f1x.cfg, change the reset_config srst_nogate do something else. There is documentation here and here.