2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ There is no easy way unfortunately as closing and opening the com port on the computer does not change anything from the USB point of view. The only way is to have two directional communication where your device is answering for the requests from the host. I do it in my devices for example and if after reopen device received initialisation command it ends all ongoing transmissions. \$\endgroup\$ – P__J__ Sep 19 '17 at 16:46
  • \$\begingroup\$ Hello @PeterJ_01, I know how to detect openning or closing port from the MCU point of view, what I actually need to know is how to abort/flush a transmition. Seems you know how to. can you tell us how to stop a transmition from MCU? \$\endgroup\$ – Nixmd Sep 20 '17 at 9:35
2
\$\begingroup\$

I'm using STM32Cube v1.16.0 and this is working for me:

#include "stm32f4xx_ll_usb.h"

...

PCD_HandleTypeDef *hpcd = hUsbDeviceFS.pData;
USB_FlushTxFifo(hpcd->Instance, 0x10U);

Flag 0x10U means "Flush all Tx buffers". See stm32f4xx_ll_usb.c for details.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.