1 2 Previous Next 22 Replies Latest reply on Oct 23, 2020 2:21 AM by LuTa_4642501

    Bug in cyfxusbdebug, doesnt work on USB 3

    LuTa_4642501

      Hi,

       

      The example cyfxusbdebug doesn't work with USB 3.0, only with USB 2.0.

      Please provide a patch to fix it.

       

      https://www.cypress.com/documentation/code-examples/ez-usb-fx3-usb-debug-example

       

      Code to test:

      #include <stdio.h>

      #include <libusb-1.0/libusb.h>

      #include <stdint.h>

      #include <string.h>

       

       

      int main(int argc, char*argv[])

      {

          int res                      = 0;

          libusb_device_handle* handle = 0;

          int kernelDriverDetached     = 0;

          int numBytes                 = 0;

          uint8_t buffer[128];

          int a;

       

       

          res = libusb_init(0);

          if (res != 0) {

              fprintf(stderr, "Error initialising libusb.\n");

              return 1;

          }

       

       

          handle = libusb_open_device_with_vid_pid(0, 0x04b4, 0x00f0);

          if (!handle) {

              fprintf(stderr, "Unable to open device.\n");

              return 1;

          }

       

       

          if (libusb_kernel_driver_active(handle, 0)) {

              res = libusb_detach_kernel_driver(handle, 0);

              if (res == 0) {

                kernelDriverDetached = 1;

              } else {

                fprintf(stderr, "Error detaching kernel driver.\n");

                return 1;

              }

          }

       

       

          res = libusb_claim_interface(handle, 0);

          if (res != 0) {

              fprintf(stderr, "Error claiming interface.\n");

              return 1;

          }

       

       

          for (a=0;a<100;a++) {

              res = libusb_interrupt_transfer(handle, 0x81, buffer, 128, &numBytes, 5000);

              if (0 == res) {

                  printf("Received %d bytes, expected 64.\n", numBytes);

              } else {

                 fprintf(stderr, "Error receiving message %d.\n", a);

              }

          }

       

       

          res = libusb_release_interface(handle, 0);

          if (0 != res) {

            fprintf(stderr, "Error releasing interface.\n");

          }

       

       

          if (kernelDriverDetached) {

              libusb_attach_kernel_driver(handle, 0);

          }

       

       

          libusb_exit(0);

       

       

          return 0;

      }

        • 1. Re: Bug in cyfxusbdebug, doesnt work on USB 3
          YatheeshK_36

          Hello,

           

          Please use the CyU3PDebugLogFlush() API in the firmware thread as soon as the CyU3PDebugLog() is called. This will flush the contents in the internal memory buffer to the target when when its not full. You will get the 8 bytes of data which incudes the message (2 bytes) and  parameter (4 bytes).

           

          Thanks,

          Yatheesh

          • 2. Re: Bug in cyfxusbdebug, doesnt work on USB 3
            LuTa_4642501

            Ok, this make it work over USB 3.

            And now there is a lot of garbage being print.

             

            root@raspberrypi ~ gcc int.c -o int -lusb-1.0 ; ./int 
            8 #xV4#
            8 #xV4"#
            8 #xV42#
            8 #xV4B#
            8 #xV4R#
            8 #xV4b#
            8 #xV4r#
            8 #xV4�#
            8 #xV4�#
            8 #xV4�#
            8 #xV4�#
            8 #xV4�#
            8 #xV4�#
            8 #xV4�#
            8 #xV4�#
            8 #xV4#
            8 #!xV4#
            8 #!xV4"#
            8 #!xV42#
            8 #!xV4B#
            8 #!xV4R#
            8 #!xV4b#
            8 #!xV4r#
            8 #!xV4�#
            8 #!xV4�#
            8 #!xV4�#
            8 #!xV4�#
            8 #!xV4�#
            8 #!xV4�#
            8 #!xV4�#

             

            # Userspace code used for test:

            #include <stdio.h>

            #include <libusb-1.0/libusb.h>

            #include <stdint.h>

            #include <string.h>

             

             

            int main(int argc, char*argv[])

            {

                int res                      = 0;

                libusb_device_handle* handle = 0;

                int kernelDriverDetached     = 0;

                int numBytes                 = 0;

                int a,b;

                unsigned char str[128];

             

             

                res = libusb_init(0);

                if (res != 0) {

                    fprintf(stderr, "Error initialising libusb.\n");

                    return 1;

                }

             

             

                handle = libusb_open_device_with_vid_pid(0, 0x04b4, 0x00f0);

                if (!handle) {

                    fprintf(stderr, "Unable to open device.\n");

                    return 1;

                }

             

             

                if (libusb_kernel_driver_active(handle, 0)) {

                    res = libusb_detach_kernel_driver(handle, 0);

                    if (res == 0) {

                      kernelDriverDetached = 1;

                    } else {

                      fprintf(stderr, "Error detaching kernel driver.\n");

                      return 1;

                    }

                }

             

             

                res = libusb_claim_interface(handle, 0);

                if (res != 0) {

                    fprintf(stderr, "Error claiming interface.\n");

                    return 1;

                }

             

             

                for (a=0;a<100;a++) {

                    memset(str, 0, 128);

                    res = libusb_interrupt_transfer(handle, 0x81, str, 128, &numBytes, 1000);

                    if (0 == res)

                        printf("%d #%s#\n", numBytes, str);

                    else

                       fprintf(stderr, "Error receiving message %d.\n", a);

                }

             

             

                res = libusb_release_interface(handle, 0);

                if (0 != res)

                  fprintf(stderr, "Error releasing interface.\n");

             

             

                if (kernelDriverDetached)

                    libusb_attach_kernel_driver(handle, 0);

             

             

                libusb_exit(0);

             

             

                return 0;

            }

            • 4. Re: Bug in cyfxusbdebug, doesnt work on USB 3
              YatheeshK_36

              Hello,

               

              Please use the latest FX3 1.3.4 Linux SDK: https://www.cypress.com/documentation/software-and-drivers/ez-usb-fx3-software-development-kit

               

              The programmer's guide in the SDK will define all the available APIs.

               

              Please use the cyusb_interrupt_transfer() API for interrupt transfer.

              Let me know if this works?

               

              Thanks,

              Yatheesh

              • 5. Re: Bug in cyfxusbdebug, doesnt work on USB 3
                LuTa_4642501

                Hi,

                 

                Having a userspace software capable of reading this data is just one step in order of making sure the firmware is working.

                The final solution needs to work inside the Linux kernel as a device driver, so using one library from cypress may work for userspace, but will not work for the kernel driver.

                 

                Please explain whats needs to be done to correctly receive this data without the use of the cypress library.

                 

                The device driver gets the same garbage:

                [    6.575114] usb 2-1: new SuperSpeed Gen 1 USB device number 2 using xhci_hcd
                [    6.605642] usb 2-1: LPM exit latency is zeroed, disabling LPM.
                [    6.612271] usb 2-1: New USB device found, idVendor=04b4, idProduct=00f0, bcdDevice= 0.00
                [    6.620532] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
                [    6.627760] usb 2-1: Product: FY3
                [    6.631092] usb 2-1: Manufacturer: TANURE3
                [    6.676491] clubb_probe
                [    6.676500] int_in
                [    6.678988] max 128 addr 129 interval 1
                [    6.715327] usbcore: registered new interface driver Clubb_Core
                [    6.716188] clubb_complete ## xV4
                [    6.778729] clubb_complete ## xV4"
                [    6.876497] clubb_complete ## xV42
                [    6.974133] clubb_complete ## xV4B
                [    7.071771] clubb_complete ## xV4R
                [    7.169414] clubb_complete ## xV4b
                [    7.267052] clubb_complete ## xV4r
                [    7.364822] clubb_complete ## xV4\x82
                [    7.462424] clubb_complete ## xV4\x92
                [    7.560095] clubb_complete ## xV4\xa2
                [    7.657733] clubb_complete ## xV4\xb2
                [    7.755500] clubb_complete ## xV4\xc2

                 

                Source Code for the device driver:

                 /*
                  * This software is licensed under the terms of the GNU General Public
                  * License version 2, as published by the Free Software Foundation, and
                  * may be copied, distributed, and modified under those terms.
                  *
                  * This program is distributed in the hope that it will be useful,
                  * but WITHOUT ANY WARRANTY; without even the implied warranty of
                  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                  * GNU General Public License for more details.
                  */
                #define DEBUG
                #include <linux/usb.h>
                #include <linux/module.h>
                #include <linux/slab.h>
                
                
                /* Structure to hold all of our device specific stuff */
                struct clubb_data {
                     struct usb_device *udev; /* usb device */
                     struct urb *urb; /* usb request block */
                     u8 *urbdata; /* interrupt URB data buffer */
                };
                
                static void clubb_complete(struct urb *urb)
                {
                     int status = urb->status;
                     char* str;
                
                     if (status && !(status == -ENOENT || status == -ECONNRESET || status == -ESHUTDOWN)) {
                          pr_err("Error! urb=%p bulk status: %d\n", urb, status);
                     }
                     str = (char*)urb->transfer_buffer;
                     pr_info("%s ## %s", __func__, str);
                
                
                     if (usb_submit_urb(urb, GFP_KERNEL)){
                          pr_info("BAD usb_submit_urb");
                     }
                }
                
                static int clubb_probe(struct usb_interface *intf, const struct usb_device_id *id)
                {
                     struct usb_device *udev = interface_to_usbdev(intf);
                     struct clubb_data* clubb;
                     struct usb_host_interface *iface_desc;
                     struct usb_endpoint_descriptor *int_in;
                     int r     et = 0;
                
                     pr_info("%s", __func__);
                
                     clubb = devm_kzalloc(&udev->dev, sizeof(struct clubb_data), GFP_KERNEL);
                     if (!clubb){
                          pr_info("BAD devm_kzalloc");
                          return -ENOMEM;
                     }
                
                
                     clubb->udev = udev;
                     usb_set_intfdata(intf, clubb);
                
                
                     iface_desc = intf->cur_altsetting;
                     ret = usb_find_common_endpoints(iface_desc, NULL, NULL, &int_in, NULL);
                     if (ret) {
                          dev_err(&udev->dev, "Could not find endpoints\n");
                     }
                     if (int_in)
                          pr_info("int_in");
                
                     pr_info("max %d addr %u interval %u\n" , usb_endpoint_maxp(int_in), int_in->bEndpointAddress, int_in->bInterval);
                
                     clubb->urb = usb_alloc_urb(0, GFP_KERNEL);
                     if (!clubb->urb) {
                     pr_info("BAD usb_alloc_urb");
                     return -ENOMEM;
                     }
                
                     clubb->urbdata = usb_alloc_coherent(udev, 128, GFP_KERNEL, &clubb->urb->transfer_dma);
                     if (!clubb->urbdata) {
                          usb_free_urb(clubb->urb);
                          pr_info("BAD usb_alloc_coherent");
                          return -ENOMEM;
                     }     
                
                     usb_fill_int_urb(clubb->urb, udev, usb_rcvintpipe(udev, int_in->bEndpointAddress), clubb->urbdata, usb_endpoint_maxp(int_in), clubb_complete,
                                         clubb, int_in->bInterval);
                     clubb->urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
                     if (usb_submit_urb(clubb->urb, GFP_KERNEL)){
                     pr_info("BAD usb_submit_urb");
                     return -EIO;
                     }
                
                     return ret;
                }
                
                static void clubb_disconnect(struct usb_interface *intf)
                {
                     struct clubb_data *clubb = usb_get_intfdata(intf);
                
                     usb_kill_urb(clubb->urb);
                     usb_free_coherent(clubb->udev, 128, clubb->urbdata, clubb->urb->transfer_dma);
                     usb_free_urb(clubb->urb);
                     devm_kfree(&clubb->udev->dev, clubb);
                }
                
                
                static const struct usb_device_id clubb_id_table[] = {
                { USB_DEVICE(0x04b4, 0x00f0) },
                     {}
                };
                MODULE_DEVICE_TABLE(usb, clubb_id_table);
                
                
                static struct usb_driver clubb_driver = {
                     .name = "Clubb_Core",
                     .probe = clubb_probe,
                     .disconnect = clubb_disconnect,
                     .id_table = clubb_id_table,
                };
                
                
                module_usb_driver(clubb_driver);
                
                
                MODULE_AUTHOR("Lucas Tanure <tanureal@opensource.cirrus.com>");
                MODULE_DESCRIPTION("Driver for Testing Interrupt communication");
                MODULE_LICENSE("GPL v2");
                          
                
                
                • 6. Re: Bug in cyfxusbdebug, doesnt work on USB 3
                  YatheeshK_36

                  Hello,

                   

                  Can you please print the data as hex values that is received from the libusb_interrupt_transfer().

                  Also,  please try using the control center to do interrupt IN transfer in Windows or Linux and compare the hex data received with your application output.

                  Let me know the results.

                   

                  Thanks,

                  Yatheesh

                  • 7. Re: Bug in cyfxusbdebug, doesnt work on USB 3
                    LuTa_4642501

                    Hi,

                     

                    New userspace code with the modifications:

                    cypress usbdebug userspace test - Pastebin.com

                     

                    New output that printds the first 32 bytes from usb:

                    root@raspberrypi ~ gcc int.c -o int -lusb-1.0 ; ./int     
                    01 15 11 c1 78 56 34 82 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 c1 78 56 34 92 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 c1 78 56 34 a2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 c1 78 56 34 b2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 c1 78 56 34 c2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 c1 78 56 34 d2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 c1 78 56 34 e2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 c1 78 56 34 f2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 c1 78 56 34 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 d1 78 56 34 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 d1 78 56 34 22 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 d1 78 56 34 32 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 d1 78 56 34 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 d1 78 56 34 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 d1 78 56 34 62 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 d1 78 56 34 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 d1 78 56 34 82 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 d1 78 56 34 92 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 d1 78 56 34 a2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
                    01 15 11 d1 78 56 34 b2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

                    • 8. Re: Bug in cyfxusbdebug, doesnt work on USB 3
                      LuTa_4642501

                      There is another way to execute the test you want without running the control center?

                      because the control center is very old software that doesn't build anymore, it needs qt5 and some icui18n library that my system doesn't have.

                      • 9. Re: Bug in cyfxusbdebug, doesnt work on USB 3
                        LuTa_4642501

                        Top image is the hex dump file.

                        The bottom image is what the control center shows

                         

                        Capture.PNG

                        • 10. Re: Bug in cyfxusbdebug, doesnt work on USB 3
                          YatheeshK_36

                          Hello,

                           

                          Looks like your application is working fine !

                           

                          Thanks,

                          Yatheesh

                          • 11. Re: Bug in cyfxusbdebug, doesnt work on USB 3
                            YatheeshK_36

                            Hello,

                             

                            Please let me know what data was expected from the interrupt transfer?

                             

                            The control center (windows and linux) will display the data received in hex format when the interrupt transfer is successful, else it returns an error.

                            If you are expecting ASCII characters then the appropriate conversion needs to be done on the application and the firmware side.

                             

                            Thanks,

                            Yatheesh

                            • 12. Re: Bug in cyfxusbdebug, doesnt work on USB 3
                              LuTa_4642501

                              Hi,

                               

                              The data expected is the debug string sent by the firmware.

                              CyU3PDebugPrint (2, "USB Debug logger: time from start in ticks: %d\n", CyU3PGetTime ());

                               

                              Please read the README from Cypress cyfxusbdebug example:

                               

                              "This example illustrates the use of the FX3 firmware APIs to implement a debug log mechanism over the USB interface.

                              The device enumerates as a vendor-specific USB device with a single interrupt endpoint (EP1-IN). The application sends out periodic log information out on the USB interface. The length of log can be up to 128 bytes. So the user should never request for data transfer of size less than 128 bytes."

                               

                              So, it seems this firmware Cypress offer doesn't work and there is no userspace application to be used with.

                               

                              Can please provide a way to get this data that the firmware is sending in Linux userspace?

                               

                              Thanks

                              Lucas

                              • 13. Re: Bug in cyfxusbdebug, doesnt work on USB 3
                                YatheeshK_36

                                Please use the CyU3PDebugLogFlush() after the API CyU3PDebugPrint (2, "USB Debug logger: time from start in ticks: %d\n", CyU3PGetTime ());

                                 

                                 

                                Please let me know what issue you are facing?

                                 

                                Regards,

                                Yatheesh

                                • 14. Re: Bug in cyfxusbdebug, doesnt work on USB 3
                                  LuTa_4642501

                                  Hi,

                                   

                                  The issue is the same as the begging of this conversation, the cyfxusbdebug demo doesn't work or USB3 and USB2, where it only outputs garbage.

                                   

                                  Please share your full source code as what you are saying doesn't work on my side:

                                  Capture.PNG

                                  1 2 Previous Next