Using Many PC/104 Serial Ports

PC/104 is a small form factor standard for embedded applications. PC/104 CPU's based on the PC architecture can run many standard and embedded operating systems including Linux. Recently, a number of groups at JLab have become interested in using PC/104 for controls applications. This interest is in part generated by the recent porting of EPICS IOC software to Linux. (See EPICS: A Retrospective on Porting iocCore to Multiple Operating Systems for more information) Discussions at the lab about PC/104 use are carried out on the PC104 mailing list.

Hall B has implimented EPICS on a PC104 to interface to the RS232 port of a NMR chasis. Arne Freyberger of Hall B maintains a website with information about PC/104 and has prepared a HOWTO on installing EPICS on a PC/104 CPU board.

Lawrence Wiencke, an astronomer at the University of Utah, has a set of very detailed notes on setting up a PC104 system with many serial ports.

Hall C PC/104 Application

Hall C is planning on running EPICS on PC/104, also as an interface to RS232 devices. The first application is to replace a VME crate and CPU that are used as an EPICS interface to the PLC that controls the G0 superconducting magnet. Replacing this VME hardware will free up some tightly packed rack space and also make about 5K$ worth of VME free for other uses.

In addition to interfacing the the PLC, we plan to use the same PC/104 system to interfaces to the RS232 ports of several temperature controllers. These temperature controllers are presently being controlled through a Win2K PC, but there is a desire to move the operation of these controllers to a more "embedded" device.

The TS-5300 was chosen as the CPU board. This board comes with a 133 MHz AMD Elan 520, 16 MB of memory (I recommend more, but 16 MB will work fine for many applications) and a Compact Flash slot. A 128 MB CF card is being used in this slot. There is a wide variety of PC104 CPU boards that would work well, but the TS-5300 was chosen because others at the lab have some experience with it and because the vendor has some online Linux Support.

PC104-1800 As the Hall C application requires a large number of seriel ports, we purchased a pair of Nagasaki PC104-1800 4 port RS232 cards from BWI. The PC104-1800 boards did not come with any documentation, but the board appears to be identical to the Technoland TL-PC104 RS23201 for which documentation is available online.

Installing Linux

As with any PC, there are a seemingly infinite number of ways to load linux onto the PC104 CPU board. The TS-5300 comes with a couple of MB of onboard flash disk. This flash is preloaded with DOS along with loadlin and a kernel that could be used to boot an NFS mounted Linux system. In our case we chose to use a desktop PC to write a system to a Compact Flash (CF) card with a USB-CF adapter. The Technologic Linux Support page has prebuilt CF disk images that are based on Linux From Scratch. These CF disk images are available for a variety CF sizes, but not for the 128MB CF cards that we have.

To put a prebuilt linux on the CF card, first use dd to write the uncompressed image to the card. (E.g. dd if=TS-3.02-16.cf of=/dev/sda bs=8192 assuming the the CF card is known as /dev/sda). This puts two partitions on the CF card, the first a dos partition, the second an ext2 partition. Since most of the card is unused, GNU Parted can be used to strech out the second partition to fully use the CF card. Note: After writing to the disk with dd, and after resizing the partion with parted, it is a good idea to remove and reinsert the CF cards from the CF-USB adapter so that Linux can redetect the partition table.

At this point the ext2 partition can be mounted on the desktop machine so that the network parameters in /etc/sysconfig can be edited so suit.

Installing other linux software

The proper way to add linux applications that are missing from the TS-3.x linux distribution is to probably to follow the instructions on Linux From Scratch. However, many system binaries from RH7.2 can just be copied to the PC104 system and will work fine. If shared libraries are missing they can be copied from /lib or /usr/lib. This probably won't work so well for C++ programs.

Patching kernel Linux

Download the 2.4.18 kernel. Get patches from TSlinux 2.2 part of technologic page. Patch kernel. Optionally replace ".config" with this copy of .config. run "make xconfig". Turn on serial options for IRQ sharing, many ports and multiport. (CONFIG_SERIAL_EXTENDED, CONFIG_SERIAL_MANY_PORTS, CONFIG_SERIAL_SHARE_IRQ, CONFIG_SERIAL_MULTIPORT) Suggest some things to turn off, such as root nfs, floating point emulation, .... Also NFS can be made a module, since NFS won't be used for production, but is nice to have around. "make dep" "make bzImage ; make modules; make modules_install". (Make sure that the kernel version that your host system is running is not exacatly "2.4.18", or else you will overwrite the modules for your system you are running. If "uname -r" shows something like "2.4.18-x", then that is different enough.)

PC104-1800

Loading new kernel

Mount the dos (first) partition from the CF card. Get "bzImage" from arch/i386/boot and put it in "X", calling it somthing like "bzjlab".

Edit "syslinux.cfg" to make the new kernel an option or the default.

Mount the linux (second) partition and copy the kernel modules to the CF card. (lib/modules/2.4.18).

Configuring card and using set serial

A bit about jumpers.

Get setserial from a RH7.2 machine, put in /usr/local/bin. Configure the ports with something like this rc.serial script which should be setup to run at boot time.

Cable notes

The pinouts for the Nagasaki RS232 connectors are the same as what is used on PC AT motherboards. So cables from old PC's can be scrounged and used. Note the pinouts on the TS-5300's serial ports is not this PC standard. We bought a TS-5300 development kit that came with a couple of serial cables (board connector to D-9). These cables of course work fine with the TS-5300, but caused quite a bit of confusion when an attempt was made to use them on the Nagasaki PC104-1800.

Sample code

Will have some sample code that talks to the LakeShore 218 Temperature Monitor. Will show how to set TTY attributes and run interface in non-blocking mode.

Vern Hoxie's Linux Serial-Programming-HOWTO contains documentation and examples of how to do serial device programming.

NFS

The TS-5300 linux distribution has NFS client software. However, the mount command will take about 5 minutes to complete. This is because the rpc portmapper is not running or included. To speed up mounting, copy /sbin/portmap from a RH7.2 system. Start the portmapper before doing any nfs mounts. If memory is tight, the the portmapper daemon may be killed after the nfs mounts are made without any apparant problems.

If the kernel is built with nfs as a module, then the modules sunrpc, lockd, and nfs need to be loaded before using nfs.


Last update July 25, 2003
Stephen A. Wood