This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CDC example

Does any body have a good example of CDC.

The one sample code that comes with 5535 only accepts 1 byte.

I did modify it to take mutiple bytes by changing the below function. But something is wrong in reading multiple bytes in the CSL layer

CDC_bulkOutHandler function

// make sure we have enough space to save the RX data

//if ((cdcAppHandle->rxEndIdx-cdcAppHandle->rxStartIdx+usb_income_num_bytes)<CSL_USB_CDC_DATA_BUF_SIZE)

if (usb_income_num_bytes<CSL_USB_CDC_DATA_BUF_SIZE)

{

if (usb_income_num_bytes!=1)

{

printf(

"S: USB RX multiple bytes\n");

}

status = USB_postTransaction(pContext->hEpObjArray[2], usb_income_num_bytes,

&tempWord,

  • Does any body from TI read these posts

    I want a reply fast please

  • Hi Microt,

    Sorry for the delay.

    I've forwarded this question to the software team.

    Lets see what they suggest.

    Regards,
    Mark

  • Hi Microt,

    The echo example is supposed to work with the hyper-terminal which never send multiple characters at one time.

    Yes, you can change the CDC_bulkOutHandler() to make it accept multiple bytes, but make sure the data buffer for USB_postTransaction() is big enough to hold all the RX data. Right now in the code we assume one byte, therefore, tempWord (two bytes) is enough. You can tell the incoing data size by using usb_income_num_bytes. You will also need to copy the data from tempWord to cdcAppHandle->rxBufferPtr[cdcAppHandle->rxEndIdx]. You may need a for loop to do it.

    Keep in mind, the data you got by USB_postTransaction() is pack (two bytes per word), while the data stored in cdcAppHandle->rxBufferPtr and cdcAppHandle->txBufferPtr is unpacked (one btye per word). That is why we need cdcAppHandle->txWorkBufPtr to re-packing the data before send it back to USB host in CDC_bulkInHandler().

    You may want to define a cdcAppHandle->rxWorkBufPtr to replace the tempWord in CDC_bulkOutHandler().

    The other possible issue is that:

     if ((cdcAppHandle->rxEndIdx-cdcAppHandle->rxStartIdx+usb_income_num_bytes)<CSL_USB_CDC_DATA_BUF_SIZE)

    is necessary to make sure the cdcAppHandle->rxBufferPtr is not overflow. You should not remove it.

     

    Best regards,

    Ming
       

  • Microt, thanks for posting this question.  I have also been struggling with the more-than-one-byte transfer problem, but spent rather a lot of time assuming that my PC code was at fault.

    Ming, I've been looking at the code that you suggest changing and I think that there might be a problem with the if statement that you quote:

    if ((cdcAppHandle->rxEndIdx-cdcAppHandle->rxStartIdx+usb_income_num_bytes)<CSL_USB_CDC_DATA_BUF_SIZE)

    I don't think that it handles the case when the circular buffer indeces wrap.  I tried the following tests (by setting a breakpoint and manually adjusting the start and end values)

    • start = 18, end = 17 : the buffer is actually full, but the condition is true and so another character is added to it and the end index is increment.  Since both start and end are the same the circular buffer is now empty.
    • start = 18, end = 16 : there is room for one more character in the buffer, but the condition is false (the variables are unsigned) and the character is discarded.
  • Hi Peter,

    You are correct. The circular buffer loop around issue is not consifered there. Good catch! We will fix it in next CSL release. The multiple character issue will also be addressed in next release.

    Best regards,

    Ming

  • Hi Ming and Peter

    I did this change to deal with the buffer wraping around. And I guess it worked somewhat.

    //if ((cdcAppHandle->rxEndIdx-cdcAppHandle->rxStartIdx+usb_income_num_bytes)<CSL_USB_CDC_DATA_BUF_SIZE)

    if (usb_income_num_bytes<CSL_USB_CDC_DATA_BUF_SIZE)

    Ming: would you send me the new CDC changes, So I can test it out before you make hte release

    I am working on something else, so could not try the changes sugested by you.

    Thanks

     

  • Hi Ming

    Any progress  with  multiple character issue in CDC? 

    Best regards,

    Krzysztof