USB: The Universal Serial Bus
Benjamin David Lunt
3rd Edition
(Updated: 2022 Jan 01)
ISBN-13: 978-1717425362
ISBN-10: 1717425364
Available at Amazon or your favorite book source and in PDF format
Volume Eight of a series of books on Operating System Design
Please go to the bottom of this page and write a review. Thank you.
The 3rd Edition, Updated 2022 Jan 01, is now available. ( what's new)
I have a blog about this and other similar items
View the Errata to the 1st Ed., 2nd Ed., or 3rd Ed.
See below for customer comments
Visit my FaceBook page
I am still interested in your help. If you have a chance, please have a look at this page.
Have a look at my Figure Eight page that shows how to create your own USB Device.
Have a look at my ATTiny2313 device that doesn't "hard code" the LED's to the board. You can attach it to a bread board and use it as you please.
This book is for those who are building an operating system, writing embedded code, or just want to learn how to communicate with the USB hardware and attached devices directly through hardware programming.
This book will show you how to find and initialize each of the four major USB Host Controllers, set up USB stacks, and communicate with attached devices. It has detailed information and examples of each step required to accomplish this.
Detailed information for the UHCI, OHCI, EHCI, and the new Super Speed xHCI controller is easy to follow and understand.
Information in the book or on the CD-ROM may include
735 pages
• quirks of different controllers
• quirks of different devices
• specific errors and "gotchas" to watch for
• step by step instructions to get a device's descriptor(s)
• Details and/or C Source code to:
• Find a USB controller on the PCI(e) bus using only the PCI hardware.
• Find information about the USB controller
• Find a device attached
• Retrieve the attached device's Device Descriptor
• Read from a USB Mass Storage Devices
• Read from a USB external Floppy Drive
• Parse the HID device descriptor
• Retrieve Mouse movement
• Retrieve Keypress information
• Print to a USB printer
• Set up and use an External Hub
• UASP (USB Attached SCSI Protocol) devices. (i.e.: New thumb drives)
• ISO transfers for all four controller types
Suggested information you will need prior to reading this book are readily available and may be included on the available companion CD-ROM, may include:
• Specification documents for the UHCI, OHCI, EHCI, and xHCI Host Controllers
• USB specification documents versions 1.1, 2.0, and 3.0
• USB HID specification
• Knowledge of system programming on an Intel 80x386 based system
• Knowledge of the C Language and an available C Compiler
• along with other system related knowledge
It is not required that you have extensive knowledge of USB or the PCI(e) bridge it resides on. This book explains in detail how to get started, even if you have little or no knowledge of this technology.
Amazon now has a "Look Inside" of the first few pages of the book including the Contents showing in a bit more detail what is referenced in the book.
The Companion CD-ROM
The companion CD-ROM is no longer available due to the ease of access to the internet. With that being said, the source code is available via github.
See Appendix A for the structure and contents of this repository, which will be updated when time, neccesity, and/or interest allows.
Table of Contents
Introduction
Part 1
1. Overview of the USB
2. The PCI Hardware
3. The UHCI Hardware
4. The UHCI Stack
5. The OHCI Hardware
6. The OHCI Stack
7. The EHCI Hardware
8. The EHCI Stack
9. The xHCI Hardware
10. The xHCI Stack
Part 2
11. Device Enumeration with the UHCI Stack Frame
12. Device Enumeration with the OHCI Stack Frame
13. Device Enumeration with the EHCI Stack Frame
14. Device Enumeration with the xHCI
Part 3
15. Using the USB Mouse
16. Using the USB Keyboard
17. Using the USB Mass Storage Device
18. Using the USB Floppy Storage Device
19. Using the USB External Hub
20. Using a USB Printer Device
21. Using a USB HUB on the xHCI Root Hub
22. Using a USB 3.0 Mass Storage Device
23. Using a USB Attached SCSI Mass Storage Device
Part 4
24. Using a USB Protocol Analyzer
25. The Human Interface Device
Part 5
26. Using a USB Video Camera
27. Setting Up the USB Video Camera
28. The UHCI and ISO Transfers
29. The OHCI and ISO Transfers
30. The EHCI and ISO Transfers
31. The xHCI and ISO Transfers
Appendix A - Disc Contents
Appendix B - Included Utilities/Source Code
Appendix C - Tables and Figures
Appendix D - Notes for all Controller Types/Devices
Appendix E - Request Sense Return Data
Appendix F - Brief History of USB
Appendix G - xHCI TRB Types and Completion Codes
Appendix H - USB OTG (On The Go)
Appendix I - USB Class Codes
Appendix J - Device Firmware Upgrade
Appendix K - New Type C USB Connector
Appendix L - Bootable USB Devices
Appendix M - USB Legacy Keyboard Support
Appendix N - EHCI and Built-in Transaction Translators
Appendix Q - Building a Simple USB Device
Appendix X - For More Information
Bibliography
A more detailed Table of Contents (pdf), stripped directly out of the book.
User Comments
- "I just started reading your USB book, and I'm very pleased with it so far. It appears to get right into the nuts and bolts of how to access the USB ports. I especially appreciate the fact that you show how to work with the port in DOS", Mike Welch
- "As I heard, USB is difficult, but your book makes it much easier", Robert Nagy
- "Wow, thank you very much for the prompt response and an excellent book!", Simon Gustavsson
- "The book is very well written and an excellent/practical supplement to the specifications (which get rather dry)", Jacob von Chorus
- "Can't wait to get deep into these. Thanks for publishing this series. The font and pageing formats are AWESOME.", Daniel de la Rosa
- Keep up the good work... I love the work that you have already done with the USB. No one explains things from a low level perspective anymore, that's why I am so glad I came across your OS series.", Michael Tindal
- "I have purchased your USB book and am very pleased with the layout and information. It is the best publication I have on the topic.", Gordon Simpson
- I have written OHCI based USB drivers for an embedded device (written in ARM assembler for an MCS8140 CPU), but was unfamiliar with the EHCI stack and needed to implement some high speed devices. Like most standards, the EHCI standard is written in a way that describes each piece of the jigsaw precisely, but makes it difficult to understand how the pieces fit together. Unlike the previous (and more expensive) book I purchased, your book has assisted tremendously.", Dave Mould
- "... let me thank you for [a] great book which is not only great from [a] technical point of view but is also a great and easy read as well. I'm looking forward to see[ing] the rest of [the] books from your OS development series.", A. Czarnowski.
- "I'm benifitting from it already", G. Curran.
- "The UHCI part was very informative", M. Kalme.
- "I appreciate the effort that you put into this project", M. Gonta.
- "Thank you", P. Wang.
- "I'm a hobbist working in a USB Stack for SGI Irix, and your book has been very helpful!! It's just what I was looking for!!", BSDero.
- "...it certainly looks promising as a complementary (and reassuring!) resource for some of the more complicated aspects of the USB...", cod3b453.
- "I bought your book [a] few days ago and I just can't tell how much I benefited from it already. Thanks for your inspiration and kindness.", Evan Ko.
- "I'm benifitting from it already.", Gertrude.
- "Thank you so much for your wonderful USB book, which will be of great assistance to me, and, I am sure, to many others.", Howard Levine.
- "Thank you very much for a great book.", Jordi Sanfeliu.
- "Great book!", Karl.
- "Thanks a lot for writing the book, I have barely read anything I am already enjoying it!", Lars Bokkers.
- "Great Job!", Loren Blaney.
- "I got the book on Friday and couldn't stop reading it :). Thank You for this book!", Madis Kalme.
- "Thank you for an excellent book. I received my copy of the book yesterday and I have been reading it since.", Markku Niemela.
- "It's great", Martin.
- "By the way, I can't wait for more books of this series, very informative and complete :)", Max.
- "Thanks for your great book.", Mike.
- "Very interesting and good complement to the USB specifications.", P. Regnier.
- "I have purchased your great book that covers details on the USB technology", Ralf.
- "This is a good book. Packed with useful information. I have already learned much from it.", Robert.
- "...ready to start delving into the intricate details of the USB system...", Ron.
- "Thank you for taking time to write that informative USB book.", Thomas Loepfe.
- "Thanks for the book.", Tom Ehlert.
- "Very nice book! Thanks very much!"
- "I am finding it fascinating...", Roger Ray
- "For starters, great book. I'm a USB newbie with a project to complete and your book has helped far more than any other source.", Larry Guertin
- "I've now read through it at speed to get an overview of its content and I'm deeply impressed at the amount of work that's gone into it. This is the book that will ensure that the hobby OS is still possible after (U)EFI leads to the extinction of the BIOS.", David Cooper
- "Thank you for taking the time to write this book", Florin
- "great book by the way :)", Kaz Baygan
- "I've just ordered your book, and am already enjoying it!", Oleg FInkelshteyn
- "I started looking for a good USB book, stumbled upon some reviews of your book, and thought 'this seems like the exact thing I need!'. What a great surprise when the book finally arrived.", Inaki Etxebarria
- "Your books are just super amazing condensed knowledge. Lecture of these books was an entertaining time and I must admit, that you encouraged me to do my best and gave me a motivation to work on my hobby OSdev project :)", Karol Grzybowski
- "I've just started to read your book but it appears to be exactly what I was looking for. I design single board computer (SBC) replacements for Programmable Logic Controllers (PLC)s. There are great I/O options available but they use USB. I'm trying to design a bare metal, single thread system for maximum safety which means writing my own USB drivers. Thanks for the great book", Alan
- "Your book is terrific and is helping me understand the USB protocol. I'm working on an embedded processor application and it is so hard to find a good book/webpage/forum etc that will help us learn USB", Robb Fisher
|
General Frequently Asked Questions about this Book Series are found at the main book page.
A Frequently Asked Question list about USB device driver development can be found here.
Frequently Asked Questions (about my book):
- Q: USB looks complicated. Should I even learn USB in the early stages of my development?
A: First, don't be discouraged that you might not wish to start so early in to USB. Though I agree that USB might be difficult and probably not something a newbie should be starting with, I will tell you that the USB is and can be a most enjoyable part of your learning experience. Therefore, if you wish to start USB now, for the joy of it, this would be a perfect time to do so, though keep in mind that a successful implementation will need other parts of an OS system already implemented.
- Q: What other components of the Operating System must I implement to be able to use USB?
A: You will need a working knowledge of the PCI(e) system to be able to find the USB controllers, and you will need some sort of accurate timing system for accurate delays as well as other time sensitive parts of the USB. For the timing, you can read the (dated) RTC clock, the (dated) 8253 Timer, the newer APIC clock, or even the most recent HPET clock. I discuss, in detail, the necessary parts needed of the PCI(e) bus in Chapter 2 of this book.
- Q: Using your book, will I need to buy any other hardware to test my code?
A: If you are using system emulation exclusively, such as QEMU or Bochs, you will not need to purchase any extra hardware. Each of these emulators with emulate the necessary hardware needed. If you wish to test your code on actual real hardware, then of course you will need the actual hardware to test with, whether you purchase it or borrow it.
- Q: Of the above questions, what specifically does this book cover?
A: This book covers the process of programming the USB from the beginning. It starts by describing the PCI enough to find the USB controllers, determine which type it is, and how to find other information about the controller. The next section shows how to setup and use each of the four controllers, each description independent of another. The next section shows how to enumerate different devices in general while the next section goes into detail about the types of devices that can be attached. These devices include Mice, Keyboards, MSDs (Mass Storage Devices) such as thumb drives, External Hubs, and Printers. I have given as much detail as possible to be able to successfully setup a controller, attached devices, and communicate with said devices to read mouse coordinates, keypresses, sectors from a thumb drive, status of external hubs, and send images to a printer. Details include, for example, the difference between full-speed thumb drives and Super-speed thumb drives and the different interfaces used.
- Q: What specific devices do you use as examples and detail in your book?
A: Most commonly available devices, such as:
- HID devices: USB Low-speed keyboards and mice, using both the default boot protocol, as well as parsing the HID descriptor(s) to use the HID protocol packets. Included is a complete chapter specific to HID Descriptor Parsing containing complete source code.
- MSD devices: Mass Storage Devices such as USB hard drives, thumb drives, and floppy disk drives. These come with difference protocols such as Bulk-only BBB (Bulk Bulk Bulk), UFI CBI (Command Block Interrupt), both with Interrupt and without, and the new UASP (USB Attached SCSI Protocol) taking advantage of xHCI Streams.
- External Hubs and Rate Matching Hubs, including how to get the status of each port, as well as other needed information pertaining to devices attached.
- USB Printers: Information is included to determine what type of printer is attached and what protocol you can use to send text or images to the printer. An example of printing an image is included.
- USB Cameras: Information on using ISO type transfers with High-speed cameras, including source code to receive full screen images.
- Information is included on known quirks of each type of device, such as getting the capacity of a thumb drive. Some manufacturers return the count of sectors available while other manufacturers return the address to the last sector available. This will always be a difference of one sector depending on the technique used.
- Q: In your book you describe the use of a USB analyzer and show how to see the traffic that is sent on the actual wire. Do I need one of these analyzers?
A: The analyzer in question is from TotalPhase and if you have a look at their website, you can see that these wonderful little pieces of hardware are quite pricy, at a price of about $500 US Dollars. Though it is not necessary to use this book, it was a great benefit to my development to see what data is actually being sent, the timing between each packet, and the sequence of these packets as they are sent back and forth between the host and the device. For your benefit, I have given examples shown in memory dumps to show this throughout this book. Therefore, unless you are very serious about USB, plan to create devices, and/or work for a company, the purchase of an analyzer is not at all necessary when using this book. However, I highly recommend an analyzer such as the one linked here if you wish to be a serious USB hardware programmer.
- Q: Your book mentions that I can create a USB device and shows how to do so. What do I need to do such a thing?
A: The freely available Appendix Q of this book shows in detail what you need to do create a simple USB device. It shows what compiler is needed and how to use it, what electronic items are needed, such as resisters and capacitors, as well as a few examples of IC boards. You will also need a little knowledge on how to use solder and a iron correctly, as well as a few misc items. The example given shows how to blink an LED, and I have other examples freely avaliable, such as how to create a 7-segment digit display and send digit values.
- Q: What is the difference between Jan Axelson's book and your book?
A: Her book explains quite well how to use the installed operating system and its functions (and additional libraries) to access the operating system's USB functionality, detailing the communication between the host and the device, but not how it actually gets sent and/or received through the host's installed hardware.
My book explains how a (non-specific) operating system communicates with the attached hardware to pass the commands and data back-and-forth between the attached devices and the host operating system, those commands and data packets her book details. My book also explains the hardware side of the USB that is used to do this from the operating system's point of view, not from the user's point of view.
- Q: Do you have a Frequently Asked Question list about USB device driver development?
A: Yes. You can find that FAQ list here.
|