Android ICS on HTC Desire with USB Host Mode

  • Install CronMod on your HTC Desire (see this thread: http://forum.xda-developers.com/showthread.php?t=1946517 )
  • build custom kernel with USB host mode support:
    • git clone git@github.com:croniccorey/eternity-kernel.git
    • git checkout remotes/origin/ics
    • apply Host Mode patch:
    • make clean
    • make bravo_defconfig
    • make menuconfig (select USB options, deselect USB gadget support)
    •  “Device Drivers => USB Support => USB Modem (CDC ACM)  include as a module.
    • $ grep MSM .config|grep -v ‘not set’|grep USB
      CONFIG_USB_EHCI_MSM7201=y
    • make -j4
  • Install kernel and modules to android device (zip file method through recovery – will post step by step once I get everything working)
  • Enable host mode drivers:
    • adb shell (opens a shell connection to android from your laptop)
    • su
    • mount -o remount,rw /
    • mount -o remount,rw /system
    • depmod -a
    • IMPORTANT plug in a powered arduino to the htc desire usb port (using your OTG cable) before loading any USB modules otherwise the arduino will not be detected
    • modprobe usbcore
    • dmesg output:
      <6>[ 140.937835] usbcore: registered new interface driver usbfs
      <6>[ 140.938232] usbcore: registered new interface driver hub
      <6>[ 140.941314] usbcore: registered new device driver usb
    • modprobe ehci-hcd
    • dmesg output will start with some good output like this:
      [  218.682006] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
      [  218.682342] ehci_hcd: block sizes: qh 60 qtd 96 itd 160 sitd 96
      [  218.682617] initializing MSM7201/QSD8X50 USB Controller
      [  218.701751] msm_hsusb msm_hsusb: Qualcomm MSM7201/QSD8X50 On-Chip EHCI Host Controller
      [  218.702148] msm_hsusb msm_hsusb: new USB bus registered, assigned bus number 1
      [  218.702392] msm_hsusb msm_hsusb: reset command 0080002 (park)=0 ithresh=8 period=1024 Reset HALT
      [  218.702819] msm_hsusb msm_hsusb: park 0
      [  218.703002] msm_hsusb msm_hsusb: reset command 0080b02  park=3 ithresh=8 period=1024 Reset HALT
      [  218.721771] AVS setting V to 1200 mV @760 MHz
      [  218.722229] msm_hsusb msm_hsusb: ...powerdown ports...
      [  218.751770] msm_hsusb msm_hsusb: irq 58, io mem 0xa0800000
      [  218.772155] usb usb1: default language 0x0409
      [  218.772399] usb usb1: udev 1, busnum 1, minor = 0
      [  218.772613] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
      [  218.773010] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
      [  218.773376] usb usb1: Product: Qualcomm MSM7201/QSD8X50 On-Chip EHCI Host Controller
      [  218.773620] usb usb1: Manufacturer: Linux 2.6.38.8-EternityKernel-ICS-1.3-GSM-RC-dtbaker ehci_hcd
      [  218.774017] usb usb1: SerialNumber: msm_hsusb
      [  218.774658] usb usb1: usb_probe_device
      [  218.775573] usb usb1: configuration #1 chosen from 1 choice
      [  218.781036] usb usb1: adding 1-0:1.0 (config #1, interface 0)
      [  218.790649] hub 1-0:1.0: usb_probe_interface
      [  218.790985] hub 1-0:1.0: usb_probe_interface - got id
      [  218.798156] AVS setting V to 1250 mV @859 MHz
      [  218.800445] hub 1-0:1.0: USB hub found
      [  218.804229] hub 1-0:1.0: 1 port detected
      [  218.808135] hub 1-0:1.0: standalone hub
      [  218.811920] hub 1-0:1.0: individual port power switching
      [  218.818847] hub 1-0:1.0: individual port over-current protection
      [  218.823364] hub 1-0:1.0: Single TT
      [  218.826507] hub 1-0:1.0: TT requires at most 8 FS bit times (666 ns)
      [  218.833007] AVS setting V to 1300 mV @1002 MHz
      [  218.838653] hub 1-0:1.0: power on to power good time: 20ms
      [  218.843139] hub 1-0:1.0: local power source is good
      [  218.847930] hub 1-0:1.0: enabling power on all ports
    • Then probably display an error like this:
      <4>[ 121.077850] ------------[ cut here ]------------
      <4>[ 121.081909] WARNING: at kernel/irq/manage.c:291 0xc00a87f0()
      <4>[ 121.087646] Unbalanced enable for IRQ 58
      <4>[ 121.091430] Modules linked in: ehci_hcd(+) usbcore bcm4329
      <4>[ 121.096923] Backtrace:
      <4>[ 121.099426] Function entered at [<c003f09c>] from [<c0427dfc>]
      <4>[ 121.105163] r7:c00a87f0 r6:c0454fe7 r5:00000123 r4:d7199d18
      <4>[ 121.110809] Function entered at [<c0427de4>] from [<c006b5d4>]
      <4>[ 121.116607] Function entered at [<c006b578>] from [<c006b690>]
      <4>[ 121.122558] r9:c04f0cf0 r8:d812a644 r7:c04d2e18 r6:0000003a r5:60070013
      <4>[ 121.128936] r4:c04e53d0
      <4>[ 121.131561] Function entered at [<c006b658>] from [<c00a87f0>]
      <4>[ 121.137481] r3:0000003a r2:c0455045
      <4>[ 121.140930] Function entered at [<c00a879c>] from [<c00a8df0>]
      <4>[ 121.146850] r5:60070013 r4:c04e53d0
      <4>[ 121.150299] Function entered at [<c00a8d5c>] from [<bf04d6f4>]
      <4>[ 121.156250] r7:c04d2e18 r6:c04d2e10 r5:00000000 r4:d812a400
      <4>[ 121.161773] Function entered at [<bf04d4d8>] from [<c0252c6c>]
      <4>[ 121.167694] Function entered at [<c0252c4c>] from [<c02517f0>]
      <4>[ 121.173400] Function entered at [<c025172c>] from [<c0251918>]
      <4>[ 121.179321] r7:00000000 r6:bf055ddc r5:c04d2e4c r4:c04d2e18
      <4>[ 121.184844] Function entered at [<c02518b0>] from [<c0250f24>]
      <4>[ 121.190795] r7:00000000 r6:c02518b0 r5:d7199df0 r4:bf055ddc
      <4>[ 121.196319] Function entered at [<c0250ed0>] from [<c0251614>]
      <4>[ 121.202239] r7:00000000 r6:c04da220 r5:cb9320e0 r4:bf055ddc
      <4>[ 121.207763] Function entered at [<c02515f0>] from [<c02507d4>]
      <4>[ 121.213714] Function entered at [<c025071c>] from [<c0252058>]
      <4>[ 121.219390] Function entered at [<c0251f9c>] from [<c02530e0>]
      <4>[ 121.225341] Function entered at [<c0253084>] from [<bf058094>]
      <4>[ 121.231018] Function entered at [<bf058000>] from [<c0035388>]
      <4>[ 121.236968] r4:bf055e38
      <4>[ 121.239349] Function entered at [<c00352a4>] from [<c009d534>]
      <4>[ 121.245300] Function entered at [<c009c404>] from [<c003b040>]
      <4>[ 121.251007] ---[ end trace 2d5c07135d1ce6e9 ]---

      this error can apparently can be safely ignored

    • then the dmesg output will contain information about connected usb devices:
      [  219.261657] usb 1-1: new full speed USB device using msm_hsusb and address 2
      [  219.322021] AVS setting V to 1250 mV @245 MHz
      [  219.411682] usb 1-1: ep0 maxpacket = 8
      [  219.415496] usb 1-1: skipped 3 descriptors after interface
      [  219.416442] usb 1-1: default language 0x0409
      [  219.425262] usb 1-1: udev 2, busnum 1, minor = 1
      [  219.425476] usb 1-1: New USB device found, idVendor=20a0, idProduct=4150
      [  219.425903] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=220
      [  219.426147] usb 1-1: Product: Eleven     
      [  219.426513] usb 1-1: Manufacturer: www.freetronics.com     
      [  219.426757] usb 1-1: SerialNumber: 7493430303035120F1C1
      [  219.427551] usb 1-1: usb_probe_device
      [  219.427764] usb 1-1: configuration #1 chosen from 1 choice
      [  219.430053] usb 1-1: adding 1-1:1.0 (config #1, interface 0)
      [  219.430419] usb 1-1: adding 1-1:1.1 (config #1, interface 1)
    • Success – android is reading that there is a freetronics eleven arduino attached via usb! progress!
    • EDIT: DON’T NEED USBSERIAL, SEE ACM MODULE BELOW:  modprobe usbserial vendor=0X20a0 product=0X4150  (values from idVendor and idProduct above in dmesg output) this creates a /dev/ttyUSB0 device and the following dmesg output
    • modprobe cdc-acm
    • this creates /dev/ttyACM0 on the android device – woot!
    • load this basic sketch onto an arduino:
      void setup() {
        // put your setup code here, to run once:
        Serial.begin(9600);
      
          Serial.println("init");
      }
      
      void loop() {
        // put your main code here, to run repeatedly:
        Serial.println("loop");
          delay(500);
      }
    • Run this on android to setup the /dev/ttyACM0 correctly:
      stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
    • Then try to read from the raw serial device like so:
      cat /dev/ttyACM0
    • You should see output like:
      localhost dtbaker # cat /dev/ttyACM0    
      init
      loop
      loop
      loop
      loop
      loop
      loop
      loop
      loop
      ^C

      reset the arduino if you get nothing

    • Some further testing / diagnostics:
      • Install the android app USB Host Diagnostics https://play.google.com/store/apps/details?id=eu.chainfire.usbhostdiagnostics&hl=en
      • launch the app and click run diagnostics, wait a bit, grant superuser access (a few times if needed), it will probably popup saying it can fix some problems, click OK and reboot the device as per the instructions
      • repeat the steps above (loading the modules) after reboot, plug in the arduino again and launch the USB Host Diagnostics app again

Leave a Reply

Your email address will not be published. Required fields are marked *