2014年1月15日 星期三

How to enable FTDI Support for your USB Host featuring Honeycomb Tablet (including sample native application)

For many projects it would be great to have an RFID-Reader on your tablet. Sadly there is no Tablet yet that has a built in NFC Chip. However, there are plenty of Readers that connect through USB to your device, and some of them use an FTDI USB Serial Converter for communication over the serial protocol.

Provided you have a USB Host Port and Root on your Tablet it is possible to communicate with a large number of peripherals that use the FTDI chip. And we want to show you how we did it.
To achieve this goal you will need to compile the Kernel Driver Module for FTDI Support in order to have an interface under “/dev/ttyUSB0″ in the end. You do this by downloading the recent Tegra Kernel from the Android Repos:
http://android.git.kernel.org/?p=kernel/tegra.git;a=tree;h=refs/heads/android-tegra-2.6.36;hb=refs/heads/android-tegra-2.6.36
For our purpose we just downloaded a Snapshot of the Kernel.
Note: if you are unsure which kernel version to use, execute step 1 first on your device and return to the repositories to choose the appropriate version.
Follow these steps to compile the new Kernel module.
1. First you need to find the appropriate Kernel version for your Android Tablet. Some manufacturers change the “Extraversion” parameter. Drop into a root shell on the tablet and find out which version you are running; also pull the current kernel config:
# cat /proc/version
extract the kernel config from your device
$ adb pull /proc/config.gz config.gz
2. Set up the current Kernel config for your freshly downloaded Kernel snapshot. Let’s assume you put the the Kernel into ~/kernel/ .
$ zcat config.gz > ~/kernel/tegra-android-tegra-2.6.36-f48009c/.config
3. Configure your new Kernel to create the FTDI module using menuconfig
Let’s say you have your Android NDK under /opt/android-ndk-r5…
~/kernel/tegra-f6874dc$ export PATH=/opt/android-ndk-r5/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin/:$PATH
~/kernel/tegra-f6874dc$ make menuconfig ARCH=arm CROSS_COMPILE=arm-eabi- -j4
Navigate to “Device Drivers -> USB Support -> USB Serial Converter Support -> USB FTDI Single Port Serial Driver” [1]
Select it as a Module hitting the “M” key so that it reads “<M>”.
Now adjust the Makefile so the Extraversion fits your extracted version.
~/kernel/tegra-android-tegra-2.6.36-f48009c$ gedit Makefile
4. Compile the module for your system
If you did not yet export the path, then do so now:
~/kernel/tegra-f6874dc$ export PATH=/opt/android-ndk-r5/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin/:$PATH
And start compiling the modules:
~/kernel/tegra-android-tegra-2.6.36-f48009c$ make modules ARCH=arm CROSS_COMPILE=arm-eabi- -j4
Your modules should be building now.
5. Your FTDI Kernel module is now located in the “drivers/usb/serial” directory. You can copy it to your tablet now:
~/kernel/tegra-android-tegra-2.6.36-f48009c$ adb push drivers/usb/serial/ftdi_sio.ko /sdcard/
load the module using insmod
~/kernel/tegra-android-tegra-2.6.36-f48009c$ adb shell
$ su
# cd sdcard
# insmod ftdi_sio.ko
And done you are! Connect your FTDI Device (for instance this USB FTDI-Board: http://www.sparkfun.com/tutorials/243) and use this Code to start communicating with your peripheral device (in this case an RFID Reader).
To compile the project files extract them and use Android’s “ndk-build” script.
~/simplectrl/jni$ /opt/android-ndk-r5/ndk-build
The executable file is found in simplectrl/lib/armeabi/simpleserial. Push it to your device, connect your FTDI device and make it executable:
~/simplectrl$ adb push lib/armeabi/simpleserial /data/local/
~/simplectrl$ adb shell
$ su
# cd /data/local/
# chmod 777 simpleserial
# ./simpleserial
This has been tested on a Rooted Acer Iconia Tab A500 with Android 3.0.1 and the Kernel Version 2.6.36.3
We hope we were able to get you started with serial programing over USB :)
Don’t hesitate to comment our post and give us some feedback to improve our mini-article.
[1] you will also find the “USB Profilic 2303 Single Port Serial Driver” there, which is used for many USB-Serial Converters.