Adding the driver to the Kernel
make ARCH=arm CROSS_COMPILE=arm-eabi- distclean
make ARCH=arm CROSS_COMPILE=arm-eabi- omap3_beagle_android_defconfig
Up to this point everything goes as normal. Now let’s add the FTDI support as a driver (NOT as a module). FTDI published a very detailed tutorial that can be found at http://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_132_Adding_FTDI_Devices_VCP_Driver_Support_to_Android.pdf.
make ARCH=arm CROSS_COMPILE=arm-eabi- menuconfig
If ‘menuconfig’ is not present in the host (Ubuntu), install it using the following code:
sudo aptitude install lib32ncurses5-dev
As the documentation presented by FTDI says, it is necessary to enable a few things:
- “Device Drivers” -> “USB Support” -> pres ‘y’ over “Support for Host-side USB”
- “Device Drivers” -> “USB Support” -> “USB Serial Converter support” -> press ‘y’ over “FTDI Single Port Serial Driver”
Now save this configuration and build the Kernel using
make ARCH=arm CROSS_COMPILE=arm-eabi- -j4
When connecting a FTDI device to the BB xM with this modified Kernel, you will see a ttyUSBx directory inside /dev.
Connecting the FTDI device to the Beagleboard
First of all it will be very useful to connect the Beagleboard Serial port to the host machine and establish a connection using Minicom (or something like that). Once you got there it will be very easy to see if the driver was properly included, and the device is recognized.
See the following screenshot. It shows the device console before the FTDI converter was connected and after that. The device was recognized perfectly, and ttyUSB0 was created under /dev.
A simple test from shell
If you have busybox on Android you can make a simple test in order to see if the driver is well configured (In case you don’t have busybox, you can follow my post on how to install busybox on BeagleBoard).
- Connect RX and TX on the FTDI IC
- Connect to board using ADB.
- Setup ttyUSB0.
/data/busybox/busybox stty -F /dev/ttyUSB0 115200
- Open microcom (similar to minicom)
/data/busybox/busybox microcom -s 115200 /dev/ttyUSB0
- Write something and it will be echoed. If you disconnect the RX and TX, what you send it will not be echoed.
Writing to ttyUSB from C
Init the ttyUSB interface
system("/data/busybox/busybox stty -F /dev/ttyUSB0 115200");
The ttyUSB interface can also be initiated from /init.rc file at the end of “on boot” section.
Getting a File Descriptor
FILE * usbdev = fopen("/dev/ttyUSB0", "rw+");
Read and Write from the File Descriptor
char message; /* buffer of data to send */
char rMessage; /* receive buffer */
fwrite(message, sizeof(char), 8, usbdev);
fread(rMessage, sizeof(char), 8, usbdev);
Closing the File Descriptor
Writing to ttyUSB from Java
Connecting to ttyUSB from Java requires a little bit of extra work. By default, a device under “dev” has permissions only for root. And if your Java app it is not running with root (or your base board is not rooted) you have to change permissions to ttyUSB0 in order to let other apps to write and read from the file (using JNI, of course).
This can be done using several methods, for example:
chmod 777 /dev/ttyUSB0