`
`US-
`COMPLET
`
`
`
`Apple 1062 (Part 1 of 3)
`
`US. Pat. No. 9,189,437
`
`SECOEB Earner:
`
`it With firmware tips & host code
`in Visual Basic and Visuai C++
`
`Apple 1062 (Part 1 of 3)
`U.S. Pat. No. 9,189,437
`
`
`
`USB Complete
`
`Everything Yea Need
`to Develep Custom USB Peripherals
`
`Second Editien
`
`Jan Axelson
`
`Lakeview Research
`
`Madison, WI 53704
`
`
`
`copyright 2001 by Jan Axelson. All rights reserved.
`Published by Lakeview Research
`
`Cover by Rattray Design. Cover Photo by Bill Bilsley Photography.
`Index by Broccoli Information Management
`
`Lakeview Research
`
`5310 Chinook Ln.
`
`Madison, WI 53704
`
`USA
`
`Phone: 608—241—5824
`
`Fax: 608—241—5848
`
`Email: info@Lvr.com
`
`Web: http://www.Lvr.com
`
`141.31le, 10987654321
`
`Products and services named in this book are trademarks or registered trademarks of
`their respective companies. In all instances where Lakeview Research is aware of a
`trademark claim, the product name appears in initial capital letters, in all capital letters,
`or in accordance with the vendor’s capitalization preference. Readers should contact the
`appropriate companies for complete information on trademarks and trademark registra—
`tions. All trademarks and registered trademarks in this book are the property of their
`respective holders.
`
`No part of this book, except the programs and program listings, may be reproduced in
`any form, or stored in a database or retrieval system, or transmitted or distributed in any
`form, by any means, electronic, mechanical photocopying, recording, or otherwise,
`without the prior written permission of Lakeview Research or the author. The programs
`and program listings, or any portion of these, may be stored and executed in a computer
`system and may be incorporated into computer programs developed by the reader.
`
`The information, computer programs, schematic diagrams, documentation, and other
`material in this book are provided “as is,” without warranty of any kind, expressed or
`implied, including without limitation any warranty concerning the accuracy, adequacy,
`or completeness of the material or the results obtained from using the material. Neither
`the publisher nor the author shall be responsible for any claims attributable to errors,
`omissions, or other inaccuracies in the material in this book. In no event shall the pub—
`lisher or author be liable for direct, indirect, special, incidental, or consequential dam~
`ages in connection with, or arising out of, the construction, performance, or other use of
`the materials contained herein.
`
`ISBN 0—96508l9~5~8
`
`Printed and bound in the United States of America
`
`
`
`Table of Contents
`
`Table of Contents
`
`Introduction xiii
`
`1. A Fresh Start 1
`
`What USB Can Do 3
`
`Benefits for Users
`
`Benefits for Developers
`It’s Not Perfect 11
`
`User Challenges
`Developer Challenges
`History 16
`The Motivation for Change
`The Specification’s Release
`USB 2.0
`
`USB versus IEEE—1394
`
`2. Is USB Right for My Project? 21
`Fast Facts 21
`
`Minimum PC Requirements
`The Components
`
`USB Complete
`
`iii
`
`
`
`Table of Contents
`
`Bus Topology
`Defining Terms
`What is a Port?
`
`The Host's Duties
`
`The Peripheral's Duties
`What. about Speed?
`The Development Process 35
`Elements in the Link
`
`Tools for Developing
`Steps in Developing a Project
`
`3. Inside USB Transfers 39
`
`Transfer Basics 40
`
`Configuration Com munications
`Application Communications
`Managing Data on the Bus
`Host Speed and Bus Speed
`Elements of a Transfer 44
`
`Device Endpoints
`Pipes: Connecting Endpoints to the Host
`Types of Transfers
`Stream and Message Pipes
`Initiating a Transfer
`Transactions: the Building Blocks of a Transfer
`Transaction Phases
`
`Ensuring that Transfers Are Successful 61
`Handshaking
`Reporting the Status of Control Transfers
`Error Checking
`4. A Transter Type for Every Purpose 71
`Control Transfers 71
`
`Availability
`Structure
`Data Size
`
`Speed
`Detecting and Handling Errors
`Bulk Transfers 78
`
`Availability
`Structure
`Data Size
`
`Speed
`
`iv
`
`USB Complete
`
`
`
`Table of Contents
`
`Detecting and Handling Errors
`Interrupt Transfers 81
`Availability
`Structure
`Data Size
`
`Speed
`Detecting and Handling Errors
`Isochronous Transfers 85
`
`Availability
`Structure
`
`Data Size
`
`Speed
`Detecting and Handling Errors
`More about Time—critical Transfers 89
`
`Bus Bandwidth
`
`Device Capabilities
`Hosr Software Capabilities
`Windows Latencies
`
`5. Enumeration: How the Host Learns about Devices 93
`
`The Process 94
`
`Enumeration Steps
`Enumerating a Hub
`Device Removal
`
`Descriptor Types and Contents 101
`Types
`Device Descriptor
`Devicerualifier Descriptor
`Configuration Descriptor
`Other_Speed_Configuration Descriptor
`Interface Descriptor
`Endpoint Descriptor
`String Descriptor
`Descriptors in 2.0wcompliant Devices 116
`Making 1.x Descriptors 2.0vcompliant
`Detecting the Current Speed of‘a Dual—Speed, Device
`
`6. Control Transfers:
`
`Structured Requests for Critical Data 119
`Elements of a Control Transfer 119
`
`The Setup Stage
`The Data Stage
`
`USB Complete
`
`
`
`Table of Contents
`
`The Status Stage
`Handling Errors
`The Requests 127
`Set~Address
`GeLDescriptor
`Set‘Descriptor
`Set_Configuration
`Get_Configuration
`Set Interface
`
`Cet_InterFaee
`Set__Feature
`
`Clear_Feature
`Gethtatus
`Synch_Frame
`Class~Specific Requests
`Vendor~Specific Requests
`
`7. Chip Choices 141
`Elements of a USB Controller 14.2
`
`The USB Port
`
`Buffers for USB Data
`CPU
`
`Program Memory
`Data Memory
`Registers
`Other I/O
`Other Features
`
`Simplifying the Development Process 147
`Architecture Choices
`
`Chip Documentation
`Sample Firmware
`Driver Choices
`
`Debugging Tools
`Project Needs
`A Look at Some Chips 157
`Cypress enCoRe
`Cypress EZ—USB
`Microchip PIC 16C7X5
`NetChip NET2888
`National Semiconductor USBN9603
`Philips Semiconductors PDIUSBD1 1/12
`Intel StrongARM
`
`vi
`
`USB Complete
`
`
`
`8. Inside a USB Controller: the Cypress enCoRe 171
`
`Table of Contents
`
`Selecting a Chip 172
`Requirements
`The Choice
`
`The Assembler 173
`
`Assembly Programming Basics
`Assembler Codes
`
`Using the Assembler
`Programming in C 180
`Advantages to C
`Using the Compiler
`Chip Architecture 181
`Features and Limits
`
`Inside the Chip
`Memory
`USB Communications 187
`
`Device Address
`Modes
`
`Endpoint Status and Control
`USB Status and Control
`
`Other I/ O 192
`
`General—purpose I/O
`SPl Port
`The PS/2 Interface
`
`Other Chip Capabilities 197
`Timer Functions
`
`Interrupt Processing
`CPU Status, Control, and Clocking
`Power Management
`
`9. Writing Firmware: the Cypress enCoRe 209
`Hardware and Firmware Responsibilities 209
`What the Hardware Does
`What the Firmware Does
`
`Hardware Development Tools 219
`The Development Kit
`PROM Programming
`
`10. How the Host Communicates 231
`
`Device Driver Basics 231
`
`Insulating Applications from the Details
`
`USB Complete
`
`vii
`
`
`
`Table of Contents
`
`Options for USB Devices
`How Applications Communicate with Devices
`The Win32 Driver Model 237
`
`Driver Models for Different Windows Flavors
`
`Layered Drivers
`Communication Flow
`
`More Examples
`Choosing a Driver Type 248
`Drivers Included with Windows
`
`Vendor~supplied Drivers
`Custom Drivers
`
`Writing a Custom Driver 249
`Requirements
`Using a Driver Toolkit
`
`11. How Windows Selects a Driver 255
`
`The Process 255
`
`Searching For INF Files
`The Registry’s Role
`The Control Panel
`
`What the User Sees
`
`Inside an INF File 262
`
`Sections
`
`The Generic INF File for HIDs
`
`Creating INF Files 271
`Tools
`
`Tips
`
`12.. Device Classes 275
`
`Uses of Classes 276
`
`Elements of a Class Specification
`Defined Classes
`
`Matching a Device to a Class 279
`Standard Peripheral Types
`Non—standard Functions
`
`13. Human Interface Devices: Firmware Basics 293
`
`What is a HID? 294
`
`Hardware Requirements
`Firmware Requirements
`Identifying :1 Device as a HID 299
`Descriptor Contents
`
`viii
`
`USB Complete
`
`
`
`Table of Contents
`
`HID Class Descriptor
`Report Descriptors
`HID—specific Requests 306
`GetHReport
`SetfiRepo rt
`Get__Idle
`Set_Idle
`GetflProtocol
`SetflProtocol
`Transferring Data 314
`Sending Data to the Host
`Receiving Data from the Host
`
`14. Human Interface Devices: Reports 321
`
`Report Structure 321
`Using the HID Descriptor Tool
`Predefined Values
`Short Items
`
`Long Items
`The Main Item Type 325
`Input, Output, and Feature Items
`Collection and End Collection Tags
`The Global Item Type 330
`Identifying the Report
`Describing the Data’s Use
`Converting Raw Data
`Describing the Data’s Size and Format
`Saving and Restoring Global Items
`The Local Item Type 339
`Physical Descriptors
`Padding
`
`15. Human Interface Devices: Host Application Primer 343
`Host Communications Overview 344
`
`How the Host Finds a Device
`Documentation
`The HID Functions
`DirectX
`
`Using API Functions 348
`Using Visual C++
`Using Visual Basic
`The Declaration
`
`USB Complete
`
`ix
`
`
`
`Table of Contents
`
`Calling a Function
`Two Useful Routines
`
`Device Attachment and Removal 362
`USBVieW
`
`Searching for a Device
`Device Notification
`
`Enabling and Disabling Devices
`
`16. Human Interface Devices:
`
`Hlost ApplicationExample 365
`Finding a Device 366
`Obtain the GVUID for the HID Class
`
`Get an Array of Structures with Information about the HIDs
`Identify Each HID Interface
`Get the Device Pathname
`Get a Handle for the Device
`Read the Vendor and Product IDs
`
`Get a Pointer to a Buffer with Device Capabilities
`Get the Device’s Capabilities
`Get the Capabilities of the Values
`Reading and Writing Data 384
`Sending an Output Report to the Device
`Reading an Input Report from the Device
`Reading Reports without Blocking the Thread
`Writing a Feature Report to the Device
`Reading a Feature Report from a Device
`Closing Communications
`
`17. Device Testing 401
`USB Check’s Test Suite 402
`
`Detecting a Device
`The Tests
`HIDVieW
`
`Test Equipment 409
`Protocol Analyzers
`Other Test Equipment
`Testing and Logos 417
`The USB Implementers Forum Compliance Program
`Windows Hardware Quality Labs Testing
`Driver Signing
`
`18. Hubs: the Link between Devices and the Host 423
`
`x
`
`USB Complete
`
`
`
`Table of Contents
`
`Hub Basics 424
`
`The Hub Repeater
`The Transaction Translator
`The Hub Controller
`
`Speed
`How Many Hubs in Series?
`The Hub Class 434
`
`Hub Descriptors
`Hub Values for the Standard Descriptors
`The Hub Descriptor
`Hub—class Requests
`Port Indicators
`
`19. Managing Power 443
`Powering Options 443
`Voltages
`Which Peripherals Can Use Bus Power?
`Power Needs
`
`Informing the Host
`Hub Power 449
`Power Sources
`Over—current Protection
`
`Power Switching
`Saving Power 452
`Global and Selective Suspends
`Current Limits for Suspended Devices
`Resuming Communications
`
`20. Signals and Encoding 457
`Bus States 457
`
`Low— and Full-speed Bus States
`Highvspeed Bus States
`Data Encoding 462
`Staying Synchronized
`Timing Accuracy
`Packet Format 467
`
`SYNC Field
`
`Packet Identifier Field
`Address Field
`
`Endpoint Field
`Frame Number Field
`Data Field
`
`USB Complete
`
`xi
`
`
`
`Table of Contents
`
`CRC Fields
`
`Inter—packet Delay
`Test Modes 470
`
`Entering and Exiting Test Modes
`The Modes
`
`21. The Electrical Interface 473
`
`Transceivers and Signals 474
`Cable Segments
`Low~ and Full~speed Transceivers
`High—speed Transceivers
`Signal Voltages 484
`Low and Full Speeds
`High Speed
`Cables 485
`Conductors
`
`Connectors
`
`Detachable and Captive Cables
`Cable Length
`Ensuring Signal Quality 492
`Sources ofNoise
`Balanced Lines
`'l‘wisted Pairs
`
`Shielding
`Edge Rates
`Isolation
`
`Index 497
`
`xii
`
`USB Complete
`
`
`
`introduction
`
`Introduction
`
`The Universal Serial Bus (USB) is a fast and flexible interface for connecting
`devices to computers. Every new PC has at least a couple of USB ports. The
`interface is versatile enough to use with standard peripherals like keyboards
`and disk drives as well as more specialized devices, including one—of~a—kind
`designs. USB is designed from the ground up to be easy for end users, with
`no user configuring required in hardware or software.
`
`In short, USB is very different from the legacy interfaces it’s replacing. A
`USB device may use any of four transfer types and three speeds. On attach—
`ing to a PC, a device must respond to a series of requests that enable the PC
`to learn about the device and establish communications with it. in the PC,
`
`every device must have a low~level driver to manage communications
`between applications and the system’s USB drivers.
`
`Developing a USB device and the software that communicates with it
`requires knowing something about how USB works and how the PC’s oper—
`ating system implements the interface. In addition, the right choice of conw
`
`USB Complete
`
`xiii
`
`
`
`Introduction
`
`troller chip, device class, and tools and techniques can go a long way in
`avoiding snags and simplifying what needs to be done. This book is a guide
`for developers of USB devices. Its purpose is to introduce you to USB and to
`help get your project up and running and troublefree as quickly and easily as
`possible.
`
`Who should read this book?
`
`This book is for you if you want to know how to design a USB peripheral,
`or if you want to know how to communicate with USB peripherals From the
`applications you write. These are some of questions the book answers:
`
`' What is USB and how do peripherals use it to communicate with PCs?
`There’s a lot to the USB interface. learning about it can be daunting at
`first. This book’s focus is on the practical knowledge you’ll need to com”
`plete your project.
`
`How can I decide if my project should use a USB interface? Maybe your
`design isn’t suited for USB. I’ll show you how to decide whether it is. If
`the answer is yes, I’ll help you decide which of USB’s speeds and transfer
`types to use.
`
`How do I choose a USB controller chip for my peripheral design? Every USB
`peripheral, must contain an intelligent controller. There are dozens of
`controller chips designed for use in USB peripherals. in this book, I corn~
`pare popular chip Families and offer tips on how to decide, based on both
`your project’s needs and your own background and preferences.
`
`How do applications communicate with USB peripherals? To communicate
`with a USB peripheral, a PC needs two things: a device driver that knows
`how to communicate with the PC’s US‘B drivers and an application that
`knows how to talk to the device driver. Some peripherals can use drivers
`that are built into Windows. Others may require a custom driver. This
`book will show you when you can use Windows’ built—in drivers and how
`to communicate with devices from Visual Basic and Visual C++ applica~
`tions. You’ll also find out what’s involved in writing a device driver and
`what tools can help to speed up the process.
`
`xiv
`
`USB Complete
`
`
`
`Introduction
`
`' How do USB peripherals communicate? USB peripherals typically use a
`combination of hardware and embedded code to communicate with
`
`PCs. In this book, I show how to write the code that enables Windows to
`identify a device and load the appropriate device driver, as well as the
`code required for exchanging data with applications.
`
`° How do I decide whet/oer my perzpbeml can use but power, or whet/Jet it
`needs its own supply? A big advantage to USB is that many peripherals can
`be powered entirely from the bus. Find out whether your device can use
`this capability and how to manage power use, especially for devices that
`use battery power.
`
`° How sun I be sure that my device will opemzfe us smoollzly us possiolefor its
`end users? On the peripheral side, smooth operation requires understand—
`ing the specifications requirements and how the device can meet them.
`In the PC, proper operation requires a correctly structured information
`(INF) file that enables Windows to identify the device and software that
`knows how to communicate with the device as efficiently as possible.
`This book has information and examples to help with each of these.
`
`What’s new in the Second Edition?
`
`In the months after the publication of the first edition of USB Complete,
`much happened in the world of USB, including the release of version 2.0 of
`the USB specification. USB 2.0 supports a bus rate of 480 Megabits per sec—
`ond, forty times faster than USB 1.1. This and other developments in hard~
`ware and software prompted this second edition of the book.
`
`Rather than just tacking on a chapter about USB 2.0, I’ve revised the book
`from start to finish to reflect the changes in 2.0. By popular request, another
`addition is Visual C++ code to accompany the Visual Basic examples for
`application communications with USB devices. I’ve also expanded the mate—
`rial about Windows drivers and applications to include Windows 2000, and
`have added information on new controller chips and development tools.
`Other additions and updates are sprinkled throughout, many prompted by
`reader suggestions.
`
`USB Complete
`
`xv
`
`
`
`introduction
`
`Is this book really complete?
`
`Although the title is USB Complete, please don’t expect this book to contain
`every possible fact about USB. That would take a library. The Complete in
`the title means that this book will guide you from knowing nothing about
`USB to developing all of the code required to get a USB peripheral up and
`communicating with a PC.
`
`There are many other worthy topics related to USB, but limitations of time
`and space prevent me from including them all.
`
`My focus is on communicating with Windows PCs. Although the basic
`principles are the same, I don’t include details about how to communicate
`with peripherals on a Macintosh or a PC running Linux or other non»Win~
`dows operating systems.
`
`I cover the basics of the device drivers responsibilities and What’s involved in
`writing a driver, but the details of driver writing can easily fill a book (and in
`fact there are excellent—wand lengthymbooks on this topic), This book will
`help you decide when you need to write a custom driver and when and how
`to use a class driver included with Windows.
`
`To understand the material in the book, it’s helpful to have basic knowledge
`in a few areas. I assume you have some experience with digital logic, applica—
`tion programming for PCs and writing embedded code for peripherals. You
`don’t have to know anything at all about USB.
`
`Additional Resources, Updates, and Corrections
`
`For more about using USB, I invite you to visit my USB Central page at
`Lakevicw Research’s website, www. meom. This is where you’ll find corn~
`plete code examples, updates, links to vendors, information and tools from
`other sources, as well as links to anything else I find that’s relevant to devel~
`oping USB products. If you have a suggestion, code, or other information
`that you’d like me to post or link to, let me know at jan@[vr. mm.
`
`In spite of my very best efforts, I know from experience that errors will slip
`through in this book. As they come to light, I’ll document them and make a
`
`xvi
`
`USB Complete
`
`
`
`Introduction
`
`list available at Lakeview Research’s website. if you find an error in the book,
`
`please let me know and I’ll add it.
`
`Thanks!
`
`USB is way too complicated to write about Without help. I have many peo'
`ple to thank.
`
`I owe an enormous thank you to my technical reviewers, who generously
`read my rough and rocky drafts and provided feedback that has improved
`the book enormously. (With that said, every error in this book is mine and
`mine alone.)
`
`I thank Paul E. Berg of PEB Consulting; Brian Buchanan, Mark Hastings,
`Lane Hauck, Bijan Kamran, Kosta Koeman, Tim Williams, and Dave
`Wright of Cypress Semiconductor; Joshua Buergel of BSQUARE Inc.; Cary
`Crowell of Micron Technology; Fred Dart of Future Technology Devices
`lnternational (FTDl); Dave Dowler; Mike Fahrion and the engineers at
`88613 Electronics; John M. Goodman, author of Hard Dis/e Secrets, Peter
`Norton '5 Inside the PC, Memory Mnngementfir All of Us, and other books;
`John Hyde, USB enthusiast and author of USB Design by likample; David
`James of lZerol Technologies; Christer Johansson of High Tech Horizon;
`Jon Lueker of Intel Corporation; Bob Nathan ofNCR Corporation; Robert
`Severson of USBMicro; and Craig R. Smith of Ford. Motor Company,
`
`R8CVT department.
`
`Others I want to thank for their help in my researching and writing this
`book are Walter Banks of Byte Craft; Jason Bock; Michael DeVault of
`DeVaSys Embedded Systems; Pete Fowler, Joseph McCarthy, and Don Park—
`man of Cypress Semiconductor; Brad Markisohn of INDesign LLC; Daniel
`McClure of Tyco Electronics; Tawnee McMullen of Belkin Components;
`Rich Moran of RPM Systems Corporation; Dave Navarro of PowerBasic;
`and Amar Rajan of American Concepts Consulting.
`
`I hope you find the book useful. Comments invited!
`
`Jan Axelson, June 2001
`
`jnn @[nncam
`
`USB Complete
`
`xvii
`
`
`
`Introduction
`
`xviii
`
`USB Complete
`
`
`
`A Fresh Start
`
`A Fresh Start
`
`Computer hardware doesn’t often get a chance to start fresh. Anything new
`usually has to remain compatible with whatever came before it. This is true
`of both computers and the peripherals that connect to them. Even the most
`revolutionary new peripheral has to use an interface supported by the com—
`puters it connects to.
`
`But what if you had the chance to design a peripheral interface from scratch?
`What qualities and features would you include? It’s likely that your wish list
`would include these:
`
`' Easy to use, so there’s no need to fiddle with configuration and setup
`details.
`
`° Fast, so the interface doesn’t become a bottleneck of slow communica-
`
`tions.
`
`' Reliable, so that errors are rare, with automatic correction of errors that
`
`do occur.
`
`° Flexible, so many kinds of peripherals can use the interface.
`
`USB Complete
`
`1
`
`
`
`Chapter 1
`
`0
`
`Inexpensive, so users (and the manufacturers who will build the inter-
`face into their products) don’t balk at the price.
`
`0 Power-conserving, to save battery power on portable computers.
`
`‘J Supported by the operating system, so developers don’t have to strug»
`gle with writing low«level drivers for the peripherals that use the inter_
`face.
`
`The good news is that you don’t have to create this ideal interface, because
`the developers of the Universal Serial Bus (U SB) have done it for you. USB
`was designed from the ground up to be a simple and efficient way to com—
`municate with many types of peripherals, without the limitations and frus—
`trations of existing interfaces.
`
`Every new PC has a couple of USB ports that you can connect to a key—
`board, mouse, scanners, external disk drives, printers, and standard and cus~
`tom hardware of all kinds. inexpensive hubs enable you to add more ports
`and peripherals as needed.
`
`But one result of USB’s ambitious goals has been challenges for the develop—
`ers who design and program USB peripherals. A result of USB’s versatility
`and ease of use is an interface that’s more complicated than the interfaces it
`replaces. Plus, any new interface will have difficulties just because it’s new.
`When USB first became available on PCs, Windows did n’t yet include
`device drivers for all popular peripheral types. Protocol analyzers and other
`development tools couldnt begin to be designed until there was a specifica—
`tion to follow, so the selection of these was limited at first. Problems like
`
`these are now disappearing, and the advantages are increasing with the avail»
`ability of more controller chips, new development tools, and improved oper—
`ating—system support. This book will show you ways to get a USB peripheral
`up and running as simply and quickly as possible by making the best possi—
`ble use of tools available now.
`
`including its advantages and drawbacks, a
`This chapter introduces USB,
`look at what’s involved in designing and programming a device with a USB
`interface, and a bit of the history behind the interface.
`
`2
`
`USB Complete
`
`
`
`A Fresh Start
`
`What USB Can Do
`
`USB is a likely solution any time you want to use a computer to communi—
`cate with devices outside the computer. The interface is suitable for
`onevokaind and small—scale designs as well as mass—produced, standard
`peripheral types.
`
`To be successful, an interface has to please two audiences: the users who
`want to use the peripherals and the developers who design the hardware and
`write the code that communicates with the device. USB has features to
`
`please both.
`
`Benefits for Users
`
`From the user’s perspective, the benefits to USB are ease of use, fast and reli—
`able data transfers, flexibility, low cost, and power conservation. Table l—l
`compares USB with other popular interfaces.
`
`Ease of Use
`
`Ease of use was a major design goal for USB, and the result is an interface
`that’s a pleasure to use for many reasons:
`
`One interface for many devices. USB is versatile enough to be usable with
`many kinds of peripherals. Instead of having a different connector type and
`supporting hardware for each peripheral, one interface serves many.
`
`Automatic configuration. When a user connects a USB peripheral to a
`powered system, Windows automatically detects the peripheral and loads
`the appropriate software driver. The first time the peripheral connects, \Win~
`dows may prompt the user to insert a disk with driver software, but other
`than that, installation is automatic. There’s no need to locate and run a
`
`setup program or restart the system before using the peripheral.
`
`No user settings. USB peripherals don’t have user—selectable settings such as
`port addresses and interrupercquest (IRQ) lines. Available IRQ lines are in
`short supply on PCS, and not having to allocate one for a new peripheral is
`often reason enough to use USB.
`
`USB Complete
`
`3
`
`
`
`Chapter 1
`
`Table 1—1: Comparison of popular computer interfaces. Where a standard
`
`
`Interface
`
`Format
`
`Typical Use
`
`'éEéEd
`Length
`Number of
`(maximum,
`(maximum,
`Devices
`bits/sec.)
`feet)
`(maximum)
`WWW
`USB
`asynchronous
`127
`16 (or up to
`1.5M, 12M, Mouse,
`serial
`96 ft. with 5
`480M
`keyboard, disk
`hubs)
`drive, modem,
`
` audio
`
`RS—232
`(ElA/TIA~
`
`232)
`RS—485
`(TIA/EIA—
`485)
`
`asynchronous
`serial
`
`asynchronous
`serial
`
`2
`
`50—100
`
`4000
`
`L
`32 unit loads
`(up to 256
`devices with
`some
`
`hardware)
`
`20k (1 15k
`with some
`
`hardware)
`1 10M
`
`Modem, mouse,
`instrumentation
`
`Data acquisition
`and control
`systems
`
`erA
`
`asynchronous
`serial infrared
`
`2
`
`6
`
`1 15k
`
`Printers, hand—
`held computers
`
`Microwire
`synchronous
`8
`10
`2M
`Microcotrollcr
`
`serial
`communications
`
`SP1
`synchronous
`8
`10
`2.1M
`Microcotroller
`serial
`communications
`
`
`12C
`
`synchronous
`serial
`
`lEEE—l 394
`
`serial
`
`40
`
`64
`
`18
`
`15
`
`3 .4M
`
`Microcotroller
`communications
`
`400M
`
`Video, mass
`
`(FireWire)
`
`(increasing to storage
`3.2G with
`lEEE— 1 39417
`
`
`IEEE~488
`parallel
`l 5
`60
`8M
`
`(GPIB)
`
`Instrumentation
`
`Ethernet
`serial
`1024
`1600
`10M/T00M7" networked PC
`1G
`
`
`MlDl
`
`serial current
`loop
`
`2 (more with
`flow—through
`mode)
`
`50
`
`31.51:
`
`Music, show
`control
`
`
`
`
`
`
`
`
`
`
`
`
`Printers,
`2 (8 with
`Parallel Printer parallel
`Port
`daisy—chain
`scanners, disk.
`
`support)
`drives
`
`10'30
`
`8M
`
`4
`
`088 Complete
`
`
`
`A Fresh Start
`
`
`
`Figure 1-1: The two USB connectors (right) are much more compact than typical
`RS-232 serial (left) and Centronics parallel (center) connectors.
`
`Frees hardware resources for other devices. Using USB for as many
`peripherals as possible frees up IRQ lines for the peripherals that do require
`them. The PC dedicates a series of port addresses and one interrupt—request
`(IRQ) line to the USB interface, but beyond this, individual peripherals
`don’t require additional resources. In contrast, each non—USE peripheral
`requires dedicated port addresses, often an IRQV line, and sometimes an
`expansion slot (for a parallel—port card, for example).
`
`Easy to connect. With USB, there’s no need to open the computer’s enclo—
`sure to add an expansion card for each peripheral. A typical PC has at least
`two USB ports. You can expand, the number of ports by connecting a USB
`hub to an existing port. Each hub has additional ports for attaching more
`peripherals or hubs.
`
`Simple cables. The USB’s cable connectors are keyed so you can’t plug
`them in wrong. Cables can be as long as 5 meters. With hubs, a device can
`be as far as 30 meters from its host PC. Figure l—l shows that the USB con—
`nectors are small and compact in contrast to typical RS—232 and parallel
`
`USB Complete
`
`5
`
`
`
`Chamer1
`
`connectors. To ensure reliable operation, the specification includes detailed
`requirements that all cables and connectors must meet.
`
`Hot pluggable. You can connect and disconnect a peripheral whenever you
`want, whether or not the system and peripheral are powered, without dame
`aging the PC or peripheral. The operating system detects when a device is
`attached and readies it for use.
`
`No power supply required (sometimes). The USB interface includes
`power-supply and ground lines that provide +5V from the computers or
`hub’s supply. A peripheral that requires up to 500 milliamperes can draw all
`of its power from the bus instead of having its own supply. in contrast. most
`other peripherals have to choose between including a power supply in the
`device or using a bulky and inconvenient external supply.
`
`Speed
`
`USB supports three bus speeds: high speed at 480 Megabits per second, full
`speed at 12 Megabits per second, and low speed at 1.5 Megabits per second.
`Every USE—capable PC supports low and full speeds. High speed was added.
`in version 2.0 of the specification, and requires USE 2.0~capable hardware
`on the motherboard or an expansion card.
`
`These speeds are signaling speeds, or the bit rates supported by the bus. The
`rates of data transfer that individual devices can expect are lower. in addition
`to data, the bus must carry status, control, and error-checking signals. Plus,
`multiple peripherals may be sharing the bus. The theoretical maximum rate
`for a single transfer is over 53 Megabytes per second at high speed. about “L2
`Megabytes per second at full speed, and 800 bytes per second at low speed.
`
`\X/hy three speeds? low speed was included for two reasons. Low—speed
`peripherals can often be built more cheaply. And for mice and devices that
`require flexible cables, low»speed cables can be more flexible because they
`don’t require as much shielding.
`
`Full speed is comparable to or better than the speeds attainable with existing
`serial and parallel ports and can serve as a replacement for these.
`
`6
`
`USBCompmm
`
`
`
`A Fresh Start
`
`After the release of USB 1.0, it became clear that a faster interface would be
`
`useful. Investigation showed that a speed increase of forty times was feasible
`while keeping the interface backwards—compatible with low— and full~speed
`devices. High speed became an option with the release of version 2.0 of the
`USB specification.
`
`Reliability
`
`The reliability of USB results from both the hardware design and the
`data«transfer protocols. The hardware specifications for USB drivers, receiv—
`ers, and cables eliminate most noise that could otherwise cause data errors.
`In addition, the USB protocol enables detecting of data errors and notifying
`the sender so it can retransmit. The detecting, notifying, and, retransmitting
`are typically done in hardware and don’t require any programming or user
`intervention.
`
`Low Cost
`
`Even though USB is more complex than earlier interfaces, its components
`and cables are inexpensive. A device with a USB interface is likely to cost the
`same or less than its equivalent with an older interface. For very low—cost
`peripherals, the lowwspeed option has less stringent hardware requirements
`that may reduce the cost further.
`
`Low Power Consumption
`
`Power—saving circuits and code automatically power down USB peripherals
`when not in use, yet keep them ready to respond when needed. In addition
`to the environmental benefits of reduced power consumption, this feature is
`especially useful on battery—powered computers where every milliampere
`COUH’CS.
`
`Benefits for Developers
`
`The above advantages for users are also important to hardware designers and
`programmers. The advantages make users eager to use USB peripherals, so
`there’s no need to fear wasting time developing for an unpopular interface.
`And many of the user advantages also make things easier for developers. For
`
`USB Complete
`
`7
`
`
`
`Chapter 1
`
`example, 'USB’s defined cable standards and automatic error checking mean
`that developers don’t have to worry about specifying cable characteristics or
`providing error checking in software.
`
`USB also has advantages that benefit developers specifically. The developers
`include the hardware designers who select components and design the cir—
`cuits,
`the programmers who write the software that communicates with
`USB peripherals, and the programmers who write the embedded code inside
`the peripherals.
`
`The benefits to developers result from the flexibility built into the USB pro
`tocol, the support in the controller chips and operating system, and the fact
`that the interface isn’t controlled by a single vendor. Although users aren’t
`likely to be aware of these benefits, they’ll enjoy the result, which is inexpenw
`sive, troublerfree, and feature—rich peripherals.
`
`Flexibility
`
`USB’s four transfer types and three speeds make it feasible for many types of
`peripherals. There are transfer types suited for exchanging large and small
`blocks of data, with and without time constraints. For data that can’t toler—
`
`ate delays, USB can guarantee a transfer rate or maximum time between
`transfers. The