5 Replies Latest reply on Aug 4, 2020 4:50 AM by YatheeshK_36

    Steps to write to and read from cypress device using libcyusb functions

    IyRa_4728991

      Hi All,

       

      I am new to USB environment. My aim is to port from windows to android to communicate with hardware peripheral using cypress device.

      Existing system:

           Windows Device  <--->  Cypress Device (FX3)   <--->  Hardware Peripheral

      New system:

            Android Device  <--->  Cypress Device (FX3)   <--->  Hardware Peripheral

       

      Established the communication between cypress device and android device using libusb. we are using libcyusb.cpp wrapper file to use libusb functions. I can able to get Handle of an USB(cypress device), PID, VID of the connected device by using libcyusb function calls.

      Now i want to communicate with hardware peripheral. In the windows code "CCyUSBEndPoint::XferData" function used to send the data. This function available in CyAPI.cpp file.

       

      Can anyone suggest a function corresponding to that API(CCyUSBEndPoint::XferData) in the libcyusb.cpp file?

       

      Best regards,

      Iyaps.

        • 1. Re: Steps to write to and read from cypress device using libcyusb functions
          YatheeshK_36

          Hello,

           

          Initially, you will have to claim the interface (interface 0) of the device using the cyusb_claim_interface() function with the handle.

          After the interface is claimed successfully,  use the  cyusb_bulk_transfer(),  cyusb_control_transfer () or cyusb_interrupt_transfer() functions to perform data transfers to or from the device to the host (android).

           

          Please refer to the cyusb_linux_programmers_guide.pdf from the FX3 linux SDK for the description of each function.

           

          Interface can be released using cyusb_release_interface() after all the data transfers with the device is complete.

           

          Thanks,

          Yatheesh

          • 2. Re: Steps to write to and read from cypress device using libcyusb functions
            IyRa_4728991

            Dear Yatheesh,

             

            Thank you for your reply.. I followed the above mentioned step and it is working fine.

             

            I have one more issue.

             

            Now i want to transfer the data in bulk transfer. When i tried i am not getting the expected result.

            In this for writing i want to use endpoint3 and for reading i want to use endpoint4(This format already followed in windows system).

             

            I tried the write operation by following steps,

            1. claim_interface(handle, 0)  --> return value 0

            2. bulk_transfer(handle,

                                      3, (Endpoint 3)

                                      databuffer,

                                      datasize,

                                      &bytestransferred,

                                     timeout).   --> return value 0

            3. release_interface(handle, 0)   --> return value 0

             

            Based on the return value and bytestransferred value i confirmed that write operation success.

             

            Now i tried the read operation by following steps,

            1. claim_interface(handle, 0)  --> return value 0

            2. bulk_transfer(handle,

                                      4, (Endpoint 4)

                                      databuffer,

                                      datasize,

                                      &bytestransferred,

                                     timeout).   --> return value -1

            3. release_interface(handle, 0)   --> return value 0

             

            At here i am getting -1 as a return value from bulk transfer and bytesTransferred value also 0 only.

             

            Can you tell me where i am missing??

             

            Best regards,

            Iyaps.

            • 3. Re: Steps to write to and read from cypress device using libcyusb functions
              YatheeshK_36

              Hello Iyaps,

               

              There are two things to consider:

               

              1. The IN endpoint address should be passed in the  unsigned char endpoint field when reading data from the respective END Point.

              If you are using End Point 4, then please pass 0x84. Here the MSb is set to indicate the direction (IN) of the endpoint and transfer.

               

              2. The length (datasize) should be equal to the exact number of bytes that is being requested from the device.

              Please make sure, the length of data is available to be read by the host on the device.

               

              Thanks,

              Yatheesh

              • 4. Re: Steps to write to and read from cypress device using libcyusb functions
                IyRa_4728991

                Dear Yadheesh,

                 

                Its working.. After changing the address it is working.

                 

                Thank you very much for your support.

                 

                But how to calculate or get that address of endpoint?

                 

                Best regards,

                Iyaps.

                • 5. Re: Steps to write to and read from cypress device using libcyusb functions
                  YatheeshK_36

                  Hello Iyaps,

                   

                  Endpoint address = 0x(Direction , Endpoint number)

                  Direction = 0x8 for IN and 0x0 for out.

                  Endpoint number = 1,2,4,6,8

                  endpoint 0 is by default control endpoint.

                   

                  For example, If endpoint 2 is configured as an IN endpoint. Then the corresponding address will be 0x82.

                  If endpoint 4 is configured as out endpoint, endpoint address = 0x04

                   

                  For information on Endpoint buffers, please refer to Section 1.17 EZ-USB Endpoint Buffers from EZ-USB Technical Reference Manual.

                   

                  Thanks,

                  Yatheesh