Вы находитесь на странице: 1из 5

won’t describe every chip, but I will

FEATURE present advantages and disadvantages


of some popular chips.

ARTICLE USB, IN BRIEF


USB is suitable for nearly any appli-
Jan Axelson cation that needs a slow to moderate-
speed connection to a host CPU with
USB support. This article will concen-
trate on Windows 98 and 2000 hosts,
but a host can be any computer with
host-controller hardware and operat-

USB Chip Choices ing system support. USB peripherals


include standard devices like key-
boards, mice, and printers, as well as
test instruments, control systems, and
Finding a Peripheral Controller other small-volume or custom designs.
Video and other high-speed applica-
tions will most likely use IEEE-1394/
Firewire.
One goal of USB is freeing users

Today, most periph-


i f you’re design-
ing a device that
will connect to a PC or
Mac, you’ll probably use
from technical and logistical hassles.
There’s no need to assign IRQs or port
addresses. Inexpensive hubs make it
easy to add peripherals without hav-
ing to open the box and find a slot.
a universal serial bus (USB). You may There’s only one interface. And the
eral devices are de- have noticed that the ports that served interface can provide up to 500 mA at
PCs for 20 years are disappearing. USB a nominal 5 V, so many peripherals no
signed with USB was designed from the ground up to longer need a wall wart or AC power
replace a variety of legacy ports with a cord for an internal supply.
connections. Design- single interface that’s flexible and easy The host controls the bus and
to use. keeps track of which devices are at-
ing USB peripherals But simplicity for end users has a tached. It also ensures each data trans-
pricethe interface is more compli- fer gets a fair share of the time. Inside
can get tricky, but cated than the single-purpose ports it the peripheral, the controller hard-
replaces. To manage the complexity, ware and embedded code respond to
choosing the right every USB peripheral must contain an transmissions from the host.
intelligent controller that knows how USB is the product of a consortium
chip can make a to respond to the requests defined by that includes Intel, Microsoft, and
the specification. The good news for other companies. The organization,
world of difference. developers is that there are plenty of the USB Implementers Forum, spon-
choices for controllers. sors a web site (www.usb.org) that has
Jan knows her USB, This article will help you find the the specification documents and tools
USB controller that gives the best for both developers and end users.
so you might want to performance. I’ll start with a quick
tour of USB and a review of the respon- HOST COMMUNICATIONS
choose to listen up. sibilities of USB peripherals. Then, I’ll Even if you’re designing only the
discuss how to narrow the choices. I peripheral side, it’s helpful to know

www.circuitcellar.com CIRCUIT CELLAR® Issue 120 July 2000 1


