The Chinese version of the question is : How to dual purpose the SWD pins ? Once it is set to GPIO, it cannot enter SWD mode to program the flash.
Once you set the SWD pins to GPIO, and go through POR, the SWD connection is gone.
My suggestion: If you need to program the flash only, then your schematic, make provision for UART ISP mode (with the ISP Entry pin). Then you can still enter ISP mode (on POR) to Erase and Program the Flash using UART.