jc2789
Posts: 5
Joined: Mon Jan 15, 2018 11:55 am

libusb transfer not working on RPi 3

Mon Jan 15, 2018 2:26 pm

I have been working on connecting an LPC4357 MCU to an RPi 3 via USB bulk transfer.
Because the project needs to be cross-platform so I am using libusb. On Windows, everything works fine.

For the RPi, the code compiles/links and runs mostly ok, all basic functions work such as descriptor-related functions and hot-plug functions.
However, all transfer-related functions always return LIBUSB_ERROR_TIMEOUT. I have tested both sync and async transfers, with/without explicit event handling but nothing works. When the async transfer is used, the callback of the transfer never get called despite the libusb_handle_events function is running.

I have also tried a few online examples (e.g. PyUSB). The result is same: most functions work fine except transfer functions as they still constantly gives LIBUSB_ERROR_TIMEOUT. May I ask for some insight of this problem? Could it be caused by a bug in the kernel? a bug in the libusb? MCU side error? or maybe some specific code/configuration is required for using libusb on RPi?

Other information:
libusb version: 1.0.21
OS version: Raspbian (kernel 4.9.76-v7+)
USB descriptors of the device:

Dev (bus 1, device 7): NXP Semiconductors - LPC4357 GENERIC USB
- Serial Number: ABCD123456789
Configuration:
wTotalLength: 39
bNumInterfaces: 1
bConfigurationValue: 1
iConfiguration: 0
bmAttributes: 80h
MaxPower: 250
Interface:
bInterfaceNumber: 0
bAlternateSetting: 0
bNumEndpoints: 3
bInterfaceClass: 255
bInterfaceSubClass: 240
bInterfaceProtocol: 0
iInterface: 4
Endpoint:
bEndpointAddress: 01h
bmAttributes: 02h
wMaxPacketSize: 512
bInterval: 0
bRefresh: 0
bSynchAddress: 0
Endpoint:
bEndpointAddress: 81h
bmAttributes: 02h
wMaxPacketSize: 512
bInterval: 0
bRefresh: 0
bSynchAddress: 0
Endpoint:
bEndpointAddress: 82h
bmAttributes: 03h
wMaxPacketSize: 4
bInterval: 9
bRefresh: 0
bSynchAddress: 0

dagbay
Posts: 2
Joined: Sat Jan 27, 2018 5:06 am

Re: libusb transfer not working on RPi 3

Sat Jan 27, 2018 5:36 am

I have a cross platform custom USB device as well. I was able to find a working solution using hidraw interface which is basically stream file I/O. Works on Windows well and I just got it to work on Rpi.

jc2789
Posts: 5
Joined: Mon Jan 15, 2018 11:55 am

Re: libusb transfer not working on RPi 3

Wed Feb 07, 2018 5:44 pm

Solved it :D
As you can see, in the original device descriptor, all of the three endpoints were in Interface 0. This is where the problem is.
I changed it so Interface 0 has no endpoint (as I don't need an interrupt EP), and added an Interface 1 with the two bulk transfer endpoints.

This should be filed as a bug in the RPi Linux kernel since there is no such rule says that Interface 0 is not allowed to have bulk transfers.
The original configuration worked under libusb for other platforms.

User avatar
topguy
Posts: 4743
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: libusb transfer not working on RPi 3

Thu Feb 08, 2018 11:14 am

jc2789 wrote:
Wed Feb 07, 2018 5:44 pm
This should be filed as a bug in the RPi Linux kernel since there is no such rule says that Interface 0 is not allowed to have bulk transfers.
I believe here is the place to file it.
https://github.com/raspberrypi/linux/issues

v_silvero
Posts: 3
Joined: Fri Feb 23, 2018 12:59 pm

Re: libusb transfer not working on RPi 3

Fri Feb 23, 2018 1:09 pm

jc2789 wrote: Solved it :D
As you can see, in the original device descriptor, all of the three endpoints were in Interface 0. This is where the problem is.
I changed it so Interface 0 has no endpoint (as I don't need an interrupt EP), and added an Interface 1 with the two bulk transfer endpoints.

This should be filed as a bug in the RPi Linux kernel since there is no such rule says that Interface 0 is not allowed to have bulk transfers.
The original configuration worked under libusb for other platforms.
Are you sure of that?.. I have a similar problem..
How can I change the number of interface of the device??

jc2789
Posts: 5
Joined: Mon Jan 15, 2018 11:55 am

Re: libusb transfer not working on RPi 3

Fri Feb 23, 2018 2:38 pm

v_silvero wrote:
Fri Feb 23, 2018 1:09 pm
jc2789 wrote: Solved it :D
As you can see, in the original device descriptor, all of the three endpoints were in Interface 0. This is where the problem is.
I changed it so Interface 0 has no endpoint (as I don't need an interrupt EP), and added an Interface 1 with the two bulk transfer endpoints.

This should be filed as a bug in the RPi Linux kernel since there is no such rule says that Interface 0 is not allowed to have bulk transfers.
The original configuration worked under libusb for other platforms.
Are you sure of that?.. I have a similar problem..
How can I change the number of interface of the device??
For descriptor, I looked into some other LPCOpen USB examples and "meshed up" one using the descriptor for USB VCOM. Then i changed the callback setting in USB Initialization to match the new descriptor/interface configuration.

daforce
Posts: 3
Joined: Wed Jul 11, 2018 9:47 pm

Re: libusb transfer not working on RPi 3

Wed Jul 11, 2018 9:52 pm

I'v been struggling with GPhoto2 with timeout problem.(works fine with the same version on other machines. only crashes on raspberry pi)

The problem occurs when transferring bulk data via usb. Always timeout exception.

I even installed some other OS, like fedberry and faced the same exception.

May be there is a hardware problem with RPI 3 b+?

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 3 guests