cancel
Showing results for 
Search instead for 
Did you mean: 

How do I reset the internal USB state machine correctly when something USB-related goes wrong?

arnold_w
Senior

I'm working with the Nucleo-64 development board with an STM32L476 microcontroller and I'm using the USB source code that STM32CubeMX has generated for me. Every once in a while something unpredictable happens, e.g. the user unplugs the USB-cable in the middle of a packet or the microcontroller attempts to send something before the cable has been plugged in properly. When something goes wrong, I would like to have a reliable way to abort all ongoing transmissions/receptions and reset the USB state machine, without having to call __USB_FORCE_RESET or MX_USB_DEVICE_Init(). What would such a function look like? Right now I call these functions:

USB_FlushRxFifo(USB_OTG_FS);
USB_FlushTxFifo(USB_OTG_FS, 15);

but I can see that ((USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData)->TxState is still 1 in some error cases. Can anybody please help me?

0 REPLIES 0