AnsweredAssumed Answered

KSDK VCOM example does not work without loopback

Question asked by Raymond White on Jul 13, 2015
Latest reply on Aug 24, 2017 by annamol alex

I am running a FRDM-K64, using KDS 3.0 and KSDK 1.2.0. I am running a bare-metal app and pumping the usb "task" frequently

 

Below is the original function from the file virtual_com.c in the KSDK:

 

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++)

        {

            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 = g_send_size;

        g_send_size = 0;

 

        error = USB_Class_CDC_Send_Data(*g_cdc_vcom_ptr, DIC_BULK_IN_ENDPOINT,

            g_curr_send_buf, size);

 

        if (error != USB_OK)

        {

            /* Failure to send Data Handling code here */

        }

    }

    return;

}

 

As can be seen, the characters coming in from the VCOM port are immediately looped back out to the output of the port. When I run PuTTy on the PC the VCOM port works fine. I can type all day and the characters are dutifully returned.

 

I also tried keeping the loopback in-place and also sending the same characters out to a UART. If works fine that way, the characters typed appear in both the VCOM port window and the UART port window.

 

The problem is I don't want to loop back the characters on the VCOM port. So, as a test, I redirected the received characters to a UART and did not send any characters back via the VCOM port. When I do this, the very first character I type is received by the VCOM driver and sent to the UART, but then no other characters are received. So, somehow, by not echoing the received characters, it seems to inhibit the reception of more characters.

 

If I disconnect the USB from the PC and plug it back in, it happens again (only one character gets received).

 

Here is my code, edited for brevity:

 

void Virtual_Com_App(void)

{

 

    /* User Code */

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

    {

        int32_t i;

 

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

        {

          // sent character to uart here

        }

        g_recv_size = 0;

    }

 

    USB_Class_CDC_Send_Data(*g_cdc_vcom_ptr, DIC_BULK_IN_ENDPOINT, NULL, 0); // I tried it without this line, same effect (only get one character).

 

    return;

}

 

What am I doing wrong?

Outcomes