This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430 HID Datapipe detection delay in Android

Other Parts Discussed in Thread: MSP430F5529, MSP430F5528

I have an MSP430-based device operating with a HID Datapipe over USB.  I'm connecting this device to an Android tablet running an app I wrote based on information from slaa630.pdf: Android Applications With MSP430™ USB on Mobile Devices.  It works great after the device is recognized, but for some reason it takes a long time to be recognized (on the order of 10 seconds).  The same hardware on windows takes less than 1 second to be recognized.  Does anyone have any idea what I can do to make this faster, or how I can figure out what is causing the delay?

Thanks.

  • Hi Sasha,

    Is the enumeration problem occurring everythime you disconnect and connect back up to the Android device?  Are you running one of the HID examples (H5 or H6) on the MSP430 or is it your own datapipe application? 

    Can you try running the H5 example with the HID application provided with SLAA630.pdf?  Are you still having this issue?

    Regards,

    Arthi 

  • Hi Sasha,

    Are you still having issues with the Android device?  If not we would like to close this post.

    Regards,

    Arthi

  • Hi Arthi,

      Yes I am still having issues.  The H5 demo project doesn't run on my hardware so I've ordered a MSP-EXP430F5529 dev kit to try with that.  It should arrive within a week and I will update the post with what I find at that time.  Please leave the post open in the meantime.

    Thanks,

    Sasha

  • Hi Arthi,

      My MSP-EXP430F5529 arrived today.  I was able to get the H5 demo app to run on it successfully.  I loaded the TI MSP430 HID 1.0 app on my tablet (a Samsung Galaxy Tab S2 running Android 6.0.1).  Unfortunately, this also exhibits extremely slow device detection.  In the TI MSP430 HID app I have to click the "Select HID device" button to make it go out and look for the device and tell me whether anything was found.  I plugged in the MSP-EXP430F5529 running the H5 demo app and repeatedly clicked the "Select HID device" button until the device showed up as found.  The time between when I plugged the device into the tablet and when it would show up on the list of found devices was on the order of 10 seconds.  On windows, the same device is detected almost instantly.  Other HID devices (such as a keyboard) are detected on the tablet within a second - so I know it's possible.  Any idea what I might be able to do to speed up detection of the MSP430 HID datapipe interface on Android?

    Thanks,

    Sasha

  • Is the detection faster with example H8, which emulates a 'real' keyboard?
  • Yes.  Detection of the device when it is running example H8 is very fast (basically immediate).  So this slow detection seems to be somehow specific to the HID datapipe interface.  I don't know a lot about how the datapipe interface is different than a keyboard interface.  Is it using a different driver on the Android side?

  • A HID keyboard uses the keyboard driver; a datapipe interface ends up using a driver that makes it available to Android programs. This appears to be a problem with Android.

    I don't know if this is a general Android problem, or only with your S2. Can you try it with a different device?
  • What do you mean when you say that the datapipe interface ends up using a driver that makes it avaliable to Android programs?  Do you have any more information on what driver that is?

    I am seeing the same slow detection of the HID datapipe device on a Samsung Galaxy S3 phone, a Samsung Galaxy S5 phone and a Samsung Tab 4.  

  • According to usbhost.c, it goes through usbfs. I don't know where this delay comes from.

    It might be a better idea to wait for a ACTION_USB_DEVICE_ATTACHED

  • What is the usbhost.c file you are referring to? I don't see any file by that name in MSP430USBDevelopersPackage.

    I was already looking at the ACTION_USB_DEVICE_ATTACHED inside a BroadcastReceiver (I copied that code from the sample TI MSP430 HID Android app). I added some logging to get the relative timing of when ACTION_USB_DEVICE_ATTACHED is received vs when the getDeviceList() function on my UsbManager object (polled in a background thread) returns a device with my Vendor ID and Product ID. The timing is almost identical. As in: it is taking on the order of 10 seconds from when I actually plug in the MSP430 HID datapipe device before ACTION_USB_DEVICE_ATTACHED is broadcast. Is there anything earlier in the driver chain I can look for?

    Also I'm curious, is there anyone out there who has ever used any MSP430 HID datapipe device with Android and gotten their device to be detected in less than 10 seconds?

  • usbhost.c

    Anyway, using HID is necessary only for Windows. If your device is intended to be used with Android, try changing the interface class to vendor-specifc. (And nowadays, even in Windows, you can replace HID with WinUSB.)

  • And what about CDC? If there is no 10 sec detection problem with CDC, maybe you can switch to CDC.

    Clemens, don't know about today, but at the time when I was doing some USB tests on MSP430 (http://forum.43oh.com/topic/2775-msp430-usb-benchmark/?p=23696) generic bulk (WinUSB) was not included in TI USB stack (examples).

  • Hi Sasha,
    I am not sure what is causing the 10 sec delay. The android HID tool uses an AlertDialog box to display all the detected HID devices. Maybe there is a delay sending the information between the background to the foreground of the application and maybe AlertDialog class might not be the ideal class to do this. In your application maybe you can use a Spinner to do a drop down box to display the HID devices after the user hits the 'Select HID Devices' button.

    Regards,
    Arthi
  • Hi Arthi,

      The delay is not in the UI.  I've been playing with this a while so I've had different ways of indicating when the connection occurs including logging it to disk (with a timestamp) and waiting for it to occur and then picking it up in the debugger.  Both of these methods had a ~10 second delay between when I plugged the USB from the MSP430 device in and when the device was recognized within my Android app.

    -Sasha

  • Hi Sasha,

    I have donwloaded an app called 'List USB Devices' from Google Play onto my tablet and this app has no problem recognizing the HID device.  It does not take up to 10 secs to enumerate the device.  So this tells me that the MSP430 USB stack is not the issue and that it could be the HID application. 

    Regards,

    Arthi  

  • What I don't see in Arthi's reply is what make/model tablet he used. I also note that Sasha's testing was all done with Samsung equipment. Might be interesting to try different a different tablet manufacturer equipment just in case there is something specific in Samsung's Android implementation.
  • Hi Arthi,

      I'd like to try to reproduce your results.

      What were you using as your HID device in your test?  Was it a MSP-EXP430F5529 running the H5 demo app, or was it something else?  

      What tablet were you using?  And what version of Android was it running?

      How long did it take to enumerate the device?  You indicated it took less than 10 seconds, but I'm interested in knowing more precisely how long a delay you saw.

    Thanks,

    Sasha

  • Hi Sasha,

    My tablet is Acer Iconia.  I don't remember the version but I believe it is 4.x.  The HID application is running on the MSP430F5529 Launchpad (it is the same as MSP-EXP430F5529).  I have the same issue as you with TI's HID application taking up to 10 seconds however when I run the 'List USB Devices' application from Google Play, the enumeration is quite fast (1 sec).  The 'List USB Devices' application displays raw USB data.

    Regards,

    Arthi

  • Thank You Arthi,

    I was able to find the "List USB Devices" App and reproduce your finding that it is able to detect the connection of the MSP430 HID device very quickly (on all of my devices). Now I just need to figure out how that app is searching for attached USB devices and replicate that. Do you have any idea what it might be doing? Up until now I have been using:

    UsbManager manager = (UsbManager)getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();

    That method is very slow, so it must be something different. But I can't find any alternative way of listing USB devices. Does anyone know of any other way? One clue I have is that the "List USB Devices" app lists not only my TI MSP430 HID device, but also two "Linux Foundation" devices for "2.0 root hub" and "3.0 root hub", which don't show up through the UsbManager getDeviceList call.

    Thanks,
    -Sasha

  • The internal root hubs are not shown by the Android framework, so the "List USB Devices" app must be using a native library that accesses the Linux APIs directly.

    Apparently, it is the Android framework that is responsible for the delay.

    Which implies that there is nothing that you can do on the MSP430 to work around this; you'd have to bypass the Android API in the app.
  • Just to add some commentary, and please understand that I do not know anything about the Android operating environment, but....

    On a Windows OS system, application software can register a callback function with the USB subsystem saying "Hey, when a USB device with [these characteristics] is attached/removed/suspended, call [my function]". Then you get notified when the event happens and can respond accordingly.

    So, does Android provide a similar facility? If so, is that how your Android app is operating? Or is it basically polling the OS for information on a periodic basis and that is what adds to the delay you are seeing?

  • See the section titled "Working with Devices" on this page developer.android.com/.../host.html and follow through with the "Intent Filter" discussion.
  • I was able to confirm that the "List USB Devices" app is using libusb to access the list of available USB devices.  It is bypassing the Android API exactly as Clemens said.  I'm satisfied that I understand the issue enough to mark my original question answered.  

    Thank you everyone.

    One suggestion I would like to make (although it will probably go into the ether).  It would be nice if TI would update their demo Android app to also use libusb so it can achieve reasonable performance.  I don't think anyone would ever use the Android API to connect to a MSP430 using a HID datapipe interface for any professional product.  The detection performance is just too poor.

  • Hi Arthi,

    We have a similar problem with USB device detection delay between 10 and 30 seconds on different Android tablets. We see the same delay when we use H1_LedOnOff example instead of our firmware - using MSP430F5528, with two versions of developers package - MSP430USBDevelopersPackage_5_00_01 and MSP430USBDevelopersPackage_5_20_06_02.

    At the same time there is no such delay when we connect MSP430 FF5529 LaunchPad Evaluation Kit with out-of-the-box software - it is detected by Android within a second or two. It looks like USB implementation there is different from the developers package, but we don't see any source code for the LaunchPad.

    Any idea what is the difference? Is it possible to get the source code to compare it with developers package implementation?

    Thanks,
    Vitaly
  • See http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP-EXP430F5529LP/latest/index_FDS.html for the LaunchPad software example code.

    You question about the delay is already answered in this thread: it's caused by the Android HID driver, not by the MSP. The out-of-box software does not use HID.

  • Hi Vitaly,

    The out-of-the-box demo example, Outofbox_emulStorageKeyboad, implements HID keyboard and not HID data pipe as demonstrated in H1_LedOnOff example. HID datapipe examples are a subclass of HID.

    The source code for the launchpad can be downloaded from TI Resource Explorer or from here:

    software-dl.ti.com/.../index_FDS.html

    As far as differences between Keyboard code and H1_LedOnOff code at the HID level and not at the application level would be the HID reports for keyboard and datapipe.  The reports can be found in descriptors.c file.

    Regards,

    Arthi

     

**Attention** This is a public forum