AnsweredAssumed Answered

USB CDC - When does the endpoint become ready?

Question asked by h..dino on Feb 10, 2016
Latest reply on Feb 10, 2016 by h..dino

I'm using the CDC class driver version 2.4.1 and made the following changes to the usbd_cdc_if.c template:

Since the provided CDC_Transmit_FS function tries to transmit the packet forever, i.e.

do {
    result = USBD_CDC_TransmitPacket(hUsbDevice_0);
while(result != USBD_OK);

this function blocks if the endpoint is not ready. Hence, I added a USB_Ready flag, which is set at the end of CDC_Init_FS and unset in CDC_DeInit_FS. In case the flag is unset, CDC_Transmit_FS returns immediately (with USBD_FAIL return code).

Now I made a strange observation: I'm calling CDC_Transmit_FS from a high frequency loop. During the first iterations the transmit function fails, that's okay (I think). However, as soon as the ready flag is set, the first packet transmitted causes a call to CDC_Receive_FS with exactly the data I tried to send, while it actually never gets transmitted to the USB host. Therefore, I assume I try to send the data a bit too early. Does this makes sense to you? Is there a way to solve this problem?