adq


Andrew de Quincey's livejournal


Previous Entry Share Next Entry
HTC Hero (MSM7201) USB host mode
adq
For the last few days I've been busy figuring out how to support USB host mode on the HTC hero. This may also apply to many other android devices (e.g. the G1, and possibly the Nexus One as I think it may use the same USB host silicon internally). I've only tested it on the Hero so far though.

Android supports USB device mode out of the box. However my aim is to use the phone as a mobile USB host. I want to control my Nikon SLR over PTP/USB in order to do fancier shoots, for example timelapses. You can also obviously do loads of other cool things: USB-serial devices, keyboards, webcams, DVB receivers, etc etc.. I knew I'd be able to implement it if I had the docs; sort of a similar situation to this XKCD :)

However, (a) there isn't a USB host mode driver for the phone, and (b) the documentation for the Qualcomm MSM7201A System on a Chip the phone uses is not available, so I was stuck for a while. A month or so ago however, my friend Mark sent me this link. That is a patch to the u-boot project implementing USB for a freescale processor. Interestingly, the register define:
#define FSL_SOC_USB_USBMODE    0x1a8
Matches that in the android USB device mode driver exactly. As do all the other fields. And there are full docs available for the freescale chips such as the MPC5121 available here. They obviously licensed the same USB controller hardware designs. I'm not quite sure whose design it was originally, as Transdimension, Oxford Semiconductor, ARC and finally Synopsys all seem to have something to do with it, and have acquired each other over the last few years.

I also needed to know what USB transceiver hardware it used. From the USB device code, I could see it communicated using the ULPI protocol. And ULPI devices implement VENDORID/DEVICEID fields in their register set. After I dumped those I could see it was an SMSC device. Its actually a USB3316, but again, register level docs are not available (there is a "data brief", but that is not detailed enough). They are for the closely related USB3320 though!

After a few days of fiddling, I have just this evening got it all working. You can see my original thread on the android kernel list here. My post with the working patch is here. You'd obviously have to get the HTC Hero kernel source (I grabbed it from developer.htc.com), patch it, and compile a custom kernel enabling EHCI/MSM7201 USB host support and disabling both USB  Function and USB Gadget support.

The next problem is that as far as I know the hero cannot supply power on the USB bus, and I'm not daring to try enabling the USB bus power hardware registers until I know more about how the charging circuitry is implemented. Therefore, I modified a portable USB hub to have two cables attached: one data with GND/D+/D- for connecting to the phone and one with GND/VBUS for supplying power to the hub itself. I'm powering everything off some rather nifty slimline rechargeable batteries acquired from Maplin.

There is information on other USB/host adapter cables at the openmoko project.

Plugging in my USB keyboard surprisingly works seamlessly - android just "works" with it. USB mice work as well in a sort of confusing manner; I think it treats them as a trackball. I've not tried anything else yet, but the idea of attaching 1TB hard disk to it sounds.... amusing :)

Here are some pictures. My workspace where I'm resoldering the cables to the USB hub:



The modified hub itself (Its some Saitek "UFO" hub:



And finally, here is it all wired together and running:




My next step will probably be to see how it can coexist with the default gadget driver; implementing USB OTG may be possible, or else I could implement some sort of software switch. Or I might just go ahead and implement some of the PTP camera control software. I've already implemented a fairly comprehensive python library, pyptp that I use from my laptop.

Page 1 of 2
<<[1] [2] >>
can you wear that hub as a necklace..?

Probably yeah! Originally it had a glowing LED in the middle that changed colour as you used it too :)

Nice Work!

(Anonymous)

2010-02-11 06:04 pm (UTC)

I've also been working on this project as well. Nice job getting this to work. What cable did you end up using?
Do you think this would work?
http://www.electronicproductonline.com/catalog/product_info.php?products_id=2043
( from the openmoko page )

Andy

