U Pci S L: Sing Erial With Inux
U Pci S L: Sing Erial With Inux
This document assumes that you are already familiar with Linux.
Contents
Related Documentation........................................................................... 2
Contributions ................................................................................... 2
Gather What You Need to Get Started.................................................... 2
Quick Start .............................................................................................. 4
Setup........................................................................................................ 5
Create Devices ................................................................................. 5
MAKEDEV Example ............................................................... 5
Find Interface Information............................................................... 5
Assign Serial Driver......................................................................... 6
setserial Example ...................................................................... 7
Assign Serial Drivers Using PCI-485....................................... 7
Assign Serial Drivers Using PCI Eight-Port Interfaces............ 7
Enable PCI Interrupt ........................................................................ 7
Configuration .......................................................................................... 8
View Your Hardware Resources ..................................................... 8
Enable FIFO Buffers........................................................................ 8
FIFO Example .......................................................................... 9
Configure struct termios .................................................................. 9
Configure PCI-485 .................................................................................. 10
Select Transceiver Mode ................................................................. 10
rs485 Example .......................................................................... 10
Lower Baud Rate Selection ............................................................. 10
Test the Setup.......................................................................................... 11
natinst.com™, National Instruments™, and NI-Serial ™ are trademarks of National Instruments Corporation. Product and company names
mentioned herein are trademarks or trade names of their respective companies.
322539A-01 © Copyright 1999 National Instruments Corp. All rights reserved. August 1999
Troubleshooting and Common Questions ...............................................12
Error Codes.......................................................................................12
Common Questions ..........................................................................13
Assign Driver...........................................................................................15
Sample /etc/rc.d/rc.serial File ..................................................................17
Related Documentation
The following documents contain information that you might find helpful
as you read this document:
• Linux Serial-Programming-HOWTO by Peter Baumann. You can find
the latest version of this document at the following locations:
ftp://metalab.unc.edu/pub/Linux/docs/HOWTO/Serial-P
rogramming-HOWTO
http://metalab.unc.edu/LDP/HOWTO/Serial-Programming
-HOWTO.html
• Linux Serial-HOWTO by David Lawyer. You can find the latest version
of this document at the following locations:
ftp://metalab.unc.edu/pub/Linux/docs/HOWTO/Serial-H
OWTO
http://metalab.unc.edu/LDP/HOWTO/Serial-HOWTO.html
Contributions
Thanks to Vern Howie for providing suggestions and examples from his
serial suite. Also, thanks to David Lawyer, Greg Hankins, and Peter
Baumann for providing so much information in their HOWTOs.
Create Devices
Create a device for each port on your multiport interface. You only need to
do this step once. Port address is the I/O address of the device, and port
number is the device/serial port number of the port. Port number is used in
the following context: ttyS<port number>. Since serial ports built into
your computer are typically named from /dev/ttyS0 to /dev/ttyS3, the
port number you choose needs to be four or greater.
Enter the /dev directory, then use the MAKEDEV script to create a device for
each serial port on the interface by entering the following.
linux# cd /dev
linux /dev# ./MAKEDEV ttyS<port number>
MAKEDEV Example
Enter the following to make the devices for a two-port interface:
linux# cd /dev
linux /dev# ./MAKEDEV ttyS4
linux /dev# ./MAKEDEV ttyS5
Note Repeat this section each time you add another interface or physical device to the
computer.
1. Use lspci (a command that displays information about the PCI bus)
with the -v option (be verbose), the -n option (show PCI vendor and
device codes as numbers), and the -d 1093:* option (display
information only on devices with a National Instruments Vendor ID
of 1093), to find the resource information of your serial interface.
linux# lspci -v -n -d 1093:*
Something similar to the following should appear. In this output, the
IRQ is 11; the memory location is 0xdff80, and the port addresses are
0xdff0 and 0xdfe0.
Note PCI Eight-Port Users—The PCI eight-port interfaces show only one I/O port
address listing. The addresses of the other seven I/O ports are calculated by adding eight to
the previous port address, (n × 8 + I/O port) for 0 < n < 8. The lspci call displays
something similar to the following:
Note You need to repeat this step each time you restart your computer or until you set up
your /etc/rc.d/rc.serial file. (Refer to the section Sample /etc/rc.d/rc.serial File for
more information on setting up the /etc/rc.d/rc.serial file.)
Enter the following to use setserial to tell the kernel each device’s
UART, port address, and IRQ. Use information returned from the lspci
output, and remember to precede the port address with 0x.
linux# setserial /dev/ttyS<port number> uart 16550A
port <port address> irq <irq> ^fourport
Note The ^fourport flag is required regardless of how many ports you have on your
interface. The ^fourport flag tells the serial driver that you are not using an AST
four-port interface.
setserial Example
Enter the following to assign the serial driver to your devices for the values
in the above two-port lscpi output:
linux# setserial /dev/ttyS4 uart 16550A port 0xdff0 irq
11 ^fourport
For example, enter the following to assign the serial driver to /dev/ttyS4
for a PCI-485 serial port at port address 0xdfe0 and IRQ 11.
linux# setserial /dev/ttyS4 uart 16550A port 0xdfe0 irq
11 ^fourport
linux# setserial /dev/ttyS4 baud_base 460800
For example, enter the following to enable interrupts for a PCI serial
interface with memory at 0x000dff80:
linux PCI-SERIAL# ./intenable dff80
Configuration
View Your Hardware Resources
To see what system resources your serial interface is using, use the
setserial command, as follows:
linux# setserial -gv /dev/ttyS<port number>
FIFO Example
Enter the following to set the receive FIFO trigger level to 56 and the
transmit trigger level to 32 for /dev/ttyS5:
linux PCI-SERIAL# ./FIFOtrigger 5 0x80 0x20
rs485 Example
Enter the following to select Four-Wire Mode for /dev/ttyS5:
linux PCI-SERIAL# ./rs485 5 0
After you change the baud_base of the serial port using setserial and
run the clockspeed program, you can use the lower baud rate flags in
your programs. The clockspeed program changes the baud base of only
For example, enter the following to select a baud base of 115200 for
/dev/ttyS4 and for /dev/ttyS5:
linux# setserial /dev/ttyS4 baud_base 115200
linux# setserial /dev/ttyS5 baud_base 115200
linux PCI-SERIAL# ./clockspeed 4 low
linux PCI-SERIAL# ./clockspeed 5 low
Enter the following to change the baud base back to 460800 for
/dev/ttyS4 and for /dev/ttyS5:
linux# setserial /dev/ttyS4 baud_base 460800
linux# setserial /dev/ttyS5 baud_base 460800
linux PCI-SERIAL# ./clockspeed 4 high
linux PCI-SERIAL# ./clockspeed 5 high
Solution The /dev/ttyS<port number> does not exist in the /dev directory. Enter the
following to create the device:
linux# cd /dev
linux /dev# ./MAKEDEV ttyS<port number>
Error Code Couldn't change i/o privilege level: Operation not permitted
Solution The program requires superuser privileges. Either exit and log in as root, or enter
the following:
linux$ su
Password: <enter the root password>
linux# <run the program>
Error Code setserial: Cannot set serial info: Address already in use
Solution Make sure you are entering the correct port address into setserial. Also, make
sure you are entering 0x if you are specifying a hex number.
linux# setserial /dev/ttyS<port number> uart 16550a port
0x<port address> irq <irq> ^fourport
Solution The program requires superuser privileges. Either exit and log in as root, or enter
the following:
linux$ su
Password: <enter the root password>
linux# ./intenable <PCI memory>
Solution Make sure that you are providing the program with the correct memory address.
Enter the following to check for the memory address:
linux# lspci -v -n -d 1093:*
00:0a.0 Class ff00: 1093:d150 (rev 01)
Flags: medium devsel, IRQ 11
Enter this address! -->Memory at 000dff80 (low-1M,
non-prefetchable)
I/O ports at dff0
I/O ports at dfe0
I/O ports at dfa8
I/O ports at dfa0
linux# ./intenable dff80
Solution Make sure the device was configured correctly in setserial. Enter the
following:
linux# setserial -gv /dev/ttyS<port number>
/dev/ttyS4, UART: 16550A, Port: 0xdff0, IRQ: 11
If the port listing does not match the one found by lspci, reconfigure the device
by entering the following:
linux# setserial /dev/ttyS<port number> uart 16550a port
<port> irq <irq> ^fourport
Common Questions
What do I do if intenable does not work immediately or causes a
segmentation fault?
Enter the following to recompile interrupt_enable.c and rerun
intenable. Also, the source code for intenable is available for editing
and viewing at interrupt_enable.c provided in the PCI-SERIAL
directory.
linux PCI-SERIAL# gcc interrupt_enable.c -o intenable
linux PCI-SERIAL# ./intenable <PCI memory address found
in lspci>
Devices labeled with UART: unknown are available for use. To designate
the available device when using setserial, enter the following:
linux# setserial /dev/ttyS<port number> uart 16550a
port 0x<port address> irq <irq> ^fourport
Assign Driver
Use these instructions to automatically assign the driver at startup using
/etc/rc.d/rc.serial.
You should not change the /etc/rc.d/rc.serial file until you have
your serial interfaces installed and configured. If you add another device or
interface to your computer, and your lspci output changes, make sure you
also change /etc/rc.d/rc.serial.