EDN Access

 

June 19, 1997


Taming the Universal Serial Bus

Richard A Quinnell, Technical Editor

Last year, the Universal Serial Bus was an untamed technology. Now, EDN's hands-on USB project gets the bus under control.

One problem with emerging technologies is the difficulty in determining when they're ready to be harnessed. When EDN first looked at the Universal Serial Bus (USB), it was still wild and unruly (Reference 1). The technology has since settled down, and we can now accurately evaluate its performance.

The USB aims to replace the plethora of back-panel peripheral connectors on the PC with one four-wire serial bus (see box, "USB basics"). The bus allows live insertion of devices, automatically configures the PC and the device upon attachment, and can provide the device with power through the attachment cable.

The intent of the USB design is to meet the attachment needs of common PC peripherals as well as emerging still-camera and computer-integrated-telephony equipment. The bus has potential for embedded systems as well. Its ability to automatically configure and power attached devices, for example, makes USB useful for adding nonintrusive diagnostic circuits to systems. A USB-based data-acquisition circuit can provide a test port in a system without consuming any of the target system's power, computational, or communication resources.

My purpose in this hands-on project was to examine the bus's operation from the embedded-system designer's viewpoint. In particular, I was interested in the bus's achievable data rates for a data-acquisition system. The bus operates at a top speed of 12 MHz, but you cannot use all of that bandwidth for data transfer. In addition to the bus-protocol overhead, the host's processing of data-transfer requests can cause system delays.

Data moves across the USB under the host system's control. With bulk-data transfer, the host initiates the transfer by sending a command that prepares the target device to either send or receive data (Figure 1). Once the data-transfer receipt is complete, the receiver sends an acknowledgment (ACK) token to the sender to indicate that the transfer was successful. After the transaction is complete, the host prepares the next data transfer.

Host delay is key

In addition to the overhead of addresses, CRC characters, and synchronization patterns, there are delays inherent in the USB protocol. The delays between parts of a transaction allow for signal propagation and reversal of bus-driver direction. These delays have upper limits that the USB specification imposes (Reference 2). Following a transaction, another delay allows the host system to determine and prepare for the next transaction. The specification does not limit host delay. It was this host delay that I wanted to investigate. My attempt last year to make such measurements ran into software problems.

USB's theoretical data rate comes from the following formula:

Transaction time (nsec)= 9107+(83.34·Floor(3.167+BitStuff·(512)))+Host_Delay,

which describes the duration of one bulk-data transfer of 64 bytes. The BitStuff factor is data-dependent. USB's NRZ-invert signaling scheme demands the insertion of a dummy zero bit after six successive data ones to permit reliable clock recovery. The worst-case factor for BitStuff is 1.1667 (1 stuff bit for every 6 data bits), but a value of 1.008 is a more likely average value.

The formula accounts for most of the delays in Figure 1, using the maximum values that the USB specification defines. The factor Host_Delay, however, is system-dependent. A minimum host delay allows the USB to handle bulk-data-transfer rates as high as 1.2 Mbytes/sec. The goal of this hands-on project was to see how close to ideal the bus really operates by estimating the host's delays.

Having a specific goal is only part of the exploration process. Like any expedition, my attempt to explore the USB needed the right equipment. My previous foray into the USB jungle proved that hardware and software must have compatible revision levels and work well together.

USB development

You can choose from a lot of development equipment (Table 1). A variety of USB microcontrollers are available, including some implemented in programmable logic, on which to base a design. Software-development and hardware-debugging tools also abound.

For this project, I elected to stay with the Intel 82930 USB microcontroller development board and Production Language Corp (PLC) Compass/251 software-de-velopment tool that I used in the first project. I stayed with these earlier choices mainly to avoid the learning curve for new equipment. I had to upgrade both of them, however, to capture the changes and improvements of the last eight months. The development board now used a daughtercard to update the USB processor to the latest version, the 82930AXD4. The onboard ROM monitor program had updated to version B2-2.1. As a result of these hardware changes, I had to upgrade the PLC software to version 3.07.