Hi - yeah, that'd probably work fine; it just needs something to allow normal USB cables to be plugged into the USB B socket after all; you can program the hardware to switch the data lines over in software if they're the wrong way round in the cable :)

I *would* check its not doing something daft like mixing GND and the +5V supply up though!

The phone can't supply power to use peripherals as far as I know so you'll need something to inject power into the system; I've not investigated enough yet though. Perhaps it could be connected to a powered hub?

I basically just hacked an old unpowered USB hub apart and added the correct USB connector for the phone and a seperate power supply for my cable.

Great work --- Droid and USB stick attached?

(Anonymous)

2010-02-11 06:10 pm (UTC)

Great work! My apologies in advance for not being on the same programming level, but i've got a few questions as I've been trying to figure out a way to do this for my Motorola Droid in order to view video files or just general files off an SD card(through a USB reader) or a USB stick

What is the main reason you had to recompile the kernel on your phone??-->."and compile a custom kernel enabling EHCI/MSM7201 USB host support and disabling both USB Function and USB Gadget support."? Was this to get the phone switched from peripheral to host mode switching the USB functionality? I know the other way to switch the Droid to host mode is through a custom soldiered USB dongle...posted here: http://www.tombom.co.uk/blog/?p=124 ...so is the kernel to forgo having to do this on the HTC? If that is the reason would there be a way to do this for the droid or easily create an app to switch the USB to host mode?

It sounds like from other posts the Droid will power devices connected to it once in host mode; therefore will your Y connector work to power both the phone(charge it) and the hub or device connected to the phone?...feel free to email me if it would be easier joshjhilgart@gmail.com

Re: Great work --- Droid and USB stick attached?

adq

2010-02-11 06:26 pm (UTC)

Hi, you basically need two cooperating drivers: one for USB device mode, and one for USB host mode.

The droid is based on the TI OMAP chipset which AFAIK already has USB device+host drivers in linux. Motorola seem to have been kind enough to leave it on in their shipping software (I guess their engineers thought it was a cool feature :) The Droid cable basically tells it to switch between device and host mode.

The other android phones - G1/Hero etc - are based on the Qualcomm MSM7201 chipset, which has different USB hardware. Google/HTC have (irritatingly) only developed a USB device driver.. so if you wanted to use it as a host you were out of luck - the hardware supports it, but the software is missing.

I basically just added in the missing host driver code. Right now its still very much a prototype (I only started investigating this a week ago!). It is missing the auto-cable-switching the droid supports (which is the "USB OTG" standard); I fully intend to support this if the hardware allows it though!

As of right now, I haven't tried telling the phone hardware to /supply/ power to the USB bus; it depends how the hardware is wired physically. It might work, but it also might fry something!

The Y cable basically replaces the missing USB power supply for the USB peripherals with a battery. And you're right: the phone can still function as a USB host, and since the power line config is unchanged, it is also charged by the battery at the same time.


Edited at 2010-02-11 06:33 pm (UTC)

Sprint Hero Too?

(Anonymous)

2010-02-11 08:35 pm (UTC)

That's hardcore! Good to see someone taking the time to hack around the deficient documentation. Do you know offhand if it'll work with the chinless Sprint Hero phones? Or would they use different hardware?

Re: Sprint Hero Too?

adq

2010-02-11 08:55 pm (UTC)

Ta! :)

According to http://www.htc.com/us/support/hero-sprint/tech-specs/ the sprint uses the MSM7600, which I hear is the CDMA version of the MSM720x series.

I've just downloaded the sprint kernel source from developer.hero.com; it looks like its using an identical msm_hsusb USB-device-mode driver, so its /extremely/ likely the host mode will be identical to the GSM Heros as well. I can't confirm till someone's actually tried it though obviously.

Re: Sprint Hero Too? (Anonymous) Expand

usb-vga?

(Anonymous)

2010-02-11 10:11 pm (UTC)

usb-vga?

