2 Replies Latest reply on Oct 22, 2020 4:28 AM by YatheeshK_36

    cyfxusbdebug gives garbage over usb

    LuTa_4642501

      Hi,

       

      The example cyfxusbdebug only outputs garbage over the interrupt endpoint.

       

       

      Output:

       

      root@raspberrypi ~ gcc int.c -o int -lusb-1.0 ; ./int 
      �xV4�xV4"�xV42�xV4B�xV4R�xV4b�xV4r�xV4��xV4��xV4��xV4��xV4��xV4��xV4��xV4��xV4�
      �xV4�xV4"�xV42�xV4B�xV4R�xV4b�xV4r�xV4��xV4��xV4��xV4��xV4��xV4��xV4��xV4��xV4�
      �xV4�xV4"�xV42�xV4B�xV4R�xV4b�xV4r�xV4��xV4��xV4��xV4��xV4��xV4��xV4��xV4��xV4�
      xV4xV4"xV42xV4BxV4RxV4bxV4rxV4�xV4�xV4�xV4�xV4�xV4�xV4�xV4�xV4�
      xV4xV4"xV42xV4BxV4RxV4bxV4rxV4�xV4�xV4�xV4�xV4�xV4�xV4�xV4�xV4�
      !xV4!xV4"!xV42!xV4B!xV4R!xV4b!xV4r!xV4�!xV4�!xV4�!xV4�!xV4�!xV4�!xV4�!xV4�!xV4�
      1xV41xV4"1xV421xV4B1xV4R1xV4b1xV4r1xV4�1xV4�1xV4�1xV4�1xV4�1xV4�1xV4�1xV4�1xV4�
      AxV4AxV4"AxV42AxV4BAxV4RAxV4bAxV4rAxV4�AxV4�AxV4�AxV4�AxV4�AxV4�AxV4�AxV4�AxV4�

       

       

      C software used 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;

          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("%s\n", 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;

      }

        • 1. Re: cyfxusbdebug gives garbage over usb
          LuTa_4642501

          With a patch from Bug in cyfxusbdebug, doesnt work on USB 3

          The new garbage is:

           

          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;

          }



          • 2. Re: cyfxusbdebug gives garbage over usb
            YatheeshK_36

            Hello,

             

            Please follow up in this thread: Bug in cyfxusbdebug, doesnt work on USB 3

             

            Thanks,

            Yatheesh