1 2 Previous Next 15 Replies Latest reply on Sep 15, 2020 1:33 AM by YatheeshK_36

    Clarifications on Endpoint and DMA Initialization

    IyRa_4728991

      Dear All,

       

      I need to communicate with an external device and i would like to get data by using bulk transfer function. I can communicate and get data with the connected device using Endpoint 4 and Endpoint 3.

      Now I want to read the data from Endpoint 1 and i need to use DMA for reading data.

      I am executing below function call.

       

      iRet = USB_processData(usb_handle,
                                               0x81,
                                               reinterpret_cast<unsigned char *>(m_pulDmaDescriptorAddr + (m_nDescriptorCnt * (int)DMA_DATA_SIZE)),
                                               (int)DMA_DATA_SIZE, // 4048 bytes
                                               &bytesTransferred,
                                               0);

      Function definition:

       

      int USB_ processData (cyusb_handle *h,
                            unsigned char endpoint,
                            unsigned char *data,
                            int length,
                            int *transferred,
                            int timeout)
      {
      int retval = ERROR;

      retval = cyusb_claim_interface(h, 0);

      if(retval == SUCCESS) {
      retval = cyusb_bulk_transfer(h,
                                    endpoint,
                                    data,
                                    length,
                                    transferred,
                                    timeout);

      cyusb_release_interface(h, 0);
      }

      return retval;
      }

       

      After calling this function my code stops here. I don't know whether the problem with external device or i have an issue with this function call.

      I want to confirm few points which i mentioned below.

       

      1. I am using Endpoint 1 to get the data from external device. My passing value 0x81 (8 - Input, 1 - Endpoint 1) correct or not?

      2. should i want to initialize DMA for using it?(I refered the data sheet but there is no much information about DMA).

       

      I am using CYUSB3014-BZXC device.

        • 1. Re: Clarifications on Endpoint and DMA Initialization
          IyRa_4728991

          My code waits in cyusb_bulk_transfer function. Sorry for adding it in reply. Wrongly I pressed Ctrl + S key. It was posted immediately.

           

          Please confirm the mentioned points.

           

          Regards,

          Iyaps.

          • 2. Re: Clarifications on Endpoint and DMA Initialization
            YatheeshK_36

            Hello Iyaps,

             

            The code part seems fine. Looks like the FX3 device does not have enough data ( 4048 bytes) to send to the host. cyusb_bulk_transfer() will return success only when the required data length is received from the device.

            Please make sure that the device has the required length of data committed to the endpoint consumer socket 1.

             

            To check this you can use the control control center in windows or in linux and check by doing an IN transfer with the required data length and if you getting the data?

             

            You can also specify a limited timeout value in your application instead of infinite timeout ( timeout =  0), for example: timeout = 5000.

            In this case the cyusb_bulk_transfer() will return with an error code, and you can check the actual data length received using the bytesTransferred parameter.

             

            Also, try receiving a smaller length. for example 1024.

             

            Thanks,

            Yatheesh

            • 3. Re: Clarifications on Endpoint and DMA Initialization
              IyRa_4728991

              Dear Yatheesh,

               

              Thank you for your reply.

               

              From your reply i understood that there is no need of initializing the DMA for using it.

               

              >> You can also specify a limited timeout value in your application instead of infinite timeout ( timeout =  0), for example: timeout = 5000.

              >> In this case the cyusb_bulk_transfer() will return with an error code, and you can check the actual data length received using the

              >> bytesTransferred parameter.

                       I tried with your suggestion. At this time I got -7 as return value from cyusb_bulk_transfer() function and I got 0 as bytesTransferred parameter.

               

              >> Also, try receiving a smaller length. for example 1024.

                   I tried with this also. I got the same output.I got -7 as return value from cyusb_bulk_transfer() function and I got 0 as bytesTransferred parameter.

               

              >>To check this you can use the control control center in windows or in linux and check by doing an IN transfer with the required data length >> and if you getting the data?

                   Can you explain this case more detail. I don't understand your question.

               

               

              Best regards,

              Iyaps.

              • 4. Re: Clarifications on Endpoint and DMA Initialization
                YatheeshK_36

                Hello Iyaps,

                 

                From your responses it seems like there is no data available to be read on endpoint 0x81. Please make sure that some data is committed to the endpoint socket so that the data is available to the host.

                 

                Are you using a standard firmware from the Fx3 SDK? if no, please share your firmware.

                 

                 

                 

                 

                To check this you can use the control control center in windows or in linux and check by doing an IN transfer with the required data length >> and if you getting the data?

                 

                FX3 windows and linux SDK comes with Control center application which is used to program the FX3 devices and also perform data transfers on it. Use the application to do the required IN transfer from the FX3 endpoint 0x81.

                 

                Thanks,

                Yatheesh

                • 5. Re: Clarifications on Endpoint and DMA Initialization
                  IyRa_4728991

                  Hello Yatheesh,

                   

                  Thank you for your support.

                   

                  Sorry. I missed to add one point here. I am using the FX3 device with Android devices (OS ver - 9, ASUS, Samsung Mobiles).

                   

                  >> Are you using a standard firmware from the Fx3 SDK? if no, please share your firmware.

                  I downloaded the linux SDK from the below link.

                  https://www.cypress.com/documentation/software-and-drivers/ez-usb-fx3-software-development-kit

                   

                  >> FX3 windows and linux SDK comes with Control center application which is used to program the FX3 devices and also perform data
                  >> transfers on it. Use the application to do the required IN transfer from the FX3 endpoint 0x81.

                     As I am using Android device I thinks that we can't run the control center application in Android device.. Is it possible to check in some other methods?

                   

                  Regards,

                  Iyaps.

                  • 6. Re: Clarifications on Endpoint and DMA Initialization
                    YatheeshK_36

                    Hello Iyaps,

                     

                    You can plug the board to either windows or linux PC if it has a type-C design (or use a converter ) and then use the control center application. 

                     

                    Thanks,

                    Yatheesh

                    • 7. Re: Clarifications on Endpoint and DMA Initialization
                      IyRa_4728991

                      Dear Yatheesh,

                       

                      >> You can plug the board to either windows or linux PC if it has a type-C design (or use a converter ) and then use the control center

                      >> application.

                                Cypress device already working with Windows(Existing system in windows only). Now we are trying to replace windows device with Android device. So I would like to verify the Endoint 1 data by using my android device itself. So can you tell me how to write data into an IN endpoint(0x81) manually from host(Android device)?

                       

                      Regards,

                      Iyaps.

                      • 8. Re: Clarifications on Endpoint and DMA Initialization
                        YatheeshK_36

                        Hello Iyaps,

                         

                        If you are using the FX3 linux SDK, then the cyusb_bulk_transfer() API can be used to read and write to the FX3 device bulk endpoint.

                        Before doing a transfer to the endpoints of the device from the host, the interface needs to be claimed using the  cyusb_claim_interface() API.

                         

                        To do a transfer to the IN endpoint (0x81) of the FX3 device please refer to the below API call after the interface (0) is claimed.

                        cyusb_bulk_transfer (handle, 0x81,buff, len, transcount, 5000 );

                         

                        Here,

                        buff is the pointer to the data buffer holding the data to be sent.

                        len: length of the data to be sent

                        transcount: when the API is executed, this variable will hold the actual bytes transferred.

                        5000: timeout for the operation

                         

                        Thanks,

                        Yatheesh

                         

                         

                         

                        • 9. Re: Clarifications on Endpoint and DMA Initialization
                          IyRa_4728991

                          Dear Yatheesh,

                           

                          Thank you for your reply.

                           

                          I tried with above mentioned function. Still I am getting timeout(-7) as return value from the function and transcount as '0'.

                           

                          let me explain my issue in detail.

                           

                          New system:

                                                   Android Device <-->  Cypress device <--> External Device

                          Existing system:

                                                 Windows Device <-->  Cypress device <--> External Device

                                                   I checked with windows device. I can able to get data from cypress device. But in android machine i am not getting any data.

                           

                          So here i can do two mistakes.

                                         1. I am not sending proper commands to external device for sending data to the android device.

                                         2. My configurations for getting data from IN Endpoint is wrong.

                          Here I don't have any idea which mistake I am doing.

                           

                          To verify the 2nd point, I want to set some data manually from android device into IN Endpoint. If i am getting my assigned data from IN Endpoint in android device means my configurations are correct.

                           

                          so Is it possible to assign some data in IN Endpoint (0x81) from Android device to verify my steps are correct or not???

                           

                          Regards,

                          Iyaps.

                          • 10. Re: Clarifications on Endpoint and DMA Initialization
                            YatheeshK_36

                            Hello Iyaps,

                             

                            You can use the attached streamer firmware on FX3 and do an IN transfer of length 512 bytes on endpoint 0x81.

                            The attached firmware will continuously stream data on 0x81 IN endpoint, so you have to retrieve data on that endpoint.

                             

                            Also, can you please let me know if you are using Super speed Explorer Kit or a custom designed board.

                             

                             

                            Thanks,

                            Yatheesh

                            • 11. Re: Clarifications on Endpoint and DMA Initialization
                              IyRa_4728991

                              Dear Yatheesh,

                               

                              I downloaded the shared img file into FX3 device successfully. I tried to get the data from android device by executing below code.

                               

                              retval = cyusb_claim_interface(handle, 0);

                              if(retval == DPS_SUCCESS) {

                                   retval = cyusb_bulk_transfer(handle,
                                   0x81,
                                   reinterpret_cast<unsigned char *>&DataAddr[0],
                                   512,
                                   &transferred,
                                   20000);

                              }

                               

                              But cyusb_claim_interface function returns -4 as return value.

                               

                              To check this i executed below functions.

                               

                              iRet = cyusb_get_configuration(usb_handle,&config);                     // Here i am getting return value as 0. But config value also '0'.
                              iRet = cyusb_get_active_config_descriptor(usb_handle, &desc);    // Here i am getting return value as -4.

                               

                              Can you tell me what i am doing wrong?

                               

                              >> can you please let me know if you are using Super speed Explorer Kit or a custom designed board.

                                   I am using custom designed board.

                               

                              Best regards,

                              Iyaps.

                              • 12. Re: Clarifications on Endpoint and DMA Initialization
                                YatheeshK_36

                                Hello lyaps,

                                 

                                Please try the below sequence:

                                bool retval;
                                int ret;
                                cyusb_handle* h = NULL;
                                int i = cyusb_open();
                                printf("number of devices  = %d\n", i);
                                
                                for (int j = 0; j < i; j++)
                                {
                                cyusb_handle* handle = cyusb_gethandle(j);
                                if (handle == NULL)
                                {
                                printf("handle return failed\n");
                                return 0;
                                }
                                unsigned short vid = cyusb_getvendor(handle);
                                unsigned short pid = cyusb_getproduct(handle);
                                
                                
                                printf("vid  = %d ,  pid  = %d\n", vid, pid);
                                
                                
                                printf("Claiming an interface\n");
                                ret = cyusb_claim_interface(handle, 0);
                                if (ret != 0)
                                {
                                printf("claiming interface failed = %d\n", ret);
                                return 0;
                                }
                                printf("interface is claimed\n");
                                
                                printf("Bulk out transfer\n\n");
                                unsigned char sendBuff[512];
                                for (int i = 0; i < 512; i++)
                                {
                                sendBuff[i] = i;
                                }
                                int len = 512;
                                int *actlen = NULL;
                                ret = cyusb_bulk_transfer(handle, 0x01, sendBuff, len, actlen,2000);
                                if (ret != 0)
                                {
                                printf("bulkout failed, error code = %d\n", ret);
                                }
                                else
                                {
                                printf("bulk out success\n");
                                }
                                

                                 

                                Please let me know the results.

                                 

                                Thanks,

                                Yatheesh

                                • 13. Re: Clarifications on Endpoint and DMA Initialization
                                  YatheeshK_36

                                  Hello lyaps,

                                   

                                  I also tried the following code using your function:

                                   

                                  int main(void)
                                  {
                                  bool retval;
                                  int ret;
                                  int bytesTransferred;
                                  cyusb_handle* h = NULL;
                                  int i = cyusb_open();
                                  printf("number of devices  = %d\n", i);
                                  
                                  for (int j = 0; j < i; j++)
                                  {
                                  cyusb_handle* handle = cyusb_gethandle(j);
                                  if (handle == NULL)
                                  {
                                  printf("handle return failed\n");
                                  return 0;
                                  }
                                  unsigned short vid = cyusb_getvendor(handle);
                                  unsigned short pid = cyusb_getproduct(handle);
                                  
                                  
                                  printf("vid  = %d ,  pid  = %d\n", vid, pid);
                                  unsigned char sendBuff[512];
                                  for (int i = 0; i < 512; i++)
                                  {
                                  sendBuff[i] = i;
                                  }
                                  
                                  
                                  printf("operation\n");
                                  
                                  
                                  int iRet = USB_processData(handle,
                                  0x81,
                                  sendBuff,
                                  (int)512, // 4048 bytes
                                  &bytesTransferred,
                                  0);
                                  if (iRet == 0)
                                  {
                                  printf("operation success\n");
                                  }
                                  
                                  
                                  else printf("operation failed\n");
                                  exit(0);
                                  }
                                  

                                   

                                  The operation was successful with the USBBulkSrcSink firmware.

                                   

                                   

                                  Thanks,

                                  Yatheesh

                                  • 14. Re: Clarifications on Endpoint and DMA Initialization
                                    IyRa_4728991

                                    Dear Yatheesh,

                                     

                                    Thank you for your reply. I tried with your implementation also. Still i am getting -4 as a return value.

                                     

                                    I would like to say one point. I am downloading the .img into internal RAM of FX3 from my android code. Checksum (0x6B450ADF) values compared and it is verified with the value read from the .img file and each byte is verified after every write by reading the same from FX3.

                                     

                                    After downloading the firmware I executed the above shared code. But still i am getting the same error.

                                    I tried the following steps also after downloading the firmware.

                                     

                                    1. I tried with close and open the usb device. Here i am getting -19 as a return value from cyusb_open (vid, pid).

                                    2. I called cyusb_kernel_driver_active function also. For this function also i am getting -4 as return value (here i commented the close and open functions which is mentioned in above step).

                                     

                                    I have few more doubts.

                                     

                                    1. How the endpoints are decided as IN and OUT endpoints. Is it configured by cypress or it is configured by firmware.

                                    2. Is it possible to change the maxpacketsize of an endpoint?

                                     

                                    Best regards,

                                    Iyaps.

                                    1 2 Previous Next