how the host communicates. Windows (maximum time between transactions)
Applications
uses a layered driver model for USB of 1 to 255 ms.
User
Win32 API calls
communications. Each driver layer mode Bulk transfers are useful for applica-
handles a portion of the communica- Win32 sub-system tions that need to transfer large
tion (see Figure 1). I/O request packets amounts of data when delivery time
Applications communicate with isn’t critical, such as printing and scan-
Hardware device drivers
device drivers (including class drivers) ning. A bulk transfer can send blocks
Kernel
that communicate with the system’s I/O request packets up to 64 KB, but without guaranteed
mode
bus drivers, which access the USB Bus drivers delivery time.
hardware. Windows includes bus driv- Hardware-specific interface
Isochronous transfers are used
ers and some class drivers. when delivery rate is critical and
Hardware
For Windows, a device driver for a errors can be tolerated, such as audio
USB device must conform to Win32 Figure 1—USB communications use a layered driver to be played in real time. An isochro-
Driver Model (WDM). A WDM driver, model in Windows 98 and 2000. Each layer handles a nous transfer can send up to 1023 Bpms
supported by Windows 98 and 2000, is portion of the communications. Bus drivers and some with a guaranteed attempt to send a
class/device drivers are provided with Windows.
an NT kernel-mode driver with power block of data every millisecond. Un-
management and plug-and-play. error-checking information. Any pe- like the other transfers, isochronous
A device may have its own driver, ripheral may have to share bus time transfers have no handshake packet
or use a generic class driver that with other peripherals, although a that enables the receiver to notify the
handles communications with any device can request guaranteed delivery sender of errors detected within data
hardware that conforms to a class rate or maximum latency between that is received.
specification. Windows adds class transactions. Low-speed transfers are USB transfers consist of one or
drivers with each release (see Table 1). limited to a fraction of the bus time more transactions. Each transaction,
If your device isn’t in a supported so that they don’t clog the bus. in turn, contains identifying informa-
class, you must provide a driver. To make the bus practical for de- tion, data, and error-checking bits.
How does Windows decide which vices with different needs, the specifi- Inside the device, all USB data
driver to use with a device? Every cation defines four transfer types: travels to or from an endpoint, which
device stores a series of data struc- control, interrupt, bulk, and isochro- is a buffer that stores data to be sent
tures called descriptors. Every Win- nous (see Table 2). or received. A single device can have
dows system has a variety of INF Control transfers are the only up to 16 endpoint numbers (0–15). An
files, which are text files that match transfers that every device must sup- endpoint address is the endpoint num-
drivers with class codes or vendor and port. Enumeration uses control trans- ber plus its direction: in (device-to-
product IDs stored in the descriptors. fers. With each, the host sends a host) or out (host-to-device). Every
When the files detect an attached request. The specification defines re- device must support endpoint 0 in and
device, the host performs an enumera- quests that devices must respond to, out for control transfers and may
tion process that requests the descrip- and a class or individual device driver support up to 30 additional endpoints.
tors. All devices must know how to may define extra requests. Most controllers support fewer
respond to the enumeration requests. Along with each control request, than the maximum number of end-
The host compares the information in the host sends a 2-byte value and a 2- points and some don’t support all of
the descriptors with the information byte index, which the request can the transfer types. Low-speed control-
stored in the system’s INF files and define in any way. Depending on the lers are limited to using control and
selects the best match. Some products request, either the host or device may interrupt transfers. Cypress Semi-
provide their own INF files, others send data. The receiver returns an conductor’s EZ-USB is one chip that
use files provided with Windows. acknowledgement. However, there is supports the maximum number of
no data stage with some requests, and endpoints (one bidirectional control
TRANSFERS the device returns an acknowledge- endpoint plus 30 additional endpoints)
USB 1.1 supports two speeds. Full ment after receiving the request. and all four transfer types.
speed is 12 Mbps. Low speed, which is The other transfers don’t use de- The host controls the bus and ini-
intended for inexpensive devices and fined requests. They transfer blocks of tiates transfers. But, a device in the
devices that need flexible cables, is data and identify and error-check low-power suspend state can use the
1.5 Mbps. The latest release, version information to or from a device. remote wake-up feature to request a
2.0, supports 480 Mbps, but requires Interrupt transfers are useful for transfer. And a device can request the
new hardware in the host, peripheral, applications that need to send small host to send or request periodic inter-
and any hubs between. amounts of data at intervals, such as rupt or isochronous data.
A single peripheral’s data transfer keyboards, pointing devices, and other
rate is less than the bus rate and not monitoring and control circuits. A ELEMENTS OF A USB CONTROLLER
always predictable. The bus must also transfer can send blocks of up to 64 A USB peripheral controller has
carry addressing, status, control, and bytes with a guaranteed latency several responsibilities. It must pro-

2 Issue 120 July 2000 CIRCUIT CELLAR® www.circuitcellar.com