Don't see why not, linux has drivers for a "SIS" USB VGA dongle.. the main problem would be how to make the android stack use it sensibly I guess.

I *do* like the idea of controlling a project from it though.. something along the lines of the SixthSense demo? (http://www.ted.com/talks/lang/eng/pranav_mistry_the_thrilling_potential_of_sixthsense_technology.html)

I wonder if you can get USB heads-up-display glasses... be rather interesting to /really/ overlay things like the Layar android app on reality :)

instead of creating that patched cable do you think that a battery hub like this one that can change the gender of the USD , can be use instead ?

http://www.everfast.com.hk/catalog/usb-hub-battery-charger-usb-hub-
4-ports-p-138.html

PS: it has also battery based charging capabilities

Fantastic! A battery powered USB hub would be ideal!

The only reason I'm not using one is because I didn't find one after a quick search and wouldn't have wanted to wait till it arrived.

On the other blog they propose this cables ? Which one do you think will be more suited ?

http://www.brightonnet.co.jp/english/product/other/bbm-wireel.html

http://www.overstock.com/Electronics/Eforcity-USB-2.0-A-to-Micro-B-Female-Male-Adaptor/4488837/product.html?cid=123620&fp=F&ci_src=14110944&ci_sku=12436069

http://cgi.ebay.com/Micro-USB-Host-Cable-for-Nokia-N810-OTG-on-the-go-N-810_W0QQitemZ250569989865QQcmdZViewItemQQptZPDA_Accessories?hash=item3a57229ee9#ht_5104wt_939

PS : I would like to buy one of this cables :)

PS2: I see that e-bay link that this is already working on various linux powered mobile devices.

I'll try and have a look at those properly tomorrow; I don't want to give bad advice.

I too am interested (Anonymous) Expand

Marvelous idea

(Anonymous)

2010-02-18 01:53 pm (UTC)

That's just a simply marvelous idea! Having USB host support in the kernel almost doubles the usefulness of this device - it basically turns the Hero into a mini-computer.

I can think of a lot of very good reasons why to have host support:
- More (and more flexible) storage solutions
- Keyboards, mice and other input devices (thinking Playstation joysticks anyone?).
- External screens
- Using the Hero as a controller for other equipment (Digital photography, printers etc)
- Wired networking cards

Really looking forward to seeing this kind of stuff in the custom ROMs.

Re: Marvelous idea

adq

2010-02-18 01:58 pm (UTC)

Totally!

Also, imagine when these things start getting "old" and hitting the second hand market - that's a lot of rather nifty embedded development systems.

BTW - in case you've not seen the more recent progress - its not just the Hero now; the magic works, the g1 should too, and I have hopes for the Nexus One.

Re: Marvelous idea (Anonymous) Expand

Camera remote control

(Anonymous)

2010-03-01 11:45 pm (UTC)

Excellent work - beyond my technical prowess but I know enough to appreciate what you've done. I've just spent a few hours scouring the web for ways to make just this happen - control my camera for timed exposures, automated aperture sequences and so on. Pretty much come to the conclusion that system-level will be required to open it up for host (or PTP) mode. I figure part of the reason could be reluctance to open up the phone-as-modem can of worms but it sure would be useful.

Another idea is to talk to a small self-contained device which has the USB host capability but uses a different mode of communication: bluetooth or wifi maybe. A cursory search reveals little but it is hard to remove the hits that deal with the opposite thing: getting bluetooth via a usb dongle... Anyway, if such a beast existed it is conceivable that the USB host could be realized in a non-rooted phone perhaps? It would even be nice to not to have to physically attach the phone to the camera for the purpose of shooting (or whatever your app would be).

Enough ranting, I really just wanted to congratulate you on solving this problem :-)

Stefan Engstrom


Re: Camera remote control

adq

2010-03-02 02:04 pm (UTC)

Thanks!

Yeah, I'd looked for a bluetooth-to-usb-host widget as well, but never had any luck finding one.

