Consistent USB problems with RFID reader


12 posts
by AndiDog » Thu Mar 21, 2013 9:24 pm
I'm experiencing reproducible problems using the SkyeTek M7 RFID reader with the Raspberry Pi via USB 2.0. SkyeTek offers a driver/API for the RFID reader that uses libusb-0.1 and works perfectly fine on a PC and the latest Ubuntu or Debian. However, with the Pi + Raspbian I always get read errors, mostly timeout errors on the first USB read operation (explained below).

In order to test it, I wrote two minimal example programs (one with libusb-0.1, one with libusb-1.0, not using the official driver at all) that simply send the "Get reader version" command to the RFID reader and try to read the response. Every second time or so, an error occurs trying to read the response (I/O, device not found). Detecting the reader as USB device, detaching the kernel driver (if any) and sending the command always works, but when reading, I can see in dmesg output that the device has disconnected in the meantime, which is most probably interrupting the data transfer.

The example programs with source code and example dmesg output can be found here. It would be nice if people with an M7 could test with these programs and see if it's reproducible.

Some things I've tried to no avail (and combinations of them):
  • Kernels 3.2.27, 3.6.* and latest (through rpi-update script, including latest firmware and Debian packages)
  • armhf vs. armel architecture: no difference
  • Two different power supplies, one was an iPod power adapter (labeled with 5V @ 1A)
  • I posted about another USB problem before (viewtopic.php?f=28&t=19393) which was already fixed in Raspbian kernel 3.2.27. In the GitHub issue (https://github.com/raspberrypi/linux/issues/29), someone mentioned to try the cmdline.txt parameters "dwc_otg.microframe_schedule=1 dwc_otg.speed=1 dwc_otg.fiq_fix_enable=1". With these enabled, the `usb_set_configuration(<device handle>, 1)` call already fails with error -71 (EPROTO = protocol error).
  • Resend "Get reader version" command
  • Avoid "usbfs: interface 0 claimed by usbhid while 'MyProgramName' sets config #1" warning by
    • adding boot option "usbhid.quirks=0xafef:0x0f01:0x4" to /boot/cmdline.txt (note: the M7 reader's VID/PID is 0xafef/0x0f01)
    • running `echo "1-1.3:1.0" > /sys/bus/usb/drivers/usbhid/unbind` before the program starts
  • Forcing USB 1.1 speed for all USB devices using boot option "dwc_otg.speed=1"
  • Unplugged all USB devices except the RFID reader (started my program via SSH over LAN)
  • Shorter USB cable

I'd be very grateful for any hints since I already spent several months on this issue. Somehow I have a feeling it's related to other USB issues with the Pi, or maybe a power problem?!

Below are some more potentially helpful details. Please ask if you need more info.

Thanks!
Andreas

--

`dmesg` usually looks like this (mind that I started the program several times here). This is with the official M7 driver, not with the example program provided above (see the Dropbox folder for example dmesg output).

[ 144.753551] usb 1-1.3: usbfs: interface 0 claimed by usbhid while 'MyProgramName' sets config #1
[ 144.765186] usb 1-1.3: usbfs: process 1626 (MyProgramName) did not claim interface 0 before use
[ 147.663141] usb 1-1.3: usbfs: process 1626 (MyProgramName) did not claim interface 0 before use
[ 147.907190] usb 1-1.3: USB disconnect, device number 8
[ 148.142596] usb 1-1.3: new full-speed USB device number 9 using dwc_otg
[ 148.245349] usb 1-1.3: New USB device found, idVendor=afef, idProduct=0f01
[ 148.245384] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 148.245402] usb 1-1.3: Product: RFID READER
[ 148.245418] usb 1-1.3: Manufacturer: SKYETEK INC
[ 151.010394] usb 1-1.3: usbfs: interface 0 claimed by usbhid while 'MyProgramName' sets config #1
[ 151.021788] usb 1-1.3: usbfs: process 1630 (MyProgramName) did not claim interface 0 before use
[ 153.917394] usb 1-1.3: usbfs: process 1630 (MyProgramName) did not claim interface 0 before use
[ 154.051801] usb 1-1.3: USB disconnect, device number 9
[ 154.292595] usb 1-1.3: new full-speed USB device number 10 using dwc_otg
[ 154.395358] usb 1-1.3: New USB device found, idVendor=afef, idProduct=0f01
[ 154.395392] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 154.395411] usb 1-1.3: Product: RFID READER
[ 154.395428] usb 1-1.3: Manufacturer: SKYETEK INC

On PC/Debian, i.e. on a system where the RFID reader is working, it's as follows:

