[libhid-discuss] USB libhid is writing to PIC but errors out reading from it.

Daniel Yount factorf2 at yahoo.com
Mon Nov 14 10:46:12 UTC 2011


Using Linux 3.x kernel and debian 6.0 stable distro.


USB flash program 1.3

http://code.google.com/p/mphidflash/


libhid 0.2.16


I have installed a Generic HID bootloader  and a basic p18F2455 circuit setup for reading and writing USB data.
20mhz crystal no LEDs one jumper for bootloader mode and a switch for reset., nothing special. 

When I plug it in and use the "dmesg" commandline program I get.

[19195.480407] usb 1-1.2: reset full speed USB device number 6 using ehci_hcd
[19238.616399] usb 1-1.4: new full speed USB device number 50 using ehci_hcd
[19238.711891] usb 1-1.4: New USB device found, idVendor=2233, idProduct=7001
[19238.711900] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[19238.711907] usb 1-1.4: Product: Generic HID
[19238.711912] usb 1-1.4: Manufacturer: Test
[19238.714576] generic-usb 0003:2233:7001.000F: hiddev0,hidraw3: USB HID v1.11 Device [Test Generic HID] on usb-0000:00:13.5-1.4/input0


I type "lsusb -v" and get.


Bus 001 Device 050: ID 2233:7001 RadioShack Corporation 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x2233 RadioShack Corporation
  idProduct          0x7001 
  bcdDevice            0.01
  iManufacturer           1 Test
  iProduct                2 Generic HID
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           41
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xc0
      Self Powered
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      47
          Report Descriptor: (length is 47)
            Item(Global): Usage Page, data= [ 0xa0 0xff ] 65440
                            (null)
            Item(Local ): Usage, data= [ 0x01 ] 1
                            (null)
            Item(Main  ): Collection, data= [ 0x01 ] 1
                            Application
            Item(Local ): Usage, data= [ 0x03 ] 3
                            (null)
            Item(Global): Logical Minimum, data= [ 0x00 ] 0
            Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0x02 ] 2
            Item(Main  ): Input, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Local ): Usage, data= [ 0x04 ] 4
                            (null)
            Item(Global): Logical Minimum, data= [ 0x00 ] 0
            Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0x02 ] 2
            Item(Main  ): Output, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Local ): Usage, data= [ 0x05 ] 5
                            (null)
            Item(Global): Logical Minimum, data= [ 0x00 ] 0
            Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0x02 ] 2
            Item(Main  ): Feature, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Main  ): End Collection, data=none
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
Device Status:     0x0000
  (Bus Powered)




Now this I had hacked around on mphidflsh to see if I could track it down. 

./mphidflash -v 2233 -p 7001 -e 


Turned on debugging and added some extra check points and I added data into the default buffer and added a second buffer to make sure it read it to a clean buffer. As you see the only data that is read back is one byte into the second buffer.Writing of the initial buffer gave no errors.


USB HID device found
Sending:
31 32 33 34 35 36 37 38 : 39 30 61 62 63 64 65 66 67 68 69 6a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

About To Write

Done Write

About to read into empty buffer
Done reading
Received:
31 59 00 00 00 00 00 00 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

./mphidflash Error: USB read error



Tracked the error down to this function in mphidflash.usb-linux.c


    if(HID_RET_SUCCESS != hid_interrupt_read(hid,0x81,usbBuf2,64,0))

What would cause libhid to return error on reading while writing is fine?


Daniel Yount 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20111114/fc1465f0/attachment.html>


More information about the libhid-discuss mailing list