Host equipment has become more widely available since the last project. At that time, only two USB-enabled PC families were in production. By the beginning of 1997, however, more than 75% of new PCs carried USB ports and contained versions of Windows 95 that provided bus support. I picked a host based on who was first to volunteer a loaner PC, ending up with a Digital Equipment Venturis GL 6200.

The version of Windows 95 that comes preinstalled on new computer systems, version 4.000.950B, is part of Microsoft's OEM Service Release 2.1, code-named "Detroit." Although it contains USB support, this version does not have all the class drivers for devices such as keyboards and mice that later versions of Windows will offer. These drivers, as well as refinements to the USB host software, are available through Microsoft's developer's programs in prebeta versions of Windows 9x, code-named "Memphis." Atten- dees of the Windows Hardware Engineering Conference (WinHEC) received trial copies of Memphis.

Host-system software in flux

I chose to start this project using Detroit, the released and widely distributed version of Windows 95 that supports USB. Although missing many class drivers, Detroit's host-controller software is complete and functioning and works with USB devices that have their own device drivers. My project needed its own drivers anyway, so Detroit would work just as well as later versions and would represent what new bus users would have available for their own efforts. The next release version of Windows with USB support will not be available until 1998.

For test equipment, I chose to use the FuturePlus USB preprocessor and Hewlett-Packard 65500 logic analyzer. This combination of devices would allow me to monitor and interpret bus traffic. It also would provide detailed timing information, which I needed for my analysis.

The final items I would need for my project were the tools for developing the device drivers that would tell the host system how to communicate with my USB peripheral. Device drivers for Windows 95 are similar to drivers for Windows NT, and the driver-development tools run under Windows NT. Therefore, I needed a Windows NT system.

Creating a device driver for Windows NT requires several tools. Microsoft has a device-driver developer's kit (DDK) package that starts the process. The DDK helps you design drivers in C, but it doesn't generate executable code. For that you need a separate compiler, such as Microsoft's Visual C. You also need a debugger, such as the one that comes with the Win32 software developer's kit (Win32 SDK). An alternative debugger is the NuMega Technologies SoftIce, version 3.01.

My experiences with driver development during the last project convinced me that device-driver development was outside my skill set. My background is assembly-language programming of microcontrollers, not interacting with PC operating systems. Operating-system driver-software development requires a different skill set from that required for microcontroller-firmware design. Most embedded-system teams will find the same division in their engineers and should plan on having separate engineers for USB-driver and-firmware design.

To help me with driver development, I wanted a guide through the Windows NT driver labyrinth. Fortunately, such guides have become more available in the eight months since my last expedition. SystemSoft offers both training and consulting services aimed at USB developers and can provide custom-driver development. BlueWater Systems offers design tools that work with the Microsoft Windows NT DDK and have libraries dedicated to creating USB drivers. I chose to work with BlueWater Systems on this project because it was willing to send engineer Joshua Buergel to help develop the driver I needed. Intel engineer Sharma Upadhyayula also gave me extensive help with the 82930AX microcontroller firmware.

As I prepared to make this expedition into USB territory, the value of experienced guides became immediately obvious. I had planned to use as my starting point the USB loopback-test firmware that Intel posts on its Web site. Upadhyayula quickly informed me that this firmware needed an update and provided me with a new firmware so that the expedition started off in the right direction.

Rather than use Intel's sample loopback driver, I wanted a custom driver that would let me receive long strings of data from the microcontroller. Buergel quickly put together a driver and DOS-based test program that gave me control over the host's interactions with the evaluation board. The test software allowed me to read and write single 64-byte blocks of data, alternate read and write transactions in a loop, and read an unlimited amount of data from the evaluation board.

Our combined efforts quickly took me beyond the territory I had explored in my previous effort. In that first project, my evaluation board never completed the enumeration sequence. With my guides' help, I was able to see why. The host system executes an allowed, but unexpected, transaction sequence during enumeration.

Upon system initialization, or whenever a new USB device attaches to a running system, the host must query the device to obtain the device's description of itself. The USB host-controller software uses that description to find and load the appropriate device drivers. After obtaining the description, the host assigns an address to the device and reads the device's configuration data.

As implemented in my system, however, the host twice queries a device for its description. The first time, the host aborts the transaction after receiving only 8 bytes. The second time, it completes the enumeration sequence according to the specification.

