|
Htc
Activating the serial port on HTC Dream, HTC Magic and HTC Hero
IntroductionHTC Android devices such as the Dream, Magic and Hero each have an ExtUSB (Extended USB) port. This port is used to charge the phone, connect to a computer via usb (using an ExtUSB or miniUSB cable), and communicate with a headset. In addition to these functions, the port also functions as a (cmos?) level serial port which in stock setups serves as a debug port. This last feature can be used as a standard (cmos?) level (NOT RS232 LEVEL!) serial port to connect to anything from a server in a beowulf cluster to an arduino, but first the headset detection and debug console code in the kernel must be disable. This requires a new kernel to be compiled, or at the very least installed on the phone which the following explain how to do. Once you have completed these instructions you can use the android-serialport-api offered in the download section to control the serial port from within android applications! Prerequisites
Backup your phoneYou should have installed a utility called nandroid when you installed Cyanogen's mod. This utility backs up all of the entries on your phone so if something should go wrong, you can restore your phone just as it was. Go ahead and search the XDA dev forums if you don't know how to do this already and save the backup on your computer. If you do not plan to build your own kernel, skip to Testing the kernel Extract the ramdisk out of the boot.imgSearch through the nandroid backup folder you copied onto your computer and find the boot.img file. Afterwards, run it through the getramdisk.py script: $ getramdisk.py boot.img Save the ramdisk.img file that is generated for later. Pull your current config file off your phoneIt is necessary to grab your phone's current kernel configuration so that the new serial enabled kernel can be built the same way and support the same features that the old one did. $ adb pull /proc/config.gz $ gunzip config.gz Save the config file that is uncompressed for later. Dream and Magic: Grab Cyanogen's Kernel$ git clone git://github.com/CyanogenMod/cm-kernel.git $ cd cm-kernel $ git branch -r For that last command, take a look at what branches are available: origin/HEAD origin/android-2.6.29-bfs origin/master and use the one that matches your kernel version. For example, with CyanogenMod-4.1.999, my kernel is 2.6.29.6-cm, so I'm going to use the android-2.6.29-bfs entry. Currently that is the only entry available, but in the future, this may not be the case. Once you identify the branch you want to use, check it out: $ git checkout --track -b cm-2.6.29-bfs origin/android-2.6.29-bfs Hero: Download kernel from HTC Developer Center$ wget http://dl4.htc.com/RomCode/Source_and_Binaries/hero-2.6.29-5f74b252.tar.gz $ tar -xzf hero-2.6.29-5f74b252.tar.gz Add the Arm cross-compiler to your pathFirst, find out where you installed the NDK. Next go to the build/prebuilt/ folder and identify the toolchain you should use for your OS. Next run the following: $ export PATH=$PATH:<path to NDK folder>/toolchains/arm-linux-androideabi-4.4.3/prebuilt/<your os specific choice>/bin $ echo $PATH If you don't see the directory appended to your PATH arguments, you may need to use another command to set environmental variables on your machine. Configure the kernelType the following command from your kernel root directory in order to create a default configuration file: $ make ARCH=arm CROSS_COMPILE=arm-linux-androideabi- hero_defconfig Next, open the .config file with your favorite text editor and replace the following lines: Replace these lines: CONFIG_MSM_DEBUG_UART=3 # CONFIG_MSM_DEBUG_UART_NONE is not set # CONFIG_MSM_DEBUG_UART1 is not set # CONFIG_MSM_DEBUG_UART2 is not set CONFIG_MSM_DEBUG_UART3=y by: CONFIG_MSM_DEBUG_UART_NONE=y # CONFIG_MSM_DEBUG_UART1 is not set # CONFIG_MSM_DEBUG_UART2 is not set # CONFIG_MSM_DEBUG_UART3 is not set Replace these lines: CONFIG_MSM_SERIAL_DEBUGGER=y CONFIG_MSM_SERIAL_DEBUGGER_NO_SLEEP=y # CONFIG_MSM_SERIAL_DEBUGGER_WAKEUP_IRQ_ALWAYS_ON is not set # CONFIG_MSM_SERIAL_DEBUGGER_CONSOLE is not set by: # CONFIG_MSM_SERIAL_DEBUGGER is not set Replace this line: CONFIG_HTC_HEADSET_V1=y by: # CONFIG_HTC_HEADSET_V1 is not set Save your modifications, you are now ready for a fresh kernel compilation. Compiling the kernelCompiling takes a while so go grab a hot snack. When you run the following, it may ask you to configure additional kernel build configuration settings if any new features were added since your kernel was last compiled too. If in doubt with these steps, hit enter to accept the default value. make ARCH=arm CROSS_COMPILE=arm-linux-androideabi- Cross your fingers it compiles ok! Testing the kernelBefore you make your new kernel the default kernel used to boot the phone with, you should test it out by temporarily booting the phone with it via fastboot. To do this, first attach your computer to your phone and power it off. Next, hold down the camera button and then the power button until you see a screen with three android robots on skateboards. If you don't see the text "FASTBOOT" on the display, press the return button a few times until you see it. If you built the kernel yourself, run the following: Remember that ramdisk.img file from earlier? Find out where you stuck it. Next, look in your cm-kernel directory under arch/arm/boot/ and find the zImage file. Once you have located these two files, you can now run the following to temporarily boot the kernel. $ fastboot boot <path to zImage>/zImage <path to ramdisk.img>/ramdisk.img OR if you are just using a boot.img from the downloads page to get serial support, run this: $ fastboot boot <boot.img file> It will take a little while, but hopefully it should boot up, if not.. you have some debugging to do! Good thing you didn't install it already, right? If the phone does boot up, check to make sure the phone works as expected (i.e. does wireless still work, do applications behave strangely, etc). Assuming everything looks ok, plug your phone into your computer again and run the following: $ adb shell This lets you browse around your phone's file systems to make sure the serial device was created. # cd /dev/ # ls -l If you see ttyMSM2 in there, congratulations, your serial port works. If it does not appear.. you have more debugging to do. Install the kernelOnce you finally get the kernel working to your liking, you can enter the engineering SPL on your phone again, then run one of the following to install it: If you built your own kernel, run this: $ fastboot flash:raw boot <path to zImage>/zImage <path to ramdisk.img>/ramdisk.img $ fastboot reboot OR if you are just using a boot.img from the downloads page to get serial support, run this: $ fastboot flash:raw boot <boot.img file> $ fastboot reboot | |
Hi! I need a levelshifter from the CMOS G1 side to my Atmega (runs@5V). Can you name one thats cheap, good and easy to use? Thank you! I also search for a cheaper supply of thos plugs.
Search google for 3.3v to 5v level shifter (instead of CMOS). It's a pretty common task and there are a variety of ways to accomplish it. You can do everything from use a few resistors and a diode, a mosfet, or prebuilt solution you can order online.
Thank you. I happen to have problems with google Mail with the Kernel from your download section (havent tried another one though). I heard there are some bugs in it anyway. Any of you willing to spend the effort to compile one for the latest cyanogen release? I can try myself but dont know if i get it together and I think this would be good for other people as well. By the way: thank you very much for figuring this out and putting it together. I was not able to test it yet (because i am waiting for my plugs) but if it works good this is exactly what i have been searching for. Where is the donate-link? Cheers!
Does this mean that communication from arduino to android is possible? I am trying to use an arduino board as a data acquisition board to feed data into android, which will log it.
The google mail problem was aa funny bug in the app not the kernel. I erased the sd content while a mail with a photo was in send progress. The mail app hung until i had photos on the card again. Then a mail with a complete different photo was sent and the app worked. Again. Funny! Today i made the first communication from an atmega to the g1. I did not close the serialport app afterwards and suddenly some stuff were blocked and the phone finally did freeze. Any problems knows with the api, kernel or sample app?
Whoops, sorry for the lack of reply, I guess I don't have update status messages turned on. I will build and upload a new kernel for the stable cyanogen release this weekend.
jpan8288, yes. If you are using a 3.3v arduino, you should be able to hook it up directly. If you are using a 5v arduino, you will need a level shifter setup to connect to the g1.
igaffai, the serial stuff hasn't gone through too much testing so you probably found a bug. Feel free to gather what info you found and add it to the issues tab. :)
igaffai
Great, Im looking forward for the new Kernel! Thank you!
Ahh, better not take the STABLE-marked release. Theres a few bugs in it. I would choose 4.2.5 instead... Cheers!
It seems to me like the Cyanogenmod 4.2.5 has the serial port enabled by default. I did not see this mentioned in the release notes, but /dev/ttyMSM2 is visible and usable.
I am experiencing a problem with the API and I can't seem to figure it out by myself.
When I open up the SerialPort? Console activity and connect two android phones together, the majority of the data that I send across not appear on the other console. Occosionnaly a byte comes across, but most are lost somewhere. However, when I send something from one phone and at the same time also send something from the other (e.g. using the Loopback test activity), they both receive bytes without missing any. When I stop sending the incoming bytes are lost again.
Has anyone come across a similar problem? I am not experienced with using the serial port so any help would be very much appreciated.
Huh, I'm glad I read your comment before making the new kernel. (regarding the serial port already being present in 4.2.5). I'll have to find my adapter and double check that it is working ok however.
Perhaps the actual android team updated the kernel so you can use the serial port AND detect headsets at the same time.. that would be really nice!
If they didn't and someone from the cyanogen build team just enabled two options that might cause problems like the one you have seen... all speculation obviously for now.
Hi Nelson,
Any luck checking out the new kernel yet? I've managed to make it work with an ugly polling system for now, but it would be great to know what is causing so much trouble.
Hi I want to interface with a device X that has serial output through USB. So I want to retrieve information like this: X --> USB--> g1.
Is this possible? When I plug in X to my linux PC it shows up as /dev/ttyUSB1
Any help would be greatly appreciated. second question. Using the serial cable referenced at instructables.com, can I use this for kernel debugging?
hello, i'm in engineering but NOT in comp-sci, and my team is trying to build a G1 that can talk to one of our medical devices on campus. my question is, how do i get the android app to grab data from /dev/ttymsm2? i'm guessing through the API, but m programming skills are not so good. please help!
p.s. is there a hyperterminal-like program that i can use to test?
Hi, if I have an Android device which has a USB port, does this API work the same way to write to/read from the USB port?
Installed cyanogenmod 4.2.5; ttyMSM2 is visible, but loopback is sending but not receiving. Looks like it doesn't work
anybody tried on HTC Hero? i can see ttyMSM2 in devices.
Can someone send to me the serialport dll for this project? (rice103@gmail.com) THANKS A LOT!!!
Hi rice103, I just committed libserial_port.so in SVN, you can directly import the project in Eclipse now.
For Hero users, the kernel can be downloaded from http://member.america.htc.com/download/RomCode/Source_and_Binaries/kernel_hero_0078c992.tar.bz2 A kernel config file is already included in the archive, you just have to change CONFIG_HTC_HEADSET and CONFIG_MSM_SERIAL_DEBUGGER as specified on this page. (under test)
Hi cedric, I want to use this on my Hero. If you got it to work, can you upload a binary then? Thanks.
I do not have Hero, but I am helping Charlie who has one. I will upload a Hero kernel if we reach to compile one
Yes, i tried with Cedric to do this communication with my Hero. We are building on kernel but it was not working, i hope we can do it quickly.
Cedric will upload (and i can help him) all what you need if i succeed.
I forgot, if someone succeed he's welcome to send us an email ^^
Hi, we succeed tonight. I can send and receive data. Now we just have to do optimization and a good ramdisk.
It will be as soon on the wiki
Good job. Please share the kernel and some instructions and I will try it out on my Hero as well. Really great to see that is was possible to get working.
I'm really excited this is working now. Please update the wiki soon!
Yeah, please update.
Does the Motorola Droid have an enhanced usb port? From what I've seen, it connects to headsets through the 3.5mm headphone jack it has. Does this mean you could create a headphone jack to serial adapter and get a Droid to work with serial devices?
I can not build the Hero kernel on Windows (cygwin). Some problem that Windows is case insensitive. Can someone upload a serial enabled kernel binary for the Hero?
I can no build the kernel. PLEASE BINARY FILES !!!
Hello, Use kernel source from here: http://wiki.github.com/loxK/android-msm-2.6.27-hero/
This is patched communty kernel (based on vanilla htc kernel) for Hero. Remember to change CONFIG_HTC_HEADSET and CONFIG_MSM_SERIAL_DEBUGGER. Api demo program works fine :] I will test uart-usb connection tommorow.
So, i used G1 headset cable, transmission from PC to Hero was fine but Tx and GnD pins are connected together (thanks Cedric for a tip), after solving the problem i can send packets from Hero to my PC. Bottom line i managed to get a connection in both directions. Thanks for great api !
Cyanogenmod has evolved since the writing of the manual so there are some considerations that would have saved me some time.
Fastbooting the compiled kernel (downloads section)
ttyMSM2 means nothing!
Kernel configuration
SerialPort?.apk
This simple tool is great but lacks some instructions. The config section is straightforward. The loopback test transmits random (I guess) data via the TX port (i.e. PIN 8 of the Magic) and expects to receive it through the RX port (PIN 9). You will have to short-circuit these two pins. If bytes are received, congratulations. The console section is useful when testing communication with an external device.
Hi there, is somebody able to help me out with a Kernel for Cyanogen 5.0.0.7?? I am using the Google Ion/ADP2...
Andy, I am also using Cyanogen 5.0.0.7 for my HTC Magic. I am compiling a kernel without CONFIG_HTC_HEADSET right now, I will upload the kernel in download section soon.
Here it is Andy, a fresh new kernel for CyanogenMod? 5.0.7. I have checked that camera and WiFi? is working, but I do not have my serial connector to test now. Could you confirm serial is working please ?
anyone know of a nexus one serial enabled kernel floating around?
never mind, compiled and tested kernel (zImage) for nexus one that runs on 2.6.33.4 Cyanogenod 5.0.7.1-N1 the N1 serial cable from bestcelldist simply did now work. I created my own from a motorola T191 and a micro usb end spliced together. one thing to note was that the signal ground (reference voltage) and chassis ground on the ttl side needed to be connected to work.
Everything works fine except the serial in the 2.6.33.4 just posted using cyanogenmod 5.0.7 on a 32B board (HTC MyTouch? 3G). It doesn't output out :(
Okay upon further investigation it seems that serial doesn't work doing the mentioned change (CONFIG_HTC HEADSET is not set) in any kernel past 2.6.29. For example 2.6.34 doesn't work.
I think it has something to do with the USB on the go stuff they added and other usb gadget stuff. I have been able to get 2.6.29 to work perfectly (although disabling the htc headset support means the headset icon constantly displays)
Hi Guys!
I'm watching this very closely, as I want to build an app that interfaces to a ham radio rig and controls it. I'm hoping someone will come up with a solution that works with a Droid Eris so I can get started.
Good work!
Hello everyone!
I've been trying to port the serialPort API to Freescales' Mx51 EVK. It provides 3 serial ports, ttymxC0,1 and 2. I have been running into permissions and thread issues. Reading the into (again) it appears that the api is design for serial communication via the USB port - although the java.io as applied seems it should support direct UART/serial port access as well. Any insight or pointers would be greatly appreciated (I'm not rebuilding w/NDK - simply importing the android.serialport directly into my project).
Keep up the great work!
@bubbah.T can you post your kernel or .config? I have a working cable and was able to access shell from the serial port but I keep getting the following messages in the terminal. Also the serial port program does not work and errors out in DDMS with a "Cannot open port" "native open returns null" 835.328552 suspend: enter suspend 835.328796 PM: Syncing filesystems ... done. 835.388854 Freezing user space processes ... (elapsed 0.01 seconds) done. 835.408905 Freezing remaining freezable tasks ... (elapsed 0.01 seconds) don e. 835.440826 PM: suspend of devices complete after 9.634 msecs
Hi everyone!
I was looking for an this particular application. I know it says HTC Dream, Magic, and Hero, but does this application also work for the Rhodium? I remember seeing the Rhodium and Hero share the same Qualcomm chipset.
I may be mistaken. Thank you in advance!
Just an FYI, it looks like this library is setting the serial port to the defaults used by cfmakeraw().
I wanted to be sure I was getting 8n1, so I modififed the jni/SerialPort?.c to be as follows:
Seems to be working great for me so far on the G1
I can confirm that the serial does NOT work on kernels later than 2.6.29 at least for the HTC Dream/ADP1/G1 device.
If anyone has / know of patches that solve this problem, I would be very interested.
Thanks.
I am using: HTC Hero Sprint
When I go to test the kernel: $ fastboot boot <path to zImage>/zImage <path to ramdisk.img>/ramdisk.img
I receive an error: >(remote: not allowed)
Has anyone got a solution for this? I cannot find one.
I root my phone using the UNREVOKED apk.
Thanks for your help.
I am testing the serial enabled kernel on a HTC Dream/ADP1/G1.
I have CyanogenMod? 5.07 installed and successfully fastbooted into the kernel_cyanogenmod_2_6_33_serial_enabled.
However, WLAN is not working.
I have pushed both, the wlan.ko from the serial enabled kernel zip and the wlan.ko from the original CM 5.07 package onto the device.
Can anybody give me some help on this issue, please? Thanks in advance.
Charlie, so you had modified the kernel, leaving API in initial state? Could you describe what exactly was done? Just a few sentence.
What is the difference between standard level and RS 232 level? I would like to establish a connection with the device using RS 232 so I would really appreciate if you will throw up a page how to accomplish that.
>What is the difference between standard level and RS 232 level? I would like to establish a connection >with the device using RS 232 so I would really appreciate if you will throw up a page how to >accomplish that.
RS-232 uses -3v to -15v for a "0" and +3v to +15v for a "1". (-3v to +3v are invalid). "Standard" or TTL-level serial uses 0v for a "0" and +5v for a "1" (on a 5v system - otherwise the "1" will be the voltage of the system - 3.3, 1.8 or whatever). In this case, it's apparantly 2.8V
Building a kernel 2.6.29 for Hero right now, anyone volunteer to test it please (I have no Hero) ? (The test is safe - no need to flash your phone)
Hi, Super new to all this. I want to read data from a Medical Device (Ventilators) via its 9 pin RS232 port, using a null modem cable (and USB-serial adaptor like Prolific) , into an android phone. Is this doable? Will the API work for RS232? Thanks
>Hi, Super new to all this. I want to read data from a Medical Device (Ventilators) via its 9 pin RS232 port, using a null modem cable (and USB-serial adaptor like Prolific) , into an android phone. Is this doable? Will the API work for RS232? Thanks
The API itself is ok for Prolific USB-serial adaptor, as long as you match the prerequisites: - your Android phone must have an USB host connector in order to plug the Prolific USB-RS232 adapter - your phone must support this adapter (pl2303 Linux module installed) - and you must change the unix permissions of file /dev/ttyUSB. If one point is not covered, I recommend you to use a bluetooth-RS232 adapter, and use the Android class "BluetoothSocket?" instead of android-serialport-api. The later solution works with any Android device supporting bluetooth, but is more expensive and consume the battery.
Cedric - appreciate the lightning fast response... this is really good info. I had a few different questions -> If I use IOIO or Android Open Accessory Dev Kit, will that help (easier?) making android phone a USB host connector? Do u know any specific android device thats tested/worked with rs232? Now, like the following link http://www.instructables.com/id/Android-G1-Serial-Cable/, do I need to figureout cabling for RS232? It seems like if I just follow what you wrote, I could use the industry standard RS232 null modem cable with prolific USB-Serial adapter.
I just created a new wiki page for your concern: android_to_rs232_guideline