cancel
Showing results for 
Search instead for 
Did you mean: 

USB CDC Stuck in Transmit State STM32L4

jacob2
Associate II
Posted on May 23, 2017 at 21:00

Little background knowledge, I'm trying to implement XMODEM protocol for a file transfer to my SD card and everything seems to be in place and working for the most part but I run into an issue occasionally on USBD_CDC_TransmitPacket(&hUsbDeviceFS), where this can get stuck as always returning USBD_BUSY because the hUsbDeviceFS->pClassData->TxState is always 1 and never returns to 0.

Wondering what could cause this lock up and if there is anything to be careful on between receive/transmit over USB?

It looks like transmit isn't always going as expected and I'm ACK-ing packets before they are even processed, almost like the USB transmit is getting backed up a bit and pushing data out incorrectly. I think I corrected this by making the function wait for the transmit to be complete before returning but then I run into this instance of being stuck in a TxState which it never seems to exit.

My current process is to have a while loop in main for while the transfer is going on to let everything handle based off the interrupts, I only tell it to NAK on a timeout or if the data is incorrect. Data is processed within the CDC_Receive_FS function once the entire 132-byte packet shows up. This seems to work fine, in fact if nothing goes wrong and I simply ACK all packets the transfer completes successfully, it is mainly when I have to put a NAK into the mix it doesn't seem to get handled correctly, now it seems to run into just getting stuck in a high TxState. As soon as the receive interrupt is triggered, the timer interrupt is disabled so no NAK should go out unless the data is invalid.

Thank you for any help.

#usb-fs #usb-com #usb-cdc #stm32l4
0 REPLIES 0