The reason for the aborted first query is unclear, but the host always made the same two-step enumeration. Possibly, the host sends the first query merely to verify that the attached device will respond correctly before starting enumeration. The specification allows this operation; a USB device must be able to recover from aborted transactions. The aborted query is simply an extra step that the specification does not require. In my first project, my evaluation board did not react properly to the aborted transaction. The updated evaluation-board firmware worked per-fectly.

Batch operation kills bus speed

I performed several tests with my USB device. The first test consisted of running a batch program that repeatedly wrote a single 64-byte block and then read a single 64-byte block. The purpose of this test was to see how quickly a batch program could obtain data from a USB device when incurring the full overhead of the USB software chain (Figure 2). In this situation, my system took 110 to 140 msec to initiate each read or write. Thus, the software overhead of running in DOS batch mode had slowed the achievable data rate to only 450 bytes/sec.

To obtain data rates closer to the 1.2 Mbytes/sec theoretically possible on the USB, requests for multiple 64-byte transactions must come from lower in the software chain. By configuring the driver to request 6400-byte transfers from the host controller, I was able to run the experiment again at a speed limited only by the host controller.

Buergel set the driver to alternate read and write requests to the USB device until 6400 bytes had transferred each way. I expected the evaluation board to accept 64 bytes of data and then to load that data into its output buffer for transmission. Ideally, then, the system would alternately execute 100 read and 100 write transactions with only the host-system delay between transactions.

In practice, my USB device wasn't fast enough to sustain these repeated transactions. It would accept several 64-byte blocks before turning around and returning the first block. Then, it would return several blocks before accepting any more. The device's average data rate was 540 kbytes/sec.

The evaluation board's internal firmware, not the host system, set that limit, however. Measuring the delay between successive transactions gave me an estimate of the data rate the system could have achieved if the board had been able to keep up. The average value for Host_Delay was 4.76 µsec following a read transaction and 3.21 µsec following a write transaction. Those values translate into a sustained data rate of 1.088 Mbytes/sec.

To estimate the long-term average data rate that my test setup achieved, I ran a program that caused the driver to loop through its 6400-byte read-and-write transfer routine and display a count of completed loops. A run of 1000 loops (6.4 Mbytes read and 6.4 Mbytes written) required 23 sec to complete, an average data rate of 556 kbytes/sec.

Old system bug

While executing the extended loop test, the host system would occasionally lock up and need to be rebooted. Buergel explained that some of the early releases of the USB host-controller IC had this problem with long bulk transfers. Later hardware versions have corrected the problem, and the Memphis version of Windows 9x had a software fix for the problem. Developers planning to use the current release of Windows 95, however, should be aware that older host hardware may lock up with sustained bulk transfers.

My initial goal for this USB project was to see what data rates a data-acquisition system on the USB could achieve. To explore that question, Upadhyayula and I modified the loopback code of the USB evaluation board to make the board continually load its output buffers so that I could perform a sustained read from the board. As with the loopback test, the evaluation board's firmware limited the average data rate to 540 kbytes/sec.

I performed all of my tests on a system that was running only the USB test application. In practical applications, however, the host system may be running other programs or servicing keyboard and mouse entries, in addition to transferring data over the USB. The Host_Delay factor accounts for the times when the host is too busy to initiate the next USB transaction.

In a brief experiment, I ran the 6400-byte read-and-write program with the system quiet and with the mouse active. A single measurement of data rates showed a 1.088-Mbyte/sec rate on a quiet system, dipping to 960 kbytes/sec when the mouse was active.

1-Mbyte/sec transfer rate

The results of my experiments have several implications for embedded-system developers. The first is that USB is now ready for developers to begin work in earnest. The system software and version problems that derailed my first project are much more settled. Al-though the released version of Windows with USB support has some problems, the more robust prebeta version of Windows 9x is readily available for developers looking to create products that will work with the 1998 Windows release.

Development teams that expect to develop their own drivers will need to have expertise in Windows NT driver development. This expertise is not the same as Windows driver expertise; Windows NT uses a driver model different from Windows 3.1. Help is available to those who need it, however, in the form of advanced development tools and consulting services.

