Installing the ft245 USB Driver

November 2011

 If you do not install the ft245 driver, the system will use the default driver, currently ftdi_sio.  There have been improvements to this driver and hardware has gotten faster, so you should try this driver with your SDR-IQ to see if it fast enough.  The FTDI chip is a serial emulator, so ftdi_sio adds files of the form /dev/ttyUSB0, /dev/ttyUSB1, etc.  Set sdriq_name to one of these files in your config file for the SDR-IQ.  Set the sample rate to the lowest value to see if it works.

December 2010

Please note that the FT245 driver is NOT needed for USB control of SoftRock hardware.  Recent SoftRocks use USB control but not through a serial port emulation.  Normal serial port control of hardware does not need the FT245 either.  The only reason to install the FT245 driver is to get a very high speed serial port emulation for use with the SDR-IQ and SDR-14 from RfSpace.

June 2010

The ft245 driver does not compile on the latest version of Ubuntu.  There is a missing include file <linux/smp_lock.h>, and the info and warn macros must be changed to pr_info and pr_warning.  The modified ft245.c is here and the Makefile is here.

January 2008

The ft245 driver is a serial to USB driver for Linux.  It works with the FT245BM and similar chips from FTDI.  This chip is used in the SDR14 and SDR-IQ receivers from RfSpace.  The ft245 driver is optimized for speed and is the preferred driver for Linrad and other Software Defined Radio (SDR) applications.

There are currently two other drivers available; the ftdi_sio driver and the libftdi0 driver.   See the FTDI site for currently available drivers.  Using the SDR-IQ on my machine, I found the ftdi_sio driver limited to about 70k samples per second.  The libftdi0 driver was capable of about 100k SPS.  The ft245 driver works fine at 110k SPS and I don't know its upper limit yet.  The other drivers may be preferred for applications other than SDR.  The ftdi_sio driver emulates a terminal with full termios capability, and the libftdi0 driver offers bit-bang capability.

This document describes how to install the ft245 driver on a modern Linux system.  But if you are using Linrad, see below because Linrad has its own way of installing the driver.

My computer is an Asus AMD dual core running Debian stable, kernel 2.6.  USB drivers depend on the Hotplug, Udev and Modules subsystems of Linux, and these are evolving rapidly.  So the exact description of ft245 installation will probably be different for you, and will almost certainly be different in the future.  Therefore I am giving more than the usual amount of explanation so you can adapt this to your needs.  Besides, it is fun to know how things work.

Install Kernel Packages

The first step is to install some packages you may not have.  All drivers are compiled for a specific kernel version, and that requires the kernel header files.  Use your package or RPM software to install these packages plus any dependencies:

    linux-headers-2.6-686
linux-kernel-headers

I use Synaptic on Debian.  The command line version is aptitude (use "man aptitude").  Be sure to install the headers for the exact version of Linux you are running.  This is a good time to become familiar with the uname -r command:

$ uname -r
2.6.18-5-686
$

It gives the version of the kernel that is running on your computer.  It is used in scripts that compile modules, and it appears in directory names such as "/lib/modules/2.6.18-5-686".  When you upgrade to a new kernel, you must re-compile the ft245 driver for that kernel.  The old version will not even be found, and may not work anyway.  The package names above are top-level packages that depend on the most recent version of Linux.  That means that when a newer version of Linux comes out, the most recent headers are downloaded too.  If everything works right, you should have a directory /lib/modules/VERSION/build, where VERSION is the exact output of "uname -r".  Always use your own version, and not "2.6.18-5-686" as you follow this document.

Download ft245 Source

Create a directory for the ft245 driver files, such as /home/jim/ft245.  Download the latest driver version from the ft245 site into that directory.  The file is a .tgz file, so:

    gunzip ft245_driver-lin26-203.tgz
tar xf ft245_driver-lin26-203.tar
rm ft245_driver-lin26-203.tar

Then from a terminal in that directory, compile the ft245 driver by entering "make".  If you get the error message

    ft245.c:195: error: unknown field 'owner' specified in initializer

then comment out line 194 through 196 by inserting "//" at the start of the line.  If you get a lot of error messages, don't panic; you are probably just missing another header file.  Look at the beginning of the error messages for something like "can not find foobar.h".  That means you need the file foobar.h but you don't have it.  Find out which package provides that file, and install it.  I go to Debian's package page and search for the file name "foobar.h".  Do not search package names and descriptions; search for files.  Install the package that contains foobar.h and try again.

If this all works, you will have your driver file ft245.o and ft245.ko.  The correct file on my system is ft245.ko, but older versions of Linux use ft245.o.  Look in /lib/modules to see which one you need.  Or try loading it with modprobe (as root).  You will get an error message if you load the wrong one.

Copy the correct driver (you will need to be root) to a suitable location corresponding to your kernel version:

   cp ft245.ko /lib/modules/2.6.18-5-686/kernel/drivers/usb/serial
Next you must run depmod to create various databases:
$ depmod
$

Now if you plug in (for example) the RfSpace SDR-IQ, the ft245 driver should be loaded.  Verify this with "lsmod".  You can load the driver by hand with "modprobe ft245" (you will need to be root).  You can remove the driver (root again) with "rmmod ft245".

If you have trouble, try looking at kernel messages with dmesg.  The kernel will add messages as USB devices are plugged and unplugged.  Look at the newest messages at the end of dmesg output.

$ dmesg | tail -20
$

Loading the Correct Driver

 Your ft245 driver is now installed, but we are not done yet.  The ftdi_sio driver is included with Linux, and so you have two drivers that claim to handle the SDR-IQ (or other) hardware.  Even if things seem to work, they may fail in the future if the wrong driver accidentally gets loaded first.  This is where the modinfo command comes in handy.  You must be root to use modinfo.

