μC/ USB
Device
Universal Serial Bus Device Stack
TM
User’s Manual
V4.00
Micriμm
1290 Weston Road, Suite 306
Weston, FL 33326
USA
www.micrium.com
Designations used by companies to distinguish their products are often claimed as trademarks.
In all instances where Micriμm Press 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 more complete information
on trademarks and trademark registrations. All trademarks and registered trademarks in this
book are the property of their respective holders.
Copyright © 2012 by Micriμm except where noted otherwise. All rights reserved. Printed in the
United States of America. No part of this publication may be reproduced or distributed in any
form or by any means, or stored in a database or retrieval system, without the prior written
permission of the publisher; with the exception that the program listings may be entered, stored,
and executed in a computer system, but they may not be reproduced for publication.
The programs and code examples in this book are presented for instructional value. The
programs and examples have been carefully tested, but are not guaranteed to any particular
purpose. The publisher does not offer any warranties and does not guarantee the accuracy,
adequacy, or completeness of any information herein and is not responsible for any errors or
omissions. The publisher assumes no liability for damages resulting from the use of the
information in this book or for any infringement of the intellectual property rights of third parties
that would result from the use of this information.
100-uC-USB-Device-001
Table of Contents
Chapter 1
1-1
1-1-1
1-1-2
1-1-3
1-2
1-2-1
1-2-2
1-2-3
1-3
1-3-1
1-3-2
1-4
1-4-1
1-4-2
1-4-3
About USB ............................................................................................ 15
Introduction .......................................................................................... 15
Bus Topology ....................................................................................... 15
USB Host .............................................................................................. 16
USB Device .......................................................................................... 16
Data Flow Model .................................................................................. 17
Endpoint ............................................................................................... 17
Pipes ..................................................................................................... 18
Transfer Types ..................................................................................... 18
Physical Interface and Power Management ....................................... 21
Speed ................................................................................................... 21
Power Distribution ............................................................................... 22
Device Structure and Enumeration ..................................................... 22
USB Device Structure .......................................................................... 22
Device States ....................................................................................... 24
Enumeration ......................................................................................... 25
Getting Started ..................................................................................... 27
Prerequisites ........................................................................................ 28
Downloading the Source Code Files ................................................... 28
Installing the Files ................................................................................ 30
Building the Sample Application ......................................................... 31
Understanding Micrium Examples ...................................................... 31
Copying and Modifying Template Files .............................................. 33
Including USB Device Stack Source Code ......................................... 37
Modifying Application Configuration File ............................................ 38
Running the Sample Application ......................................................... 40
Chapter 2
2-1
2-2
2-3
2-4
2-4-1
2-4-2
2-4-3
2-4-4
2-5
3
Table of Contents
Chapter 3
3-1
3-1-1
3-1-2
Host Operating Systems ...................................................................... 45
Microsoft Windows .............................................................................. 46
About INF Files ..................................................................................... 46
Using GUIDs ......................................................................................... 51
Architecture .......................................................................................... 53
Modules Relationship .......................................................................... 55
Application ........................................................................................... 55
Libraries ................................................................................................ 55
USB Class Layer .................................................................................. 56
USB Core Layer ................................................................................... 56
Endpoint Management Layer .............................................................. 56
Real-Time Operating System (RTOS) Abstraction Layer ................... 57
Hardware Abstraction Layer ................................................................ 57
CPU Layer ............................................................................................ 58
Task Model ........................................................................................... 58
Sending and Receiving Data ............................................................... 59
Processing USB Requests and Bus Events ....................................... 61
Processing Debug Events ................................................................... 63
Configuration ........................................................................................ 65
Static Stack Configuration ................................................................... 65
Generic Configuration .......................................................................... 66
USB Device Configuration ................................................................... 66
Interface Configuration ........................................................................ 66
String Configuration ............................................................................. 67
Debug Configuration ............................................................................ 68
Communication Device Class (CDC) Configuration ........................... 68
CDC Abstract Control Model (ACM) Serial Class Configuration ....... 68
Human Interface Device (HID) Class Configuration ........................... 68
Mass Storage Class (MSC) Configuration .......................................... 69
Personal Healthcare Device Class (PHDC) Configuration ................. 69
Vendor Class Configuration ................................................................. 69
Application Specific Configuration ..................................................... 69
Task Priorities ...................................................................................... 69
Task Stack Sizes .................................................................................. 70
Device and Device Controller Driver Configuration ........................... 71
Configuration Examples ...................................................................... 71
Chapter 4
4-1
4-1-1
4-1-2
4-1-3
4-1-4
4-1-5
4-1-6
4-1-7
4-1-8
4-2
4-2-1
4-2-2
4-2-3
Chapter 5
5-1
5-1-1
5-1-2
5-1-3
5-1-4
5-1-5
5-1-6
5-1-7
5-1-8
5-1-9
5-1-10
5-1-11
5-2
5-2-1
5-2-2
5-3
5-4
4
5-4-1
5-4-2
5-4-3
Simple Full-Speed USB device ........................................................... 72
Composite High-Speed USB device ................................................... 73
Complex Composite High-Speed USB device ................................... 74
Device Driver Guide ............................................................................. 77
Device Driver Architecture ................................................................... 77
Device Driver Model ............................................................................. 78
Device Driver API ................................................................................. 78
Interrupt Handling ................................................................................ 81
Single USB ISR Vector with ISR Handler Argument ........................... 81
Single USB ISR Vector ......................................................................... 82
Multiple USB ISR Vectors with ISR Handler Arguments .................... 82
Multiple USB ISR Vectors .................................................................... 83
USBD_DrvISR_Handler() ...................................................................... 83
Device Configuration ........................................................................... 85
Endpoint Information Table ................................................................. 86
Memory Allocation ............................................................................... 88
CPU and Board Support ...................................................................... 88
USB Device Driver Functional Model .................................................. 89
Device Synchronous Receive .............................................................. 89
Device Asynchronous Receive ............................................................ 91
Device Synchronous Transmit ............................................................ 93
Device Asynchronous Transmit ........................................................... 95
Device Set Address ............................................................................. 97
USB Classes ......................................................................................... 99
Class Instance Concept ....................................................................... 99
Class Instance Structures .................................................................. 108
Class and Core Layers Interaction through Callbacks ..................... 111
Communications Device Class .......................................................... 115
Overview ............................................................................................. 116
Architecture ........................................................................................ 119
Configuration ...................................................................................... 120
General Configuration ........................................................................ 120
ACM Subclass .................................................................................... 121
Overview ............................................................................................. 121
5
Chapter 6
6-1
6-2
6-3
6-4
6-4-1
6-4-2
6-4-3
6-4-4
6-4-5
6-5
6-5-1
6-6
6-7
6-8
6-8-1
6-8-2
6-8-3
6-8-4
6-8-5
Chapter 7
7-1
7-2
7-3
Chapter 8
8-1
8-2
8-3
8-3-1
8-4
8-4-1