I'm hoping I'll be finished with fixing the device-mode stuff soon; its not exactly the most interesting thing to do. I'd ideally like to write an android app for the camera control.

Since the hero and G1 use the same port, and pretty similar software, do you think it would be possible? Also, if I sent you the parts, and some cash, could you make one of those for me? I don't have a soldering iron, so that would be greatly appreciated!

Re: possible on the G1?

adq

2010-03-08 10:13 pm (UTC)

as far as I know, yes, the G1 should work, but no one has confirmed it yet as far as I remember. The magic has been.

Not really up to making bespoke cables, but I know its possible to do it with a HDD-style USB Y-cable connector and a converter and no soldering.. I'm hoping to put a guide up once I've got the thing actually working.

Just what I was after to start my project

(Anonymous)

2010-03-29 05:02 am (UTC)

Brilliant!. I am currently using the Teknologist 1.9 Kernel on the Modaco rom image 3.0. I will have to see if its been enabled in the tree. Of course come mid April, we can hope the new 2.1 kernel's are better compiled from HTC.

My current project that I want to develop on my Hero (and for Android phones in general) is based around a TIRA device (http://www.home-electro.com/tira2.php). I just ordered it today, and expect it this week. Since this device is LIRC compliant, it would be idea for this!. Most likely I would have to use batteries like you for my testing, but in long run would like to get power for Tira board from the HTC Hero.

I will post my results some where once I have some success (or not).

Please let me know what you think in this thread.

-Randy

Re: Just what I was after to start my project

adq

2010-04-01 09:54 pm (UTC)

Ah cool! That sounds interesting, keep me informed how it goes. I'll hopefully get some time tomorrow to debug my latest patch.

Gamepad

(Anonymous)

2010-04-14 05:03 pm (UTC)

Hi, I think your work is awesome.

I'm thinking about connect a game pad (NES like) to the Hero and searching for info I ended in your post.

Do you think is possible to connect a game pad to the USB port on the Hero?

I’ll appreciate so much if you can guide me or give me some clues.

Thanks and regards.

Hi, it should support pretty much any USB device, as long as the appropriate device driver module is compiled and present on the phone.

I spotted this: http://www.joystiq.com/2007/04/12/nes-usb-controller-dont-make-it-buy-it/

nexus one

(Anonymous)

2010-04-22 08:13 am (UTC)

I have been dreaming of being able to connect a portable screen like this one http://www.medltech.com/ to my nexus one accompanied by a Bluetooth keyboard. It would be like having a netbook in your pocket. Imagine RDP to your powerful home PC with that set up. I have been searching this topic and came across your work. Keep it up this is awesome stuff.

HTC Incredible

(Anonymous)

2010-05-26 03:46 am (UTC)

Hey I love your project and want to help. I have the HTC Incredible and created a Micro USB A and B cable from http://www.tombom.co.uk/blog/?p=124 - Chris Paget's Blog , I got USB- Keyboard and mouse working on the Moto Droid but not on Incredible. What do I need to do to get it to work on my machine? Do I need to wait for it to be rooted or can I install your patch?

Re: HTC Incredible

adq

2010-06-05 12:35 am (UTC)

If its an HTC phone, it'll be based on the Qualcomm chipset, so it would most likely need my patch ported to it (only the TI OMAP chipsets will just "work" with the cable mod).

As I don't have the hardware, I can't really help as its the sort of fiddly thing you need to test on a live device.

Acer liquid host mode

(Anonymous)

2010-09-27 04:51 pm (UTC)

May be or not? What are you think.

kernel patched and compiled, whats next?

(Anonymous)

2010-09-29 10:25 am (UTC)

Hi, Im very interested in USB Host function, I follow your instructions and compiled the kernel successfully, but now Im trying to boot from zImage, but the only ways I know are:

- using fastboot: famous "remote: not allowed" error
- compile a complete ROM (not sure, too complex)

What is the recommended way to test my USB Host kernel?

If anybody send me a compiled ROM for htc Hero with USB Host tested, i will pray for his soul...at "jesusmorion gmail com" with corresponding @ and dot.

Need the App

(Anonymous)

2010-11-10 04:52 pm (UTC)

All well and good. Can we get an App generated to trick "host mode" on Android?

Unfortunately its not that easy; it needs a kernel upgrade to add the missing host mode drivers.

hi, Andrew! is power supply any special?

(Anonymous)

2010-11-23 07:47 am (UTC)

i just wanna buy a usb hub, but i don't know which one i need actually, 0.5a or 1a, or even higher?
my email is rt77789@gmail.com, thanks for you sharing this great post.

Re: hi, Andrew! is power supply any special?

adq

2010-12-06 09:48 pm (UTC)

Hi, most usb devices will only draw up to 0.5a, if that.... as long as you don't attach a USB-powered hard disk or something!


Turn on USB host mode via driver module

(Anonymous)

2010-11-23 01:25 pm (UTC)

Can the USB host mode be implemented via driver module, instead of rebuild whole kernel?
So we can use "insmod" to load it dynamicaly on demand.

Would like to know how to use ULPI to setup USB host mode as default during the init of the module.

Re: Turn on USB host mode via driver module

adq

2010-12-06 09:50 pm (UTC)

Yeah, I did implement that actually, but again, its a custom patch to HTC's Hero kernel. You'd still need to replace the entire kernel though as you need to disable the USB function mode code, and that is compiled in.

This is some incredible work you've done, Andrew.
Unfortunately, I'm not a programmer so there are lots of things that keep me wondering.

Look. I'm using an LG Optimus One device. Specs are as following:
-Android Version: 2.2
-Kernel Version: 2.6.32.9 lg-electronics@LGERP-BLD-LNX #1
Mon Oct 18 09:44:15 MSD 2010
-Build Version: FRF91
Software Version: LGP500-V10d-OCT-18-2010

And the phone is rooted. I hesitate to perform any kernel replacement since I don't know whether this operation will either degrade or upgrade any of these versions. The reason is simple: Android version 2.2.1 / Software version V10F just can not be rooted. So if SU(root) will disappear the would be quite a trouble. Could you please tell me in what way will patching affect all these versions? (I really wonder why did Android creators make so many ver. IDs after all...)

Could you please also give me some advice on how to edit the patch for it to fit into my LG software? Or, probably, the USB host mode is already included in that model? I don't have even a faintest idea where to start.

I fully agree with your thoughts

paxexuhumi

2011-03-07 10:43 pm (UTC)

Spot on with this write-up, I actually suppose this website wants far more consideration. I’ll most likely be again to learn rather more, thanks for that info.

Looking Forward To Getting Involved

(Anonymous)

2011-04-09 04:45 am (UTC)

Thanks...this looks really interesting. I am looking forward to having my says!

Just saying "hi" from the Gold Coast, Australia - Looking Forward To Getting Involved.

(Anonymous)

2011-04-11 02:00 am (UTC)

Thanks...this looks really interesting. I am looking forward to having my say!

Looking forward to get involved

(Anonymous)

2011-04-12 11:30 am (UTC)

Hey - I am certainly delighted to find this. cool job!

Thanks for putting all this together. I'm really excited by the idea of using this app with My hero CDMA and my Canon 7D. I'm not sure if I'll need a USB HUB for power or not since both the Camera and the phone are powered devices in themselves. Here is a link to the software i'm hoping to get running. I'm going to look to some IRC channels on help building this into my HERO CDMA and hopefully can share a working build with the XDA community if I can get it working. Do you have any thoughts on whether or not this is a futile effort? Preferably Does someone out there who has done this on their HERO have a Supported Canon Camera that can give it a shot?

http://boingboing.net/2011/08/08/dslr-controller-app-for-android.html

Page 1 of 2
<<[1] [2] >>