A brief introduction to this problem:
I have a STM32F767 which is configured for USB Device FS. USB interface is used to transmit a large array of data from MCU to computer. If, by any chance user closes the Virtual Com Port (USB) of MCU, next time user opens Virtual Com Port (USB), MCU will send remaining data it was transmitting to computer, creating a lot of troubles.
I want to flush TX buffer of USB Device mode or abort transmition progress whenever VCP is opened/closed in the computer. I've to mention that I use HAL libraries.