Thursday, December 3, 2009

Run Debian Linux in VMware with no desktop

I use Linux a lot and used to run my main Linux machine on an ancient 500MHz Pentium, but I now use VMware on my Windows XP machine. I mostly run the gEDA tools an eclipse on Linux and I find it a nuisance switching between VMware and Windows so I run Xming (good free Xserver for Windows) and start an xterm with the Windows PC as the X display, then run everything from there. That way all my Linux windows are still just normal windows and I can mouse between them easily.
It seemed pointless having the Gnome desktop when I never use it, and I am already logged on to my PC so I have set it up to automatically log me on and start up an xterm.

Note: Some of the commands below need to be run as root.

1. First get rid of nome and gdm.
su
apt-get remove gdm
- reboot
su
apt-get autoremove
exit

2. Set up X to run an xterm automatically.
Create the file ~/.xsession and add the following line to it:
exec xterm -display 10.1.1.3:.0.0
where 10.1.1.3 is the IP address of your Windows PC that you run VMware from.
Note: You can run any GUI program from here, most will take an argument of --display.

3. Set up your login to run X-windows automatically and shutdown linux when you exit.
Edit ~/.bashrc and add the following to the end (see http://it.dennyhalim.com/2008/10/linux-automatic-login-startx-and.html):
if [ $(tty) == "/dev/tty1" ]; then
 startx
 /sbin/halt
fi
4. Set up halt so that anyone can run it.
su chmod +s /sbin/halt

5. Configure your Linux startup to automatically log you on:
suapt-get install mingetty
Edit /etc/inittab, remove the /sbin/getty line for tty1 and add in its place:

exec /sbin/mingetty --autologin replacewithyourusername tty1

Now when you start Linux it will automatically log you on and an xterm will pop up on your Windows desktop.

(Note: I am now using VirtualBox with the guest additions which works
nicely on Windows 7. It won't grab the mouse and you can even cut and
paste between Windows and Linux.)

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).

Tuesday, August 25, 2009

Delphi modal form not closing

I just spent a frustrating afternoon trying to fix a problem in someone else's code written in Delphi 5 (I know it's ancient, but there are good reasons why it hasn't been upgraded).
I had a modal form that was displayed using ShowModal and when a comms error occured I set ModalResult to mrAbort expecting the form to close, but it wouldn't.
The form uses a serial port component (see http://comport.sf.net/ ) and has an OnRxChar callback on the serial port component set up to process characters. The OnRxChar callback is set to a method of the modal form. It turns out that the window won't close until you "unhook" the callback so I had to do the following to get it to close :

// Close the form when an error occurs
procedure TGetFilesForm.Stop;
begin
// Must get rid of the rx callback, otherwise
// the form won't close
if _comport <> nil then
_comport.OnRxChar := nil;
ModalResult := mrAbort;
end;

Wednesday, August 12, 2009

Convert Postscript to PDF

To get my gschem circuit schematics in PDF I print them from gschem to a Postscript file and then convert the Postscript file to PDF using gs, as follows:
gs -q -dSAFER -dNOPAUSE -dBATCH -sOutputFile=circuit.pdf -sDEVICE=pdfwrite -f circuit.ps

Export gEDA PCB layout to DXF

I am using gEDA PCB to layout a circuit board and needed to export the layout to a DXF file so that the mechanical designer can check it against the plastic housing design. Here's what you do:
1. Export the layout form PCB to Postscript- tick the "multiple files" box so that each page is a separate Postscript file
2. Merge the Postscript files with the outline and assembly with psmerge - "psmerge -opcb.ps pcb.outline.ps pcb.frontassembly.ps"
3. Convert the Postscript file to DXF with pstoedit - "pstoedit -f dxf pcb.ps pcb.dxf"

I usually print out the Postscript file to check the footprints I am using against the actual parts I am using. Note that this does not work if you convert the Postscript files to PDF - you seem to then have a file that does not print out to scale.

Wednesday, August 5, 2009

Blogging as a personal notebook

I thought I might try this new-fangled blogging thing to see if it is a good way to keep track of useful bits of information, particularly related to my work.
I work with Embedded Systems (electronics and software) so I am continuously finding out new bits of information on hardware or software that I will want to remember some day.