# modinfo ft245
filename: /lib/modules/2.6.18-5-686/kernel/drivers/usb/serial/ft245.ko
author: Robin Cutshaw, spam
description: USB Driver for FTDI FT245 chipset
license: GPL
vermagic: 2.6.18-5-686 SMP mod_unload 686 REGPARM gcc-4.1
depends: usbcore
alias: usb:v0403pF728d*dc*dsc*dp*ic*isc*ip*
alias: usb:v0403p6001d*dc*dsc*dp*ic*isc*ip*
#

All this output is useful information, but look closely at the lines starting with "alias".  The ft245 driver is advertising that it is a driver for the USB devices with vendor ID 0x0403, and product ID's 0xF728 and 0x6001.  We can look up these ID's and find that the vendor is FTDI.  If you enter "modinfo ftdi_sio" you will see that it claims to support the same two devices (as indeed it does).  To make sure that the ft245 is selected as the RfSpace driver create the file /etc/modprobe.d/sdriq (or other name of your choice) with this contents:

    alias   usb:v0403pF728d*dc*dsc*dp*ic*isc*ip*    ft245
    alias   usb:v0403p6001d*dc*dsc*dp*ic*isc*ip*    ft245

Note that some systems use modprobe.conf instead of modprobe.d.  So what is happening?  The vendor and product ID's are coded into the USB hardware device.  When the device is plugged in, the system looks for the name of a driver.  The "alias" lines in the files in modprobe.d provide the name of the driver to use.  If no alias line is found, then the aliases coded into the driver files themselves are used.

The Files in /dev

Now if you unplug your SDR-IQ (or other hardware), remove the ft245 and ftdi_sio drivers with rmmod (be root), and plug the hardware back in, you should see that the module ft245 is loaded (lsmod).  When ft245 loads it will create the file /dev/ftdi2450, so check to see that the file exists.  If the ftdi_sio driver is in use, it creates the file /dev/ttyUSB0.  These files in /dev are special files that provide communication with the driver.  To use the driver, you open the file in /dev that the driver created.  But on my computer the file /dev/ft2450 is create with rw-rw---- permissions, and with owner root and group root.  That means I can't open it unless I am root.  I hope by now everyone knows that you never require users to run as root.  So create the file /etc/udev/rules.d/local.rules with this contents:

    # Additional rules for this computer:
# USB devices
KERNEL=="ft245?", MODE="0660", GROUP="dialout"

The Linux udev subsystem creates the files in /dev that are needed from time to time.  The above rule specifies that files named "ft245?", that is, "ft245" followed by one additional character, should be created with "0660" permissions (rw-rw----) and with a group name "dialout".  I chose "dialout" because I am a member of it already, and that is the group of /dev/ttyUSB0 on my computer.  Check what groups you belong to for other possibilities (maybe the plugdev or audio groups work for you).  An alternative would be to change the MODE to 0666, meaning read/write by anyone, and removing "GROUP".  Now unplug your hardware and plug it back in.  You should have /dev/ft2450 with proper permissions.  By the way, if you have multiple hardwares, they have names ft2450, ft2451, ft2452, ....

Use with Linrad

If you downloaded Linrad and ran "make sdr14", then the ft245 driver is installed in a different way.  It is started with the SYS5 startup scripts in /etc/rc0.d, /etc/rd1.d, etc.  In these /etc/rc*.d directories are links to the file /etc/linrad/usb_sdr14.  The usb_sdr14 program loads and unloads the driver, and creates the file /dev/linrad_ft245 to access it.  I am not sure about interference from ftdi_sio.

There is nothing wrong with this, and it will work on many Linux flavors including older systems.  But if you want to install ft245 as described above, then don't use "make sdr14".  If you already have the usb_sdr14 links in /etc/rc*.d, remove them (carefully) and remove /etc/linrad.  You can check the Linrad Makefile to see exactly what you need to remove.  Then in lsetad.c change the define for SDR14_DEVICE_DRIVER from "/dev/linrad_ft245" to "/dev/ft2450".  I have not tested this, but it should work.  Linrad also has its own version of ft245.c, so maybe you want to install that version of ft245.ko.

Programming Notes

If you are writing code for the ft245 there are a few things you should know.  The receive buffer is not a circular buffer.  Characters from USB are appended to a 64k byte buffer, and the buffer write position is reset to zero only when the buffer is empty.  So you must be sure to read all available characters before the buffer has a chance to overflow.  Also, a read of greater than 64k is considered an error, so you must limit a read request to 64k maximum.

The data from the SDR-IQ is a byte stream with the data length and type coded in the first two bytes.  You read a block by decoding these two bytes and then reading the rest of the block using the length.  But if any bytes are lost, you will read into the next block, and the two byte header will actually be data from a subsequent block.  This causes the read process to go out of sync.  It is easy to lose bytes by starting another program, moving windows around on the screen, etc.

To detect a loss of synchronization, I consider all lengths less than 2 (the length includes the two-byte header) and greater than 50 (large data blocks have a special length of zero) to be an error.  Assuming the SDR-IQ is running and returning data blocks, I try to resynchronize by looking for the data block start 0x00, 0x80.

Credits

This was written by Jim Ahlstrom, N2ADR, in the hope that it would be useful.  You can write me at user name jahlstr computer gmail.com.  I am using the ft245 driver in one of my SDR projects QUISK.  Many thanks to Robin Cutshaw for the driver, and to Lief Asbrink, SM5BSZ, for Linrad and his many contributions to all things SDR.