[ 1037.805455] usb 7-2: new full speed USB device using uhci_hcd and address 3
[ 1037.972360] usb 7-2: New USB device found, idVendor=afef, idProduct=0f01
[ 1037.972362] usb 7-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1037.972364] usb 7-2: Product: RFID READER
[ 1037.972365] usb 7-2: Manufacturer: SKYETEK INC
[ 1037.972423] usb 7-2: configuration #1 chosen from 1 choice
[ 1037.980409] generic-usb 0003:AFEF:0F01.0006: hiddev1,hidraw3: USB HID v1.11 Device [SKYETEK INC RFID READER] on usb-0000:00:1d.0-2/input0
[ 1069.534825] usb 7-2: usbfs: interface 0 claimed by usbhid while 'MyProgramName' sets config #1
[ 1096.011593] usb 7-2: USB disconnect, address 3
[ 1096.035229] MyProgramName[5823]: segfault at 0 ip 00007f76fb6fec6d sp 00007fffde932980 error 4 in libusb-0.1.so.4.4.4[7f76fb6fa000+7000]
[ 1096.251354] usb 7-2: new full speed USB device using uhci_hcd and address 4
[ 1096.418820] usb 7-2: New USB device found, idVendor=afef, idProduct=0f01
[ 1096.418822] usb 7-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1096.418824] usb 7-2: Product: RFID READER
[ 1096.418825] usb 7-2: Manufacturer: SKYETEK INC
[ 1096.418885] usb 7-2: configuration #1 chosen from 1 choice
[ 1096.426866] generic-usb 0003:AFEF:0F01.0007: hiddev1,hidraw3: USB HID v1.11 Device [SKYETEK INC RFID READER] on usb-0000:00:1d.0-2/input0
[ 1096.987778] usb 7-2: usbfs: interface 0 claimed by usbhid while 'MyProgramName' sets config #1

`sudo lsusb -v -d afef:0f01`

Bus 001 Device 004: ID afef:0f01
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0xafef
idProduct 0x0f01
bcdDevice 10.00
iManufacturer 1 SKYETEK INC
iProduct 2 RFID READER
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 41
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus 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 37
Report Descriptor: (length is 37)
Item(Global): Usage Page, data= [ 0x0a 0xff ] 65290
(null)
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Main ): Collection, data= [ 0x01 ] 1
Application
Item(Local ): Usage, data= [ 0x01 ] 1
(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= [ 0x40 ] 64
Item(Main ): Input, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Local ): Usage, data= [ 0x02 ] 2
(null)
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x40 ] 64
Item(Main ): Output, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Local ): Usage, data= [ 0x03 ] 3
(null)
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Global): Report Count, data= [ 0x05 ] 5
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 0x01 EP 1 OUT
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 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
Device Status: 0x7568
(Bus Powered)
Debug Mode
Posts: 28
Joined: Sat Apr 07, 2012 6:01 pm
by AndiDog » Sun Mar 24, 2013 4:12 pm
I added logging to dmesg and enabled verbose USB messages in the kernel. Now on failures, I get messages like these:

