Monday, November 9, 2009

Upgrade subversion to 1.6 in Debian 5 (lenny)

The default subversion package for Debian is svn 1.5 and that doesn't have the feature that allows an externals property to reference a single file (can only reference a directory) so I needed to upgrade to 1.6. Here's how you do it:

Log on as root (su)
Add this line to your /etc/apt/sources.list.
deb http://www.backports.org/debian lenny-backports main contrib non-free

Run the following commands:

apt-get update
aptitude -t lenny-backports install subversion


Wednesday, November 4, 2009

How to Build the FTDI USB Serial Driver for Linux (Debian)

(Note: Some of this information is copied - I can't take credit for it all)

To use the FTDI FT4232 (Quad USB to serial adapter) you need the latest FTDI driver and this hasn't made it's way into the Linux kernel yet.
The instructions on the FTDI website on how to build it don't work, so you must copy the driver source into a kernel source tree and build it there.

(Note: To install the pre-built driver module get the file ftdi_sio.ko and install it as described in the last section here "Install the driver:").

Download ftdi_sio.tar.gz from the FTDI web site and copy it to /usr/src/
cd /usr/src
tar xzvf ftdi_sio.tar.gz

Get the Linux kernel source (install the version to suit your kernel, type "uname -r" if not sure):
apt-get install linux-source-2.6.26
cd /usr/src
bunzip2

Copy your systems configuration to the kernel source tree:
cd /usr/src/linux-source-2.6.26
cp /boot/config-2.6.26-2-686 .config

Copy in the latest FTDI driver source:
cp /usr/src/ftdi_sio/ftdi_sio.c /usr/src/linux-source-2.6.26/drivers/usb/serial/
cp /usr/src/ftdi_sio/ftdi_sio.h /usr/src/linux-source-2.6.26/drivers/usb/serial/

Edit the driver (won't compile with 2.6.26 kernel without this change) and comment out
lines 655, 656 and 657:

.id_table = id_table_combined,
// .num_interrupt_in = 0,
// .num_bulk_in = 1,
// .num_bulk_out = 1,
.num_ports = 1,

Start building the kernel, let it run for a while and then cancel it
(you don't need to build the whole kernel):

cd /usr/src/linux-source-2.6.26
make

Now build the FTDI driver module - easiest way is to build all the modules in that directory:

cd /usr/src/linux-source-2.6.26
make -M=drivers/usb/serial

Install the driver:

cd /usr/src/linux-source-2.6.26/drivers/usb/serial
cp ftdi_sio.ko /lib/modules/2.6.26-2-686/kernel/drivers/usb/serial/
rmmod ftdi_sio
modprobe ftdi_sio

Edit /etc/modules and add "ftdi_sio" as the last line (to make sure that ftdi_sio is loaded on startup).

Connect the FT4232 and check that you now have /dev/ttyUSB0 to /dev/ttyUSB3.
If you don't type 'dmesg' to look at the log to see what happened.
Use 'lsusb' to see detected USB devices.
(Note: With the old FTDI driver the FT4232 will connect and be recognised as a FT4232,
but the virtual serial ports won't appear).

Tuesday, November 3, 2009

USB cables

I have just finished designing a board that uses the FTDI quad serial port USB chip. This board is designed to be mounted inside a PC case, so doesn't have a standard USB connector on it and instead has a 4 pin socket that accepts a crimp header style connector. The board worked fine when connected to my Windows PC, but when I installed it inside a PC running Linux it had problems. Everything seemed fine until I started using the USB serial ports - they would work fine at first, but then report errors and eventually the USB device would be disconnected and the 4 serial ports (/dev/ttyUSB0 to 3) would disappear.
The sort of errors appearing in /var/log/syslog were:

Nov 3 13:49:23 minibox2 kernel: [ 1787.820556] usb 5-8: USB disconnect, address 5
Nov 3 13:49:23 minibox2 kernel: [ 1787.820556] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
Nov 3 13:49:23 minibox2 kernel: [ 1787.820556] ftdi_sio 5-8:1.0: device disconnected
Nov 3 13:49:23 minibox2 kernel: [ 1787.820556] ftdi_sio 5-8:1.1: device disconnected
Nov 3 13:49:23 minibox2 kernel: [ 1787.820556] ftdi_sio 5-8:1.2: device disconnected
Nov 3 13:49:23 minibox2 kernel: [ 1787.820556] ftdi_sio ttyUSB3: FTDI USB Serial Device converter now disconnected from ttyUSB3
Nov 3 13:49:23 minibox2 kernel: [ 1787.820556] ftdi_sio 5-8:1.3: device disconnected

and

Nov 3 15:37:42 minibox2 kernel: [ 132.047082] hub 5-0:1.0: port 8 disabled by hub (EMI?), re-enabling...
Nov 3 15:37:42 minibox2 kernel: [ 132.047082] usb 5-8: USB disconnect, address 5
Nov 3 15:37:42 minibox2 kernel: [ 132.051081] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
Nov 3 15:37:42 minibox2 kernel: [ 132.051081] ftdi_sio 5-8:1.0: device disconnected
Nov 3 15:37:42 minibox2 kernel: [ 132.051081] ftdi_sio 5-8:1.1: device disconnected
Nov 3 15:37:42 minibox2 kernel: [ 132.051081] ftdi_sio 5-8:1.2: device disconnected
Nov 3 15:37:42 minibox2 kernel: [ 132.051081] ftdi_sio ttyUSB3: FTDI USB Serial Device converter now disconnected from ttyUSB3
Nov 3 15:37:42 minibox2 kernel: [ 132.051081] ftdi_sio 5-8:1.3: device disconnected
Nov 3 15:37:42 minibox2 kernel: [ 132.293491] ehci_hcd 0000:00:1d.7: port 8 reset error -110
Nov 3 15:37:42 minibox2 kernel: [ 132.293491] hub 5-0:1.0: hub_port_status failed (err = -32)
Nov 3 15:37:42 minibox2 kernel: [ 132.656542] hub 5-0:1.0: unable to enumerate USB device on port 8
Nov 3 15:38:02 minibox2 kernel: [ 165.111640] ftdi_sio: error from flowcontrol urb
Nov 3 15:38:02 minibox2 kernel: [ 165.111658] ftdi_sio: update_mctrl Error from MODEM_CTRL urb: DTR LOW, RTS LOW
Nov 3 15:38:02 minibox2 kernel: [ 165.111834] ftdi_sio ttyUSB1: FTDI USB Serial Device converter now disconnected from ttyUSB1
Nov 3 15:38:28 minibox2 kernel: [ 203.066197] ftdi_sio ttyUSB2: FTDI USB Serial Device converter now disconnected from ttyUSB2

I first suspected the driver (I didn't spot the "port 8 disabled by hub (EMI?), re-enabling..." messages at first) and tried rebuilding it with no luck. Eventually I realised that it was the cable that I had connecting the USB on my board to the USB header on the PC motherboard. I had made up a cable just using 4 pieces of hookup wire - not such a good idea with the speed of USB - so I suspect that the USB connection to my board was getting excessive noise and errors. All I had to do to fix the problem initially was to twist the D+ and D- wires together - that was enough to improve it and get it working! I recommend, however, using a shielded cable (as recommended by the USB 2.0 standard).