USB to any microcontroller with a
Windows edition USB device drivers added
data bus. The external CPU manages
Windows 98 Gold (original) audio HID 1.0 (includes keyboard and pointing devices) non-USB tasks and communicates with
Windows 98 SE (second edition) HID 1.1 communications (modem) still image capture the USB controller as needed.
(scanner, camera), (first phase/preliminary) For applications that require fast
Windows 2000 mass storage printer performance, another option is to
Windows 98 Millennium design an application-specific inte-
Table 1—Each release of Windows added drivers for new classes of USB devices. If your device fits into one of the grated circuit (ASIC). Components are
supported classes, you don’t need to write a driver for it. available as synthesizing VHDL and
Verilog source code.
vide a physical interface to the bus and a scanner controller with a USB inter- Cypress has several chips that
detect and respond to requests and face. Dallas Semiconductor’s DS2490 contain a CPU developed specifically
other events at the USB port. And it is a USB-to-1–wire bridge. for USB applications. The M8 family
provides a way for an internal or exter- includes the CY7C6xxx series of inex-
nal CPU to store data that it wants to SIMPLIFYING THE PROCESS pensive chips, each with two to four
send and retrieve. Aside from the chip’s features, easy endpoints, 12 to 32 general-purpose I/
Controller chips vary by how much development affects how long it takes O lines, and 2 to 8 KB of program
firmware support they require for to get a project running. The simplest memory. Note that the program
these operations. Some, such as and quickest USB project meets the memory is one-time programmable
NetChip’s NET2888, require little following criteria. First, you must be (OTP) EPROM.
more than accessing a series of regis- familiar with the project’s chip archi- The instruction set is short (35
ters to configure the chip and store tecture and programming language. instructions), so learning it isn’t diffi-
and retrieve bus data. Others, such as Second, the project has a development cult. However, this also means you
Cypress’ M8 series, require routines system that enables easy firmware won’t find detailed instructions that
to manage data transfers and ensure downloading and debugging. Third, it do most of the work for you. For ex-
that the appropriate handshaking in- has detailed, well-organized hardware ample, there are no instructions for
formation is exchanged. documentation. Fourth, there is well- multiplying or dividing; calculations
Some chips use registers, and others documented, bug-free sample firmware must be done by adding, subtracting,
reserve a portion of data memory for for an application similar to your and bit shifting (Cypress offers a C
transmit and receive buffers. project. And fifth, it can communicate compiler from Byte Craft with exten-
For faster transfers, Philips using device drivers included with sive math functions).
Semiconductor’s PDIUSBD12 has Windows or another well-documented For 8051 users, Cypress’ EZ-USB
double buffers that store two full sets driver that you can use with minimal has an architecture similar to Dallas
of data in each direction. While one modification. Semiconductor’s 80C320. Two other
block of data is transmitting, the These are not trivial consider- early 8051 compatibles were Intel’s
firmware can write the next block of ations. The correct choice will save 8x930 and 8x931. Intel stopped manu-
data into the other buffer so it’s ready many hours and much aggravation. facturing both of these this year but
when the first block finishes trans- licensed the technology to Cypress.
mitting. In the receive direction, the ARCHITECTURE CHOICES If you have 8051 experience, espe-
extra buffer enables a new tran- Some USB controllers contain a cially if you’re designing a USB-ca-
saction’s data to arrive before the general-purpose CPU, and others have pable version of an existing 8051
firmware finishes processing data a serial or parallel interface that must product, sticking with the 8051
received in the previous transaction. connect to an external CPU. makes sense. Even if you’re not famil-
In both cases, the hardware automati- A chip with a general-purpose CPU iar with the architecture, its popular-
cally switches between the buffers. may be based on an existing family ity means that programming and
A controller likely will have an such as the 8051, or may be designed debugging tools are available, and
interface other than the USB port to specifically for USB applications. you’re likely to find sample code and
the outside world. In addition to gen- Controllers that interface with an advice from other users on the
eral-purpose I/O pins, a chip may external CPU provide a way to add Internet. Keil has C compilers for the
support other serial interfaces, such as
Low Guaranteed Guaranteed
an asynchronous interface for RS-232
Transfer speed Error delivery maximum
or synchronous interfaces, such as I2C type Required OK correction rate latency Typical use
or Microwire.
Some chips include special inter- control Y Y Y N N enumeration
bulk N N Y N N printer
faces. For example, Philips’ USA1321
interrupt N Y Y N Y mouse
contains a digital-to-analog converter isochronous N N N Y Y audio
(DAC) for USB speakers and other
audio devices. NetChip’s NET1031 is Table 2—The USB’s four transfer types are designed to meet different application needs.

