STM32 USB programming using the OTG interface
Microcontrollers are, by default, programmed using their so-called programming/debug interfaces. In case of STM32, it has SWD and JTAG interfaces for programming and debugging. You can use for example an ST-Link debugger to connect to these interfaces and program the device. If your application requires programming over USB or UART, you can use a bootloader to flash the microcontroller over these interfaces.