You should be able to readily attain bulk-transfer data rates of 1 Mbyte/sec in systems dedicated to the transaction. Designs should provide adequate buffering, however, for those times when the instantaneous data rate drops. Such drops result from the host system's internal activity or the occasional need to resend data because of system noise. Attempts to achieve a sustained data rate of 1.088 Mbytes/sec, as I measured in short bursts, should be made with caution. Achieving such data rates may require that the designer carefully control the host system's operation as well as the USB-device design.

Finally, be aware that, although the USB is settling down, it is far from a domestic animal. The updated host-system software is still in prebeta testing. Many published examples of USB software are out-of-date, and some are just plain wrong. Nonetheless, the USB is ready to begin taking its part in the PC architecture and can serve as a useful port for embedded-system designs.


References

  1. Quinnell, Richard A, "USB: a neat package with a few loose ends," EDN, Oct 24, 1996, pg 38.

  2. Universal Serial Bus Specification Version 1.0, Jan 19, 1996.


Acknowledgments

I would like to thank BlueWater Systems, Digital Equipment Corp, Hewlett-Packard, FuturePlus Systems, Intel, Logitech, Microsoft, and PLC for the generous loan of equipment, personnel, and expertise that made this article possible. Special thanks go to Joshua Buergel of BlueWater Systems, Sharma Upadhyayula of Intel, and Susan Shaw of the USB's Implementer's Forum for their time and talents.


  • The USB product and tool infrastructure has stabilized enough to allow widespread development.

  • USB device-design teams need Windows NT driver expertise to be successful.

  • Achieving high speeds on the USB requires drivers that handle large transactions.

  • Bulk-data-transfer rates readily reach 1 Mbyte/sec.

  • Pushing the USB beyond 1 Mbyte/sec requires a dedicated host system.

Table 1--USB-development products
Product type Company USB products
ICs Atmel Hub controller
  CAE Technology USB cores (ASIC)
  CMD Technology Inc USB-PCI host controller, keyboard controller
  Cypress Semiconductor Peripheral microcontroller
  FTDI Hub and peripheral controllers
  Innovative Semiconductors Inc Synthesizable cores (ASIC)
  Intel Host and peripheral controllers, motherboards
  LSI Logic USB-function cores (ASIC)
  Lucent Technologies Programmable logic, USB-to-parallel converter
  Micrel Semiconductor Controllers, power switches
  Mitsubishi Microprocessor-unit core
  Motorola Peripheral controllers
  Multivideo Labs Inc Monitor-hub controller
  National Semiconductor Host-and monitor-hub controllers
  NEC Electronics Host-controller core (ASIC)
  NetChip Technology Inc Hub and interface controllers
  Oki Semiconductor USB-function cores (ASIC)
  Philips Semiconductors Hub controller
  Samsung Semiconductor Mouse and joystick microcontroller
  Sand Microelectronics Synthesizable cores (ASIC, FPGA)
  Scan Logic Image peripheral interfaces
  Texas Instruments Hub and peripheral controllers, power management
  Thesys Microelectronics Microcontroller-to-USB interface
  USAR Systems Keyboard microcontroller
  Virtual Chips Inc USB cores (ASIC)
Software American Megatrends Inc BIOS, device drivers, reference-design kits
  Award Software BIOS
  eTEK Labs Firmware, software interfaces, device drivers
  MCCI Firmware, device drivers
  Microsoft Corp Host OS, driver-development kit
  Phoenix Technologies Ltd BIOS, device drivers, ASIC cores
  SystemSoft Firmware, device drivers, peripherals
  USAR Systems Human-interface-device (HID)-class firmware, device drivers
Tools BlueWater Systems Inc Driver-development kit, USB-class libraries
  Cactus Logic Emulator
  CATC Protocol analyzer, test generator
  CMX Co RTOS
  Crescent Heart Software Probe adapter, traffic simulator
  Digital Systems Associates Protocol analyzer
  FuturePlus Systems Corp Protocol analyzer
  Genoa Technology Inc Protocol analyzer
  Hitex Development Tools Emulator
  iSystems Emulator
  Keil Software Inc Assemblers, compilers, debuggers
  Production Languages Corp Assemblers, compilers, debuggers
  Tasking Software Assemblers, compilers, debuggers
  Vireo Software Inc Driver-development kit
  Xyratex Protocol analyzers
