Virtual Comport demo freezing / losing data   // frdm-k22f // ksdk 2.0

cancel
Showing results for 
Search instead for 
Did you mean: 

Virtual Comport demo freezing / losing data   // frdm-k22f // ksdk 2.0

Jump to solution
498 Views
vincentg_
Contributor II

Hi,

I am trying to setup a reliable USB connection to exchange some data between the frdm-k22f and my pc.

The usb_device_cdc_vcom demo  itself works as expected, echoing anything I send.

When trying to send more then one packet from the board the data will get messed up. There will be missing data / data sent twice.

Sending 5 packets as  reply to one incoming byte with a simple counter will result in the answer "1/2/3/4/4" so the 0 packet is missing and the 4 is being sent twice.

Looping the USB_DeviceCdcAcmSend command with a larger buffer can kill the connection too, so the problem seems to be that even if returning  kStatus_USB_Success it doesn't ensure that the data has been sent or that the hardware is ready to accept new data.

Any hint how to ensure the data gets sent would be  appreciated.

 

 

Minimal code example ( s_cdcVcom.startTransactions has to be set to 1 / commented out for the demo to work

static uint32_t counter = 0; static uint32_t buffersize = 4; int k, i = 0;      if ((0 != s_recvSize) && (0xFFFFFFFFU != s_recvSize)) {           for (k = 0; k < 5; k++) {                for (i = 0; i < buffersize; i += 4) {                     s_currSendBuf[i + 3] = (counter >> 24) & 0xff;                     s_currSendBuf[i + 2] = (counter >> 16) & 0xff;                     s_currSendBuf[i + 1] = (counter >> 8) & 0xff;                     s_currSendBuf[i + 0] = (counter) & 0xff;                     counter++;                }                do {                     error = USB_DeviceCdcAcmSend(s_cdcVcom.cdcAcmHandle,USB_CDC_VCOM_BULK_IN_ENDPOINT, s_currSendBuf, buffersize);                } while (error != kStatus_USB_Success);           }           s_recvSize = 0;      }
Labels (1)
Tags (1)
1 Solution
193 Views
vincentg_
Contributor II

Ok I found the solution myself.

If anybody is running into the same problem:

Search for "/* User: add your own code for send complete event */" and handle the status yourself.

View solution in original post

0 Kudos
2 Replies
194 Views
vincentg_
Contributor II

Ok I found the solution myself.

If anybody is running into the same problem:

Search for "/* User: add your own code for send complete event */" and handle the status yourself.

0 Kudos
193 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

I suppose you add your sending code  as following, it is right? I ask it so that I can answer customer question if they have similar issue.

BR

XiangJun Rong

usb_status_t USB_DeviceCdcVcomCallback(class_handle_t handle, uint32_t event, void *param)
{
    usb_status_t error = kStatus_USB_Error;
    uint32_t len;
    uint16_t *uartBitmap;
    usb_cdc_acm_info_t *acmInfo = &s_usbCdcAcmInfo;
    usb_device_cdc_acm_request_param_struct_t *acmReqParam;
    usb_device_endpoint_callback_message_struct_t *epCbParam;
    acmReqParam = (usb_device_cdc_acm_request_param_struct_t *)param;
    epCbParam = (usb_device_endpoint_callback_message_struct_t *)param;
    switch (event)
    {
        case kUSB_DeviceCdcEventSendResponse:
        {
            if ((epCbParam->length != 0) && (!(epCbParam->length % g_UsbDeviceCdcVcomDicEndpoints[0].maxPacketSize)))
            {
                /* If the last packet is the size of endpoint, then send also zero-ended packet,
                 ** meaning that we want to inform the host that we do not have any additional
                 ** data, so it can flush the output.
                 */
                USB_DeviceCdcAcmSend(handle, USB_CDC_VCOM_BULK_IN_ENDPOINT, NULL, 0);
            }
            else if ((1 == s_cdcVcom.attach) && (1 == s_cdcVcom.startTransactions))
            {
                if ((epCbParam->buffer != NULL) || ((epCbParam->buffer == NULL) && (epCbParam->length == 0)))
                {
                    /* User: add your own code for send complete event */

            

              USB_DeviceCdcAcmSend(); //Rong write: does you add send code here?


                    /* Schedule buffer for next receive event */
                    USB_DeviceCdcAcmRecv(handle, USB_CDC_VCOM_BULK_OUT_ENDPOINT, s_currRecvBuf,
                                         g_UsbDeviceCdcVcomDicEndpoints[0].maxPacketSize);
#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
    defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) &&             \
    defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
                    s_waitForDataReceive = 1;
                    USB0->INTEN &= ~USB_INTEN_SOFTOKEN_MASK;
#endif
                }
            }
        }
        break;