Content originally posted in LPCWare by abonent on Wed Dec 30 13:15:24 MST 2015
Quote: SeleneSW
Hi abonent,
SeleneSW - thank you much for your response. Since it is almost year since I tried to solve this problem, I don't remember very much details.
Quote: SeleneSW
While implementing USB CDC communication in one of our projects, I had your problem too.
After some investigation, as you saw, I've found that the VCOM_bulk_out_hdlr function is broken in the sense that overrides the pVcom->rx_buff buffer with new data every time the interrupt is called.
In this way if the vcom_bread function is not called fast enought we lose some packets.
I've managed to fix this, implementing a check inside the VCOM_bulk_out_hdlr function, and if there is no space in the buffer for the new packet, I just don't do the USBD_API->hw->ReadEP call (with the side effect that the interrupt will not be called any time soon, because the USB peripheral has no space),
So, not reading USBD_API->hw->ReadEP is safe and doesn't have any adverse effects? I barely remember setting up simple state machine and checking room in data buffer and once it was full, I didn't do EP reading, hoping in NAKed packets, but I recall it locked down virtual COM port. Perhaps my implementation was wrong, so I can try to reimplement it again.
Quote: SeleneSW
and later in the vcom_bread when I make room reading data, I call the USBD_API->hw->ReadEP enabling the interrupt again.
Well, maybe this is my problem, I didn't perform EP reading in vcom_bread function, but expected the VCOM_bulk_out_hdlr to be called again - seems like I was wrong. Thank you for this information, I'll try to find the old code and rework it.