Training Addison Wesley Longman Textbooks
  Annabooks Handbooks, textbooks, training
  SystemSoft Consulting, training
Note: This table lists tools for developers. It omits host systems, peripherals, and connector-cable assemblies.
USB basics

The goal of the Universal Serial Bus (USB) design is to sweep the plethora of I/O ports on the PC into one serial channel. The bus runs at a base data rate of 12 Mbps but offers a 1.5-Mbps option that helps keep down the cost of low-performance devices, such as keyboards.

USB's physical configuration is a tiered star. The PC acts as the host and root hub to which the user can attach devices or additional hubs. These additional hubs can, in turn, connect to a combination of devices and another hub layer. The bus supports as many as five hub layers and 127 devices on one host. The bus also can provide 5V power to attached devices.

The control of system setup, device initialization, and data flow all reside with the host system. Upon system power-up, the host performs enumeration on each USB device. The host queries the device for a description, assigns the device a unique address for subsequent transactions, and sets the device's operating configuration. The host also identifies and loads hardware-specific drivers for the USB device into the operating system during device enumeration.

Every millisecond (the USB frame time), the USB host initiates a series of data transactions. The USB offers two types of data transactions for high-volume data. Isochronous transactions offer guaranteed bandwidth, with the host system allocating 1 to 1023 bytes/frame for the transaction. Bulk transactions have no bandwidth guarantees. The host allocates to bulk data as much bandwidth as is left over after all other transactions are accounted for. Bulk transactions have guaranteed delivery with resend ability, ensuring that all data arrives eventually.

All USB data transactions are host-initiated. Based on application program requests for data transfers, the host signals the USB device to start the data flow, regardless of the data's source or destination. USB devices cannot initiate a transfer; they can only respond to the host's command.

For more information...
For information on products such as those discussed in this article, circle the appropriate numbers on the Information Retrieval Service card or use EDN's Express Request service. When you contact any of the following manufacturers directly, please let them know you read about their products in EDN.
Addison Wesley Longman
Reading, MA, 1-617-944-3700
fax 1-617-942-3077
www.aw.com
American Megatrends Inc
Norcross, GA
1-770-246-8600
fax 1-770-246-8790
www.megatrends.com
Annabooks
San Diego, CA
1-619-673-0870
fax 1-619-673-1432
www.annabooks.com
Atmel Corp
San Jose, CA
1-408-441-0311
fax 1-408-487-2600
www.atmel.com
Award Software International
Mountain View, CA
1-415-968-8886
fax 1-415-968-0274
www.award.com
BlueWater Systems Inc
Edmonds, WA
1-206-771-3610
fax 1-206-771-2742
www.bluewatersystems.com
Cactus Logic
Baldwin Park, CA
1-800-847-1998, 1-818-337-4547
fax 1-818-337-0689
CAE Technology
San Jose, CA
1-408-526-9207
fax 1-408-529-9308
CMD Technology Inc
Irvine, CA
1-714-454-0800
fax 1-714-455-1656
www.cmd.com
CMX Co
Framingham, MA
1-508-872-7675
fax 1-508-620-6828
www.cmx.com
Computer Access Technology Corp (CATC)
Santa Clara, CA
1-408-727-6600
fax 1-408-727-6622
www.catc.com
Crescent Heart Software
Portland, OR
1-503-287-5422
fax 1-503-287-5430
www.c-h-s.com/~chschs
Cypress Semiconductor
San Jose, CA
1-408-943-2600
www.cypress.com
Digital Equipment Corp
Computer Systems Division
Maynard, MA
1-800-344-4825
www.pc.digital.com
Digital Systems Associates
Santa Ana, CA
1-714-838-2495
fax 1-714-838-2497
eTEK Labs
Rochester, NY
1-716-292-6400
fax 1-716-292-6273
FuturePlus Systems Corp
Colorado Springs, CO
1-719-380-7321
fax 1-719-380-7362
www.futureplus.com
Future Technology Devices International (FTDI)
Glasgow, Scotland, UK
+44 141 353 2565
fax +44 141 353 2656
Genoa Technology Inc
Moorpark, CA
1-805-531-9030
fax 1-805-531-9045
www.gentech.com
Hewlett-Packard
Colorado Springs, CO
1-719-590-3265
fax 1-719-590-3505
Hitex Development Tools
San Jose, CA
1-800-454-4839
fax 1-408-441-9846
www.hitex.com
Innovative Semiconductors Inc
Mountain View, CA
1-415-968-3370
fax 1-415-938-0735
www.isi96.com
Intel
Folsom, CA
1-916-356-6653
fax 1-916-356-6227
www.intel.com
iSystems
Dachau, Germany
+49 8133 125 083
Keil Software Inc
Dallas, TX
1-214-735-8052
fax 1-214-735-8055
Logitech Inc
Fremont, CA,
1-510-795-8500
LSI Logic
Milpitas, CA
1-408-433-8000
www.lsilogic.com
Lucent Technologies
Allentown, PA
1-800-372-2447
fax 1-610-712-4106
www.lucent.com/micro
MCCI
Ithaca, NY
1-607-277-1029
www.mcci.com
Micrel Semiconductor
San Jose, CA
1-408-944-0800
Microsoft Corp
Redmond, WA
1-206-882-8080
Mitsubishi Electronics America
Electronic Device Group
Sunnyvale, CA
1-408-730-5900
fax 1-408-732-9382
Motorola, Microcontroller
Technologies Group
Austin, TX
1-800-765-7795, ext 887
sps.motorola.com/csic
Multivideo Labs Inc
1-609-497-1930
fax 1-609-497-1945
National Semiconductor
Santa Clara, CA
1-800-272-9959
fax 1-408-245-9655
www.national.com
NEC Electronics
Mountain View, CA
1-415-528-6000
fax 1-415-528-5400

 