Code: Select all
[ 3044.783461] m7rawusb: STARTING
[ 3044.783461] m7rawusb: Finished libusb_init
[ 3044.783461] m7rawusb: Opening USB device
[ 3044.783461] m7rawusb: done
[ 3044.783461] m7rawusb: Set config #1
[ 3044.783461] m7rawusb: done
[ 3044.783461] m7rawusb: Finished claiming interface
[ 3044.783461] m7rawusb: Sending cmd
[ 3044.783461] m7rawusb: done
[ 3044.783461] m7rawusb: Reading response
[ 3044.783461] m7rawusb: done
[ 3044.783461] m7rawusb: FAILED
[ 3044.783461] m7rawusb: EXIT
[ 3044.788093] hub 1-1:1.0: state 7 ports 3 chg 0000 evt 0004
[ 3044.789656] hub 1-1:1.0: port 2, status 0101, change 0001, 12 Mb/s
[ 3044.789691] usb 1-1.2: USB disconnect, device number 13
[ 3044.789706] usb 1-1.2: unregistering device
[ 3044.789722] usb 1-1.2: unregistering interface 1-1.2:1.0
[ 3044.790019] usb 1-1.2: usb_disable_device nuking all URBs
[ 3044.948498] hub 1-1:1.0: debounce: port 2: total 100ms stable 100ms status 0x101
[ 3045.028487] usb 1-1.2: new full-speed USB device number 14 using dwc_otg
[ 3045.130014] usb 1-1.2: skipped 1 descriptor after interface
[ 3045.130363] usb 1-1.2: default language 0x0409
[ 3045.130948] usb 1-1.2: udev 14, busnum 1, minor = 13
[ 3045.130974] usb 1-1.2: New USB device found, idVendor=afef, idProduct=0f01
[ 3045.130993] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 3045.131007] usb 1-1.2: Product: RFID READER
[ 3045.131020] usb 1-1.2: Manufacturer: SKYETEK INC
[ 3045.139674] usb 1-1.2: usb_probe_device
[ 3045.139710] usb 1-1.2: configuration #1 chosen from 1 choice
[ 3045.140110] usb 1-1.2: adding 1-1.2:1.0 (config #1, interface 0)
[ 3045.140444] usbhid 1-1.2:1.0: usb_probe_interface
[ 3045.140472] usbhid 1-1.2:1.0: usb_probe_interface - got id
[ 3045.143528] usbhid 1-1.2:1.0: looking for a minor, starting at 96
[ 3045.144084] hid-generic 0003:AFEF:0F01.000B: hiddev0,hidraw0: USB HID v1.11 Device [SKYETEK INC RFID READER] on usb-bcm2708_usb-1.2/input0
[ 3045.144469] hub 1-1:1.0: state 7 ports 3 chg 0000 evt 0004


I'm not an expert, but if it says "debounce" doesn't that mean the connected USB device had actually disconnected (physically/logically??) and the hub is handling that as if I just plugged in the device (electrical debouncing)?
Posts: 28
Joined: Sat Apr 07, 2012 6:01 pm
by pluggy » Sun Mar 24, 2013 4:25 pm
Welcome to the Pi's flakey USB....

Its a work in progress. It may improve in time. Take a look at the USB Redux thread or you could try a search for 'elephant in our room'.
Don't judge Linux by the Pi.......
User avatar
Posts: 2406
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
by rimansyah » Thu Apr 25, 2013 6:14 am
Hi AndyDog,

I downloaded and tried your code but I am using SkyeReader SR70.
I believed it is using the same component.

so, I change the message sent to reader to "SELECT TAG (EPC C1G2)"..
I also got the same read failed but after that I got good response from reader.
finally it response the EPC Data.
so I believed that it is 50:50 chance. It is still not very stable.
Posts: 1
Joined: Thu Apr 25, 2013 4:20 am
by AndiDog » Mon Apr 29, 2013 7:59 pm
Thanks for investigating! What do you mean by "not very stable". Did it work consistenly after that first failure, or did you get sporadic faults afterwards?
Posts: 28
Joined: Sat Apr 07, 2012 6:01 pm
by jamesh » Tue Apr 30, 2013 12:22 am
Have either of you tried the FIQ fix by user gsh (search forum for details). It has fixed a lot of USB issues, but is still in testing, so not yet released. You may need to build a new kernel.
Soon to be unemployed software engineer currently specialising in camera drivers and frameworks, but can put mind to most embedded tasks. Got a job in N.Cambridge or surroundings? I'm interested!
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11618
Joined: Sat Jul 30, 2011 7:41 pm
by gsh » Wed May 01, 2013 5:58 am
Looks to me like it doesn't work properly on the PC either...

There is clearly a
[ 1096.035229] MyProgramName[5823]: segfault at 0 ip 00007f76fb6fec6d sp 00007fffde932980 error 4 in libusb-0.1.so.4.4.4[7f76fb6fa000+7000]

That's not good, the fact that it works on the PC just means it does things slightly differently but I'd first try understanding why you've got this error first.
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 777
Joined: Sat Sep 10, 2011 11:43 am
by AndiDog » Wed May 01, 2013 10:50 am
I tried with both "dwc_otg.fiq_fix_enable=0" and "=1" in cmdline.txt and it doesn't make a difference.

Will also try to rebuild the kernel as suggested in USB FIQ testing.
Posts: 28
Joined: Sat Apr 07, 2012 6:01 pm
by AndiDog » Thu May 09, 2013 6:13 pm
Tried with `sudo BRANCH=fiq_split rpi-update`, didn't help.
Posts: 28
Joined: Sat Apr 07, 2012 6:01 pm
by gsh » Thu May 09, 2013 9:08 pm
[ 1069.534825] usb 7-2: usbfs: interface 0 claimed by usbhid while 'MyProgramName' sets config #1
[ 1096.011593] usb 7-2: USB disconnect, address 3
[ 1096.035229] MyProgramName[5823]: segfault at 0 ip 00007f76fb6fec6d sp 00007fffde932980 error 4 in libusb-0.1.so.4.4.4[7f76fb6fa000+7000]


As I've said before on this forum, this is an error, fix this first then try again...

Gordon
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 777
Joined: Sat Sep 10, 2011 11:43 am
by benmesander » Wed Jan 22, 2014 8:15 pm
Hi,

I fixed this by modifying the SkyeTek API library using hints from this page:

http://stackoverflow.com/questions/1108 ... rom-libusb

In SkyeTekAPI_Linux1360/SkyeTekAPI/Device/USBDevice.c I changed:

if(strcmp(DriverName, "usbhid") == 0)

to:

if(1)

This obviously isn't a "real" fix, but the dance that USBDevice.c does to reset the device if it has been claimed by a HID driver seems to also work well for the non-HID case and makes the race go away.

Hope this helps,
Ben
Posts: 1
Joined: Wed Jan 22, 2014 8:02 pm
by AndiDog » Thu Jan 30, 2014 8:43 pm
Thanks a lot for posting this. However this fix doesn't help. Could you post the modified driver sources, and do you have an example program?
Posts: 28
Joined: Sat Apr 07, 2012 6:01 pm