Difficulty with getting USB serial [USB CDC] working

Hi,
thank you, the solution is working. However, there is still a problem.

I am programming a bluepill, and stlink for upload and debug.
If I upload the code, the usb virtual serial port is working.
If I start a debug session, no serial port in the Device Manager, but an unknown usb device instead. So the serial monitor is not working.

I suspect it’s because the debugger stops the uC before proper enumeration.

A workaround:

  • start running the code in the debugger
  • disconnect the board’s usb, and reconnect it, now the virtual usb port appears in the Device Manager
  • restart the serial monitor in PIO
  • stop the uC with a breakpoint
  • now both debugging and serial is working

While it’s working, not really comfortable. Is there a better way?