NetChip Technology Inc
Mountain View, CA
1-415-526-1490
fax 1-415-526-1494
www.netchip.com
NuMega Technologies
Nashua, NH
1-603-889-2386
Oki Semiconductor
Sunnyvale, CA
1-408-720-1900
fax 1-408-720-1918
www.okisemi.com
Philips Semiconductor
Sunnyvale, CA
1-408-991-2000
Phoenix Technologies Ltd
Santa Clara, CA
1-408-654-9000
fax 1-408-452-1985,
www.ptltd.com
Production Languages Corp
1-817-599-8363
fax 1-817-599-5098
www.plcorp.com
Samsung Semiconductor
San Jose, CA
1-408-954-7000
fax 1-408-954-7286
Sand Microelectronics
Santa Clara, CA
1-408-235-8600
fax 1-408-235-8601
Scan Logic
Bedford, MA, 1-617-276-3901
fax 1-617-275-1758
www.scanlogic.com
SystemSoft
Natick, MA, 1-508-651-0088
fax 1-508-651-8188
www.systemsoft.com
Tasking Software
Dedham, MA, 1-617-320-9400
fax 1-617-320-9212
www.tasking.com
Texas Instruments
Denver, CO
1-800-477-8924, ext 4500
www.ti.com
Thesys Microelectronics
Erfurt, Germany
+49 361 427 6160
USAR Systems
New York, NY, 1-212-226-2042
fax 1-212-226-3215
www.usar.com
USB Implementers Forum
Hillsboro, OR
1-503-264-0590
fax 1-503-264-9027
www.usb.org
Vireo Software Inc
Acton, MA, 1-508-264-9200
fax 1-508-264-9205,
www.vireo.com
Virtual Chips Inc
San Jose, CA, 1-408-452-1600
fax 1-408-452-0952
www.vchips.com
Xyratex
Havant, UK
+44 1705 486363
fax +44 1705 492228
www.xyratex.co.uk

Richard Quinnell, Technical Editor

You can reach Richard Quinnell at 1-719-530-0560, fax 1-719-530-0560**, e-mail ednquinnell@mcimail.com.

 

| EDN Access | Feedback | Table of Contents |


Copyright © 1997 EDN Magazine, EDN Access. EDN is a registered trademark of Reed Properties Inc, used under license. EDN is published by Cahners Publishing Company, a unit of Reed Elsevier Inc.