Sending out more than 64 bytes of with with USB Virtual COM demo

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending out more than 64 bytes of with with USB Virtual COM demo

2,082 Views
kevinlfw
Contributor III

I've tried a couple approaches to sending out large chunks (up to 4k bytes) of data using the virtual COM port example (MK22FN512VLH12, KSDK 1.3.0) however none of them have worked.  I've found that you can send out 64 bytes, once, without a problem; however, sending out more than that, or calling USB_Class_CDC_Send_Data multiple times does not work as expected and I don't know why.  Take this code for example, in Virtual_Com_App():

 

if (g_send_size)

{

  uint8_t error;

  uint32_t size = g_send_size;

  g_send_size = 0;

  uint8_t stuff[64] = { 65, 65, 65, ..., 65, 0 };

  uint8_t j;

  for(j = 0; j < 5; j++)

  {

    error = USB_Class_CDC_Send_Data(applicationHandle, DIC_BULK_IN_ENDPOINT, stuff, 64);

  }

 

Calling USB_Class_CDC_Send_Data consecutively does not work.  If I remove the for loop, it works as expected.  Also, if I call USB_Class_CDC_Send_Data(applicationHandle, DIC_BULK_IN_ENDPOINT, stuff, 200); this does not work either, returns USB_ERR (0xFF).  I'm trying to figure out how I can write a chunk of data to the COM port without any or with minimal interaction from the PC side.  How can this be done using the USB Virtual COM demo?

 

Thanks,

Kevin

Labels (1)
4 Replies

627 Views
kevinlfw
Contributor III

This question may be relevant: https://community.nxp.com/thread/385999?q=virtual%20com

I've never really had to change the SerialPort settings from their defaults when writing communication apps in .NET.  Whats the reason behind this, and is there something I can change so that I don't have to set DtrEnable?  Lastly, does setting the baud rate correctly actually matter since its really a USB device after all? 

0 Kudos

627 Views
isaacavila
NXP Employee
NXP Employee

Hello Kevin,

Problem here is that Maximum packet size for Bulk endpoint in Full speed is set to 64 (wMaxPacketSize in endpoint descriptor), so, in order to send more than 64 bytes, multiple transactions must be done.

I modified default example and could send more than 64 bytes, and the difference between your example and mine is that buffer that will be sent is not a LOCAL VARIABLE (as far as I know, USB CDC does not uses internal buffer and does not copy the information that you want to send in internal buffer, so it shouldn't be saved in local variables):

Here is what I made:

uint8_t buffer[] = {"This is a buffer larger than 64 bytes: 0123456789ABCDEF... Test for sending more than 64 bytes\n"};

Then, In Virtual_Com_App i modified to send this buffer everytime that i received any data from Host:

void Virtual_Com_App(void)

{

    /* User Code */

    if ((0 != g_recv_size) && (0xFFFFFFFF != g_recv_size))

    {

        int32_t i;

        /* Copy Buffer to Send Buff */

        for (i = 0; i < g_recv_size; i++)

        {

            USB_PRINTF("Copied: %c\n\r", g_curr_recv_buf[i]);

            g_curr_send_buf[g_send_size++] = g_curr_recv_buf[i];

        }

        g_recv_size = 0;

    }

    if (g_send_size)

    {

        uint8_t error;

        uint32_t size = sizeof(buffer);

        g_send_size = 0;

        error = USB_Class_CDC_Send_Data(g_app_handle, DIC_BULK_IN_ENDPOINT,

                buffer, size);

        if (error != USB_OK)

        {

            USB_PRINTF("Error on USB_Class_CDC_Send_Data\n");

            /* Failure to send Data Handling code here */

        }

    }

After that, I could see that message was sent correctly (First, 64 bytes were sent then, missing 32 bytes are sent):

Sending more than 64 bytes in CDC Example.jpg

Have you tried to declare this buffer as global?

Regards,

Isaac

627 Views
kevinlfw
Contributor III

isaacavila Thanks for the feedback.  Its all figured out :smileyhappy:.  Could you tell me what tool you used to sniff USB protocol (the last screenshot)?

0 Kudos

627 Views
isaacavila
NXP Employee
NXP Employee

Hi Kevin,

I used Ellisys USB Analizer: Ellisys - USB and Bluetooth Protocol Analyzers

Regards,

Isaac

0 Kudos