www.circuitcellar.com CIRCUIT CELLAR® Issue 120 July 2000 3


8x930/1, and both Keil and data on the bus is encoded,
Tasking have a C compiler for conventional oscilloscopes and
the EZ-USB. logic analyzers aren’t helpful
Other examples of families for viewing USB data. A proto-
with USB-capable chips are col analyzer captures the data,
Mitsubishi’s 740, 7600, and then filters and displays it in a
M16C, Motorola’s HC05, and variety of formats. PC-based
Microchip’s PIC16C7x5. analyzers may connect to an
Controllers that interface to Ethernet port or an ISA card.
external CPUs typically use a Other analyzers are designed as
parallel or synchronous serial attachments to logic analyzers.
interface. An interrupt pin sig-
nals the CPU when the control- PROJECT NEEDS
ler receives USB data or is ready In addition to looking for a
for new data to send. This Photo 1—Cypress Semiconductor’s M8 Monitor program enables you to chip that will be easy to work
works if you want to use a CPU control program execution, and view and change memory and registers. with, narrow the choices by
that doesn’t have a USB-capable specifying your project’s re-
variant. for the data it will exchange. The re- quirements and looking for chips that
Philips’ PDIUSBD11 has an I2C port format tells the host the size and can meet them. Here are some ques-
interface that uses three pins, a clock quantity of the report data, and also tions to consider.
input, bidirectional data, and an inter- may provide units and other informa- How fast does the data need to
rupt output. The maximum clock tion to help the host interpret the data. transfer? The rate of data transfer de-
frequency of the chip’s I2C bus is 100 The mass-storage driver introduced pends on several things: whether the
kHz, so it doesn’t handle high-volume with Windows 2000 is an option for device is low- or full-speed, how busy
transfers. In contrast, the PDIUSBD12 devices that need to transfer a lot of the bus is, and the transfer type. As a
has a multiplexed parallel bus that can data but don’t have critical timing peripheral designer, you don’t control
transfer up to 1 Mbps. requirements. how busy a user’s bus will be, but you
National Semiconductor’s For custom drivers that use bulk or can design your product to work in a
USBN9602 can be configured to trans- isochronous transfers, start with the worst-case scenario.
fer multiplexed or non-multiplexed bulkusb.sys and isousb.sys ex- If a product requires only occasional
parallel data or Microwire serial data. amples in the Windows 2000 DDK. If interrupt and control transfers, a low-
you use these, search the Developers speed chip may save money. But, the
DRIVER CHOICES Webboard at www.usb.org for tips and fastest configuration for a low-speed
The other side of programming a bug fixes. interrupt endpoint is 8 bytes per trans-
USB device is the device driver and action with a maximum latency of 10
application software on the host. You DEBUGGING TOOLS ms between transactions, which is 800
can use a device driver included with Most chip vendors offer a develop- Bps.
Windows, use or adapt a driver from ment board and basic debugging soft- How many and what type of end-
another source, or write your own. ware to make development easier. The points do you need? Each endpoint is
The human interface device, known development board enables you to configured to support a transfer and
as HID, drivers included with Win- load a program from a PC to the chip’s direction. Although the host can re-
dows 98 and 2000 are an option for program memory, or to circuits that quest a new configuration or interface
general-purpose applications up to 64 emulate the chip’s hardware. to use a different transfer for each, in
KBps. HIDs can use control and inter- Typical debugging software uses a most cases each transfer type and di-
rupt transfers. monitor program, which enables you rection will have its own endpoint.
The classic HID examples are the to control program execution and What about firmware upgrades? For
keyboard and mouse, when a human’s watch the results (see Photo 1). You program memory, many USB devices
actions cause data to be sent to the can step through a program line by use EPROM, in which changing the
host. But, a HID doesn’t need a human line, set breakpoints, and view the firmware requires removing the chip.
interface, it can include test instru- contents of the chip’s registers and The EZ-USB supports an easier way,
ments, control circuits, and other de- memory. And, you can run the monitor using a re-enumeration process that
vices that operate within the limits of program and a test application at the loads the program code into the chip
the class specification. same time. Look inside the emulated from the host on each power-up. If you
Applications access HIDs using the chip to view registers and memory expect firmware changes, the EZ-USB
API functions ReadFile and contents as your application communi- is difficult to beat.
WriteFile. The device’s firmware cates with it. Do you need a flexible cable? One
must include the HID class code in its Another useful debugging tool is a reason why most mice are low-speed
descriptors and define a report format USB protocol analyzer. Because the devices is that the less stringent re-

