Is it possible to implement a host on stm32 (without hardware support) with only the program code to write data to the USB flash drive?
Why the host function can't be implemented with device-only hardware? Because the USB is not symmetrical with regard to host and devices.

On the device side the USB function is to support basic USB protocol called "SIE", Serial Interface Engine. This engine includes device ability to RECEIVE host requests, starting with "default pipe", and respond properly with getting data with ACK response, or sending data and waiting for host ACK to complete transactions. Because of USB timing limitations (1.7us response time), the final stage of control transaction can't be implemented by software means, and most parts of device SIE engines are hardware-encoded. Other functions of SIE are to accept address assignment, and accept/enable configuration, which concludes the enumeration phase of USB attach protocol. Then the SIE supports basic IN/OUT/other pipes, within the same protocol constraints. In short, the device function is to RESPOND.

Because of these hardware limitations, it is impossible to use the device engine for host function, mainly because the host functions are entirely opposite to the device functions. The bus handling follows very different state machines. The host must GENERATE periodic frame packets, and INITIATE all transactions. And then provide smooth stream of data, all usually done using Direct Memory Access hardware. The host must provide port power function, and port reset function, which is not there in device implementations.

These are major reasons why MCU are designed with separate host hardware and device hardware controllers.