2 Replies Latest reply on Jul 27, 2020 3:37 AM by AlEr_4025481

    FX3: slow data rate from EP0 when DMA is active

    AlEr_4025481

      Hi there,

       

      I wrote a tiny app to know how many data requests can be sent (received) to (from) FX3 device. According to USB specification it must be one request per each millisecond or 1000 requests per second, but I need to be sure. So part of my EP0 callback looks like:

       

      ...  
      if (SetupRequest.DirDevToHost
          && (SetupRequest.Type == (CY_U3P_USB_VENDOR_RQT >> 5))
          && (SetupRequest.Target == CY_U3P_USB_TARGET_INTF))
          {
          switch (SetupRequest.Value) {
      
          // Sending 16 bytes of data TO host
          case VENDOR_CONTROL_REQUEST:
          request_counter++;
          CyU3PUsbSendEP0Data(SetupRequest.Length, Ep0Buffer);
          isHandled = CyTrue;
          break;
      
          default:
          CyU3PDebugPrint(CY_FX_DEBUG_PRIORITY, "Unknown vendor code received (%d)\r\n", SetupRequest.Value);
          CyU3PUsbStall (0, CyTrue, CyFalse);
          }
      }
      
      if (!SetupRequest.DirDevToHost
          && (SetupRequest.Type == (CY_U3P_USB_VENDOR_RQT >> 5))
          && (SetupRequest.Target == CY_U3P_USB_TARGET_INTF))
          {
          switch (SetupRequest.Value) {
      
          // Receiving 16 bytes of data FROM host
          case VENDOR_CONTROL_REQUEST:
          request_counter++;
          CyU3PUsbGetEP0Data(SetupRequest.Length, Ep0Buffer, &br);
          isHandled = CyTrue;
          break;
      
          default:
          CyU3PDebugPrint(CY_FX_DEBUG_PRIORITY, "Unknown vendor code received (%d)\r\n", SetupRequest.Value);
          CyU3PUsbStall (0, CyTrue, CyFalse);
          }
      }
      ...
      

       

      Next, I attach FX3 to USB 3.0 port and start to send 1000 vendor requests to EP0. The result is perfect: 1000 requests in ~1000 ms.

      Starting 1000 control requests from Host to Device...
        Completed in: 1007 ms
      
      Starting 1000 control requests from Device to Host...
        Completed in: 1000 ms
      

       

      But when I attach FX3 to USB 2.0 port something strange happens. Device to host requests take a lot of time: 1000 requests in ~11 seconds!

      Starting 1000 control requests from Host to Device...
        Completed in: 1000 ms
      
      Starting 1000 control requests from Device to Host...
        Completed in: 10969 ms
      

       

      I have tried on different computers (desktop, laptop), on different OS'es (Windows, Linux), on different libs (libusb, libusbK), the result was the same. Finally, as I found it started to work properly when I turned off DMA multi channel. Just commented lines below and data rate from device to host has returned to normal speed.

      /* Set DMA Channel transfer size */
      // apiRetStatus = CyU3PDmaMultiChannelSetXfer (&DmaChInHandle, 0, 0);
      // if (apiRetStatus != CY_U3P_SUCCESS)
      // {
      //     CyU3PDebugPrint (CY_FX_DEBUG_PRIORITY, "CyU3PDmaMultiChannelSetXfer failed, Error code = %d\r\n", apiRetStatus);
      //     CyFxAppErrorHandler(apiRetStatus);
      //}
      

       

      And now my questions are: why this happen and how can I fix it? Source code is attached, test app for Linux based on Qt & libusb 1.0.