AnsweredAssumed Answered

USB CDC device receive fails on transmit

Question asked by jdbk on Mar 31, 2017
Latest reply on Apr 11, 2017 by jdbk

I am using the USB CDC library on a STM32F746 as created with CubeMX and have run into a problem when the MCU transmits at the same time that it is receiving over USB.  I had a PC bursting data to the MCU.  The data is packetized, so for test purposes I had the MCU send a single byte each time it received a full packet.  If the PC sent one packet at a time, this worked fine, but when it sent a burst of packets back to back, the MCU would receive the first packet and part of the next, then it would stop receiving data.  This was with 262 byte packets, but when I reduced the packet size to about 200 bytes, which would change the timing of the transmit relative to the receive stream, the MCU would receive all of the packets.


On further digging, I found that when the reception failed, the CDC receive end point was disabled (EPENA cleared in DOEPCTL).  The code calls USBD_CDC_ReceivePacket every time in the CDC_Receive_FS callback, but when this happened, I would need to call USBD_CDC_ReceivePacket again to get reception started again.


It seems that somehow, when CDC data is transmitted at a certain point during CDC reception, it causes the receive end point to be disabled.  I assume it is happening in the HAL_PCD_IRQHandler ISR, but I have not been able to capture when or how it happens.  For now, I have implemented a brute force fix where the main loop keeps checking if the Rx end point is enabled, and if not it calls USBD_CDC_ReceivePacket again.


Has anyone else seen this issue or know how or why it happens?  I would very much like if I could have this work properly.