CyAPI Host not reading bytes

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

cross mob
Anonymous
Not applicable

I am getting started on CyAPI and used the loopback example program as the starting point.

   

The device appears to receive the data from the host PC but when it goes to send the bytes back out, it goes into infinite loop waiting for the host to read the data.

   

       if (USBFS_OUT_BUFFER_FULL == USBFS_GetEPState(OUT_EP_NUM))
        {
            /* Read number of received data bytes. */
            length = USBFS_GetEPCount(OUT_EP_NUM);
            /* Trigger DMA to copy data from OUT endpoint buffer. */
        #if (USBFS_16BITS_EP_ACCESS_ENABLE)
            USBFS_ReadOutEP16(OUT_EP_NUM, buffer, length);
        #else
            USBFS_ReadOutEP(OUT_EP_NUM, buffer, length);
        #endif /* (USBFS_GEN_16BITS_EP_ACCESS) */

   

            /* Wait until DMA completes copying data from OUT endpoint buffer. */
            do {
                EPState = USBFS_GetEPState(OUT_EP_NUM);                
            }         while (EPState == USBFS_OUT_BUFFER_FULL);   // This never clears.

   

On the PC side, I am using CyAPI like this.

   

    while (1)
    {
        int err;

   

        if (g_InEP == NULL) return;    // If the End-point is invalid, terminate the thread.
        OVERLAPPED inOvLap;
        inOvLap.hEvent = CreateEvent(NULL, false, false, L"CYUSB_IN");
        unsigned char inBuf[64];
        ZeroMemory(inBuf, 64);
        LONG length = 1;
        // Just to be cute, request the return data before initiating the loopback
        UCHAR *inContext = g_InEP->BeginDataXfer(inBuf, length, &inOvLap);
        err = g_InEP->UsbdStatus;
        g_InEP->WaitForXfer(&inOvLap, 100);
        err = g_InEP->UsbdStatus;
        g_InEP->FinishDataXfer(inBuf, length, &inOvLap, inContext);
        CloseHandle(inOvLap.hEvent);
        err = g_InEP->UsbdStatus;
        if( length > 0)
            OutputDebugStringA((LPCSTR)inBuf);

   

        Sleep(1);
    }

   

Any suggestions on what I might have done incorrectly?

   

 

   

Hiroo

0 Likes
3 Replies
Anonymous
Not applicable

Hi,

   

Does the code on the host side execute correctly? Does it return error in any case? Can you please check with a software USB analyser (like USBLyzer) to where the issue is?

   

Regards,

   

- Madhu Sudhan

0 Likes
Anonymous
Not applicable

Code on the host is running and I can step through the reader no problem.  The error is reporting 0 indicating that each of the calls are succeeding and it is not blocking.  The end point handle is valid and they are showing reasonable values (object instantiated correctly).

On the PSoC side, the code stepping shows that it has received the "Hello." from the PC and the bytes has been read out of the OUT_EP without issues.  It appears that the PSoC code goes into infinite loop prior to loading the IN_EP .

   
            /* Wait until IN buffer becomes empty (host has read data). */             do {                 EPState = USBFS_GetEPState(IN_EP_NUM);                             }         while (EPState != USBFS_IN_BUFFER_EMPTY); 
   

The EPState returns 0x00 every call which maps to USBFS_NO_EVENT_PENDING which is an alias for USBFS_IN_BUFFER_FULL.  Logically, since I have not sent anything to host yet, there is nothing for host to read.  Therefore, it will continue to spin here.

Hiroo

0 Likes
Anonymous
Not applicable

Hi Hiroo,

Can you please confirm on the DMA mode? Is it Auto or Manual?

I have seen in my project that if the DMA mode is auto we don't have to wait

            do {
                 EPState = USBFS_GetEPState(OUT_EP_NUM);               
             }         while (EPState == USBFS_OUT_BUFFER_FULL);

I have seen in my project that if the DMA mode is auto we don't have to wait for BufferFull on OUT_EP. It will come out of this loop only if there is new data available in OUT_EP.

Regards,

Nishal

0 Likes