why can not read data from bulkin endpoint 0x86

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I am using C68013 chip.  I have downloaded the firmware from  AN61345 - Source code slave fifo  slave.iic.

using the newest driver  1.2.3.20 by 11/08/2017 on windows 7 x64.

the FPGA code is OK,  we can wirte and read data using NI-VISA driver and Labview program.

But,

I can write the data to C68013,  but can not read data from C68013.

Here is the VC++ code.  I also used the usb bus hound to look the data , there is also no data in to PC.

please help me, thank you very much!

// out endpoint  is ok

bool UsbTest::SendUsbData(unsigned char *wdata, long writeLength)

{

CCyUSBEndPoint *epBulkOut = m_usbDev->EndPointOf(2);

bool rst = epBulkOut->XferData(wdata, writeLength);

printf("send usb data ok\n");

return rst;

   

}

void UsbTest::RecvUsbData()

{

    long nCount = 0;

    long BytesXferred = 0;

    long outTransferred = 0;

bool m_bBulkLoopCompleted = false;

CCyUSBEndPoint *epBulkIn = m_usbDev->EndPointOf(0x86); // in传输   0x86

if (NULL == epBulkIn)

{

printf("epBulkIn is NULL\n");

return;

}

long totalTransferSize = epBulkIn->MaxPktSize * 16;

//epBulkIn->SetXferSize(10);

//epBulkIn->TimeOut = 1200;

unsigned char data[512] = { 0 };

OVERLAPPED inOvLap;

inOvLap.hEvent = CreateEvent(NULL, false, false, NULL);

        long readLength = 10;

    

UCHAR *inContext = epBulkIn->BeginDataXfer(data, readLength, &inOvLap);

if (epBulkIn->NtStatus || epBulkIn->UsbdStatus)

{

printf("BeginDataXfer Failed with (NT Status = 0x%X and USBD Status = 0x%X). Bailing out...\n", epBulkIn->NtStatus, epBulkIn->UsbdStatus);

}

        //////////Wait till the transfer completion..///////////////////////////

        if (!epBulkIn->WaitForXfer(&inOvLap, 150))

        {

/*

            epBulkIn->Abort();

if (epBulkIn->LastError == ERROR_IO_PENDING)

{

WaitForSingleObject(inOvLap.hEvent, 1500);

}*/

        }

       

        ////////////Read the trasnferred data from the device///////////////////////////////////////

bool success = epBulkIn->FinishDataXfer(data, readLength, &inOvLap, inContext);

       

printf("read usb data ok\n");

for (int idx = 0; idx < 64; ++idx)

{

printf(" 0x%x, ", data[idx]);

}

Sleep(300000);

    

}

0 Likes
1 Solution
SrinathS_16
Moderator
Moderator
Moderator
1000 replies posted 750 replies posted 500 replies posted

Hello,

- Modify the readLength parameter to be a multiple of the MaxPcktSize of the endpoint. Since, you have initialized this parameter to 10, the WaitForXfer/FinishDataXfer API fails thereby not receiving the data.

- Whenever the WaitForXfer/FinishDataXfer API fails, ensure that the endpoint is abort and reset using the CCyUSBEndpoint->Abort() CCyUSBEndpoint->Reset() functions before performing the next transaction.

I have modified the code as follows and I am able to successfully read the data.

// Should be a multiple of MaxPcktSize

long readLength = 512;    

UCHAR *inContext = epBulkIn->BeginDataXfer(data, readLength, &inOvLap);

if (epBulkIn->NtStatus || epBulkIn->UsbdStatus)

{

    printf("BeginDataXfer Failed with (NT Status = 0x%X and USBD Status = 0x%X). Bailing out...\n",     epBulkIn->NtStatus, epBulkIn->UsbdStatus);

    return -3;

}

   

//////////Wait till the transfer completion..///////////////////////////

if (!epBulkIn->WaitForXfer(&inOvLap, 150))

{

    printf("Wait for Xfer failure");

    // These statements are used to recover the endpoint

    // when there is a failure

    epBulkIn->Abort();         

    epBulkIn->Reset();         

    if (epBulkIn->LastError == ERROR_IO_PENDING)

    {

        WaitForSingleObject(inOvLap.hEvent, 1500);

    }

    // Break out when there is a failure

    return -4;    

}

   

////////////Read the trasnferred data from the device///////////////////////////////////////

bool success = epBulkIn->FinishDataXfer(data, readLength, &inOvLap, inContext);

if (success)

    // Identify the bytes of data actually transferred

    printf("read usb data ok. Data transferred: %lu\n", readLength);

else

{

    printf("Finish Data Xfer Failure"); 

    // Break out when there is a failure

    return -5;

}       

CloseHandle(inOvLap.hEvent);

for (int idx = 0; idx < readLength; ++idx)

{

    printf(" 0x%x ", data[idx]);

}

Best regards,

Srinath S

View solution in original post

0 Likes
1 Reply
SrinathS_16
Moderator
Moderator
Moderator
1000 replies posted 750 replies posted 500 replies posted

Hello,

- Modify the readLength parameter to be a multiple of the MaxPcktSize of the endpoint. Since, you have initialized this parameter to 10, the WaitForXfer/FinishDataXfer API fails thereby not receiving the data.

- Whenever the WaitForXfer/FinishDataXfer API fails, ensure that the endpoint is abort and reset using the CCyUSBEndpoint->Abort() CCyUSBEndpoint->Reset() functions before performing the next transaction.

I have modified the code as follows and I am able to successfully read the data.

// Should be a multiple of MaxPcktSize

long readLength = 512;    

UCHAR *inContext = epBulkIn->BeginDataXfer(data, readLength, &inOvLap);

if (epBulkIn->NtStatus || epBulkIn->UsbdStatus)

{

    printf("BeginDataXfer Failed with (NT Status = 0x%X and USBD Status = 0x%X). Bailing out...\n",     epBulkIn->NtStatus, epBulkIn->UsbdStatus);

    return -3;

}

   

//////////Wait till the transfer completion..///////////////////////////

if (!epBulkIn->WaitForXfer(&inOvLap, 150))

{

    printf("Wait for Xfer failure");

    // These statements are used to recover the endpoint

    // when there is a failure

    epBulkIn->Abort();         

    epBulkIn->Reset();         

    if (epBulkIn->LastError == ERROR_IO_PENDING)

    {

        WaitForSingleObject(inOvLap.hEvent, 1500);

    }

    // Break out when there is a failure

    return -4;    

}

   

////////////Read the trasnferred data from the device///////////////////////////////////////

bool success = epBulkIn->FinishDataXfer(data, readLength, &inOvLap, inContext);

if (success)

    // Identify the bytes of data actually transferred

    printf("read usb data ok. Data transferred: %lu\n", readLength);

else

{

    printf("Finish Data Xfer Failure"); 

    // Break out when there is a failure

    return -5;

}       

CloseHandle(inOvLap.hEvent);

for (int idx = 0; idx < readLength; ++idx)

{

    printf(" 0x%x ", data[idx]);

}

Best regards,

Srinath S

0 Likes