USB Host library problem

Hello everybody (especially Gus or someone else working for GHIelectronics)

It seems like there is a bug in the USB host functionality, when reading input from a bluetooth dongle.

When making the bluetooth functionality work with a PS3 Controller (http://wiki.tinyclr.com/index.php?title=PS3_Controller). I discovered that it you can only read a maximum of 16 bytes when reading from a interrupt endpoint - look in the code, at the “EV_REMOTE_NAME_COMPLETE” case. I made a work around, so I just read the next 16 bytes and so on, until the name has been read. At first I thought it was normal, but then I tried to port the program to the USB Host Shield for Arduino (http://www.circuitsathome.com/products-page/arduino-shields/usb-host-shield-2-0-for-arduino/), and I discovered that it can read all the byte (255 in total), without problem. It seems like that it automatically reads the 2. byte, and sees that the length is 255 (0xFF), and automatically read the rest. See this picture: [url]https://picasaweb.google.com/lh/photo/6Qb5lzsw-LsO9Vlxjmqs7g?feat=directlink[/url]

I know that the max packet size says, that the maximum packet size is 16 byte (see this picture: [url]https://picasaweb.google.com/lh/photo/CxYsmjAPvYhpSE942JsEJQ?feat=directlink[/url]) - but if the USB host shield can support it anyway, then the FEZ should too? :slight_smile:

It the same problem with reading the bulk input (for reading button, status, accelerometer, gyro etc.) - it can not read all the bytes - it should be possible to read 64 (again see this picture: [url]https://picasaweb.google.com/lh/photo/CxYsmjAPvYhpSE942JsEJQ?feat=directlink[/url]), but it can not. It can only read 31 bytes???
I haven’t got it working with the USB host shield yet, but I will write as soon as I got it working, and tell if it can read all the bytes sent from the PS3 Controller via the Bulk Input pibe.

I am not the USB expert so someone else will help you :slight_smile:

Okay. I think it might be a problem, with the reference itself :slight_smile:

What happens when you read more? It seems that you set the transfer timeout to 0. Over 16 bytes will definitely take more than 1 ms because the endpoint size is 16. Increase the timeout and see if it works.

Increasing “IntInPipe.TransferTimeout” and “BulkInPipe.TransferTimeout” did not help - it tried anything from 1 to 100 :frowning:

After I had a deeper look in the Arduino USB host shield code, I found out it that the library automatically detects if the length is longer than the endpoint max packet size of the interrupt input (16 byte), and just keeps reading it until the packet has been read. Take a look at this link: [url]https://github.com/felis/USB_Host_Shield_2.0/blob/master/Usb.cpp[/url] at “USB::inTransfer”

My problem is that I still can not read all 64 bytes from the bulk input. By setting the buffer array to below 31 for example:

private byte[] BulkInBuffer = new byte[30];

The following exception occurs:


    #### Exception System.Exception - 0xffffffff (7) ####
    #### Message: 
    #### GHIElectronics.NETMF.USBHost.USBH_RawDevice+Pipe::TransferPipe_Helper [IP: 0000] ####
    #### GHIElectronics.NETMF.USBHost.USBH_RawDevice+Pipe::TransferData [IP: 001c] ####
    #### PS3ControllerBluetooth.Bluetooth::BulkReadingThread [IP: 0027] ####
Number Of Completed Packets: 0
A first chance exception of type 'System.Exception' occurred in GHIElectronics.NETMF.USBHost.dll

By looking at the output byte number 3 and 4, it can see that my length only is 0x11 (17), this is not the same as my mac: [url]https://picasaweb.google.com/lh/photo/d1W9rcqunQHi0YOTERPtbg?feat=directlink[/url], as it should be 0x36 (54), it’s the same with byte 5 and 6 which is 0x0D (13) and the right value should be 0x32 (50).
It just seems like it it cut off anything from above the last joystick axis (right y-axis) - which is byte 19, as I can not read the analog readings starting at byte 24 (see this link: http://wiki.ps2dev.org/ps3:hardware:sixaxis - only as reference, as it is for when you are using USB). But it still throws an exception when reading less than 31 bytes???

Do you think it is a problem with the USB reference/library, the bluetooth dongle or the code itself? I do not think it is the code, as I did exactly the same as my mac…

It should read everything automatically.
When you get the exception, call USBHostController.GetLastError() What do you get?

Sorry I haven’t answered you before now, but I have just been so busy lately.
I am not sure what you mean, but here is a screenshot: https://picasaweb.google.com/lh/photo/b3scGCMRusz8eF8eIm7zCg?feat=directlink

I think what Mike is asking you to do is:


try
{
    codeThatFails();
}
catch
{
    USBHostController.GetLastError()
}

That’s exactly what I did, but it doesn’t print anything?

I got it working. It was actually a stupid mistake. The reason why it did not sent out the accelerometer, gyro values etc. Was because the bluetooth dongle was only version 2.0, and you needed 2.1 for it to work :slight_smile: So now everything is working. I will update the wiki straight away!