USB CDC Example Receive only fail

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB CDC Example Receive only fail

Jump to solution
1,558 Views
etronic_arg
Contributor III

Hi,

I just trying to do a Virtual COM communication based on the USB CDC example from SDK.
I tested the example with success.

I cancel the "echo" part of the APPTask:

static void APPTask(void)
{
    usb_status_t error = kStatus_USB_Error;
    if ((1 == s_cdcVcom.attach) && (1 == s_cdcVcom.startTransactions))
    {
        /* User Code */
        /* endpoint callback length is USB_CANCELLED_TRANSFER_LENGTH (0xFFFFFFFFU) when transfer is canceled */
        if ((0 != s_recvSize) && (USB_CANCELLED_TRANSFER_LENGTH != s_recvSize))
        {
            int32_t i;

			/* Copy Buffer to Send Buff */
            for (i = 0; i < s_recvSize; i++)
            {
                s_currSendBuf[s_sendSize++] = s_currRecvBuf[i];
            }

			s_recvSize = 0;
        }


/*
        if (s_sendSize)
        {
            uint32_t size = s_sendSize;


			s_sendSize    = 0;

            error = USB_DeviceCdcAcmSend(s_cdcVcom.cdcAcmHandle, USB_CDC_VCOM_BULK_IN_ENDPOINT, s_currSendBuf, size);

            if (error != kStatus_USB_Success)
            {
                // Failure to send Data Handling code here
            }
        }
*/

 

If I send "HELLO" wth a terminal from a PC, the first time s_currSendBuf fills with the characters.

With the second "HELLO" I send, the terminal stucks.

I just need to receive characters but not send them back.
What would be the right way to do it?

Thanks

 

Tags (3)
0 Kudos
Reply
1 Solution
1,470 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Yes, this is a good solution. After you have data, just call the the function to send.

BR

Xiangjun Rong

USB_DeviceCdcAcmSend();

 

View solution in original post

0 Kudos
Reply
3 Replies
1,509 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Can you tell us the part number you are using?

BR

XiangJun Rong

0 Kudos
Reply
1,496 Views
etronic_arg
Contributor III

Hello XiangJun,

The part I'm using is the MK27FN2M0VM115 in a custom board, but I also tested it in a FRDM-K64F.

I solve the issue partially calling the USB sending fuction without data after receiving:

 

 if (s_sendSize)
        {
            uint32_t size = s_sendSize;


			s_sendSize    = 0;

            error = USB_DeviceCdcAcmSend(s_cdcVcom.cdcAcmHandle, USB_CDC_VCOM_BULK_IN_ENDPOINT, NULL, 0);

            if (error != kStatus_USB_Success)
            {
                // Failure to send Data Handling code here
            }
        }

 

Is there a better solution?

Tags (1)
0 Kudos
Reply
1,471 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Yes, this is a good solution. After you have data, just call the the function to send.

BR

Xiangjun Rong

USB_DeviceCdcAcmSend();

 

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-1965405%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EUSB%20CDC%20Example%20Receive%20only%20fail%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1965405%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20just%20trying%20to%20do%20a%20Virtual%20COM%20communication%20based%20on%20the%20USB%20CDC%20example%20from%20SDK.%3CBR%20%2F%3EI%20tested%20the%20example%20with%20success.%3C%2FP%3E%3CP%3EI%20cancel%20the%20%22echo%22%20part%20of%20the%20APPTask%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3Estatic%20void%20APPTask(void)%0A%7B%0A%20%20%20%20usb_status_t%20error%20%3D%20kStatus_USB_Error%3B%0A%20%20%20%20if%20((1%20%3D%3D%20s_cdcVcom.attach)%20%26amp%3B%26amp%3B%20(1%20%3D%3D%20s_cdcVcom.startTransactions))%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%2F*%20User%20Code%20*%2F%0A%20%20%20%20%20%20%20%20%2F*%20endpoint%20callback%20length%20is%20USB_CANCELLED_TRANSFER_LENGTH%20(0xFFFFFFFFU)%20when%20transfer%20is%20canceled%20*%2F%0A%20%20%20%20%20%20%20%20if%20((0%20!%3D%20s_recvSize)%20%26amp%3B%26amp%3B%20(USB_CANCELLED_TRANSFER_LENGTH%20!%3D%20s_recvSize))%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20int32_t%20i%3B%0A%0A%09%09%09%2F*%20Copy%20Buffer%20to%20Send%20Buff%20*%2F%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(i%20%3D%200%3B%20i%20%26lt%3B%20s_recvSize%3B%20i%2B%2B)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20s_currSendBuf%5Bs_sendSize%2B%2B%5D%20%3D%20s_currRecvBuf%5Bi%5D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%09%09%09s_recvSize%20%3D%200%3B%0A%20%20%20%20%20%20%20%20%7D%0A%0A%0A%2F*%0A%20%20%20%20%20%20%20%20if%20(s_sendSize)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20uint32_t%20size%20%3D%20s_sendSize%3B%0A%0A%0A%09%09%09s_sendSize%20%20%20%20%3D%200%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20error%20%3D%20USB_DeviceCdcAcmSend(s_cdcVcom.cdcAcmHandle%2C%20USB_CDC_VCOM_BULK_IN_ENDPOINT%2C%20s_currSendBuf%2C%20size)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(error%20!%3D%20kStatus_USB_Success)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Failure%20to%20send%20Data%20Handling%20code%20here%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A*%2F%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3EIf%20I%20send%20%22HELLO%22%20wth%20a%20terminal%20from%20a%20PC%2C%20the%20first%20time%26nbsp%3Bs_currSendBuf%20fills%20with%20the%20characters.%3C%2FP%3E%3CP%3EWith%20the%20second%20%22HELLO%22%20I%20send%2C%20the%20terminal%20stucks.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20just%20need%20to%20receive%20characters%20but%20not%20send%20them%20back.%3CBR%20%2F%3EWhat%20would%20be%20the%20right%20way%20to%20do%20it%3F%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1970996%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20USB%20CDC%20Example%20Receive%20only%20fail%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1970996%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3EYes%2C%20this%20is%20a%20good%20solution.%20After%20you%20have%20data%2C%20just%20call%20the%20the%20function%20to%20send.%3C%2FP%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EXiangjun%20Rong%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3EUSB_DeviceCdcAcmSend()%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1970007%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20USB%20CDC%20Example%20Receive%20only%20fail%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1970007%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CSPAN%3EXiangJun%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EThe%20part%20I'm%20using%20is%20the%26nbsp%3B%3C%2FSPAN%3EMK27FN2M0VM115%20in%20a%20custom%20board%2C%20but%20I%20also%20tested%20it%20in%20a%20FRDM-K64F.%3C%2FP%3E%3CP%3EI%20solve%20the%20issue%20partially%20calling%20the%20USB%20sending%20fuction%20without%20data%20after%20receiving%3A%3C%2FP%3E%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3E%20if%20(s_sendSize)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20uint32_t%20size%20%3D%20s_sendSize%3B%0A%0A%0A%09%09%09s_sendSize%20%20%20%20%3D%200%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20error%20%3D%20USB_DeviceCdcAcmSend(s_cdcVcom.cdcAcmHandle%2C%20USB_CDC_VCOM_BULK_IN_ENDPOINT%2C%20NULL%2C%200)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(error%20!%3D%20kStatus_USB_Success)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Failure%20to%20send%20Data%20Handling%20code%20here%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3EIs%20there%20a%20better%20solution%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1969408%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20USB%20CDC%20Example%20Receive%20only%20fail%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1969408%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3ECan%20you%20tell%20us%20the%20part%20number%20you%20are%20using%3F%3C%2FP%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EXiangJun%20Rong%3C%2FP%3E%3C%2FLINGO-BODY%3E