4 Issue 120 July 2000 CIRCUIT CELLAR® www.circuitcellar.com


quirements for a low-speed cable mean www.dalsemi.com
that the cable can be thinner and more
flexible. Keil Software
Need a long cable? Low-speed (800) 348-8051
cables are limited to 3 meters, and full- (972) 312-1107
speed cables can be 5 meters. Full- Fax: (972) 312-1159
speed cables have shielded, twisted www.keil.com
pairs. Hubs can stretch a connection Microchip Technology, Inc.
beyond these limits. The limit is five (888) 628-6247
hubs plus the host, each with a 5-meter (480) 786-7200
cable, for a maximum distance of 30 Fax: (480) 899-9210
meters. Active extension cables that www.microchip.com
contain embedded hubs are available.
What other hardware features and Mitsubishi Electronics
abilities are needed? The list includes (408) 730-5900
everything from general-purpose I/O Fax: (408) 730-4972
to on-chip timers. The requirements www.mitsubishichips.com
depend on the application. Motorola
The answers to these should nar- (512) 328-2268
row your search, making your chip Fax: (512) 891-4465
choices and the development as pain- www.mot-sps.com/sps/general/
less as possible. I chips-nav.html

This article is adapted from mate- National Semiconductor


rial in USB Complete: Everything You (408) 721-5000
Need to Develop Custom USB Periph- Fax: (408) 739-9803
erals by Jan Axelson. www.national.com

NetChip Technology, Inc.


Jan Axelson has worked with elec-
(650) 526-1490
tronics and computers for 25 years.
Fax: (650) 526-1494
Jan’s web site (www.lvr.com) has
www.netchip.com
resources for developers using USB
and legacy ports. You may reach her Philips Semiconductor
at jan@lvr.com. (408) 991-5207
Fax: (408) 991-3773
www.semiconductors.philips.com
REFERENCES
USB Central, links for USB devel-
opers, www.lvr.com/usb.htm.
USB Designer Links, links to USB
controller chips,
www.ibhdoran.com/
usb_link.html.
USB Implementers Forum, the
specification documents,
Developer’s Webboard, and
more, www.usb.org.

SOURCES
USB Chips
Cypress Semiconductor
(408) 943-2600
Fax: (408) 943-6848
www.cypress.com
Circuit Cellar, the Magazine for Computer Applica-
Dallas Semiconductor tions. Reprinted by permission. For subscription
(972) 371-4448 information, call (860) 875-2199,
subscribe@circuitcellar.com or
Fax: (972) 371-3715
www.circuitcellar.com/subscribe.htm.

www.circuitcellar.com CIRCUIT CELLAR® Issue 120 July 2000 5

Вам также может понравиться