USB Overview This course serves as an introduction to USB.
Agenda USB overview USB low level data transfer USB protocol structure USB chapter 9 structure Enumeration Standard classes Firmware example Silicon Labs solutions Where to get more information 2 We are going to cover fairly in depth overview of USB, the device families that support USB connectivity, and some of the tools available to the support customer designs. At then end we will illustrate how Silicon Labs supports USB efforts and can abstract all of what you are about to learn.
Advantages of USB Ease of Use One interface for many devices Hot pluggable Automatic configuration No power supply required Devices can pull up to 500 mA from the bus Reliability Lossless data transfers Type A/B Mini Speed Three transfer speeds Low Speed – 1.5 Mbps (USB 1.1 and 2.0) Full Speed – 12 Mbps (USB 1.1 and 2.0) Hi-Speed – 480 Mbps (USB 2.0 only) Low Power Consumption Suspend mode Devices consume 500 uA or less (USB 2.0) Devices consume 2.
Some USB Terms Host — computer that controls the interface Function — device that provides a capability to the host Hub — device with one or more connections to USB devices plus hardware to enable communications with each device Device — something that attaches to a USB port (sometimes synonymous with a function) Port — a connector on the USB Host bus Suspend — Device enters Suspend after 3mS of inactivity on the bus to minimize power consumption. Host uses timing packet to keep Peripherals active.
What is USB? Serial protocol—strictly defined frame and packet based protocol with error checking and handshaking. LSB in first, MSB last. Host Controller Root Hub Half Duplex—all transactions initiated by the host with data carried by the D+ and D- signals in both directions Device Management—host assigns addresses to newly attached devices and removes support for detached devices. Host also manages bandwidth. Peripheral Hub Power Management—use of Suspend mode to conserve power on the bus.
USB Lower Layer In this course serves as an introduction to USB.
Attach Event Plugging in a USB device to the host root hub or external hub is considered an attach event. The device has a 1.5 KΩ pull-up resistor to the USB supply (VBUS). Pull-up to D+ signals a full speed device. D- is for low speed devices. 1.5KΩ D+ D+ Transceiver Transceiver Full Speed Attach Event D- 15KΩ VBUS D- Device 15KΩ Host or Hub Port When no device is connected D+ and D- are at 0 V 1.
Packet Identifiers (PID) The PID signals to the receiver that what the packet structure and content will be and how the receiver has to respond PID Type PID Name PID Value <3:0> OUT 0001b IN 1001b PID - indicates transaction type and has different meaning based on the transaction. Lower nibble is the inversion of the upper nibble provided for error checking.
Packets Packets—block of information with a defined data structure. The packet is the lowest level of the USB transfer hierarchy describing the physical layer of the interface.
Transactions A transaction allows a set of operations to be grouped in such a way that they either all succeed or all fail; further, the operations in the set appear from outside the transaction to occur simultaneously. If the transaction is unsuccessful then the host/device ignores any data that was received. Transaction Types SETUP: Specifies a control transfer. Setup transactions are always targeted to Endpoint 0 and are bi-directional (IN and OUT endpoint).
What is a Transfer? The transfer is the process of making a communications request with an endpoint.
Transfer Format Transfer Type Stages (Transactions) Phases (Packets) Comments Setup Token Enables host to read configuration information, set addresses and select configurations Only transfer that is required to be supported by peripherals Has both IN and OUT transfers to a single endpoint Data Handshake Control Data (IN or OUT) (optional) Token Status (IN or OUT) Token Data Handshake Data Handshake Bulk Data (IN or OUT) Token Data Handshake Interrupt Data (IN or OUT) Token Data Handsha
USB Transfers—A Closer Look Control Write Transfers (OUT)—contains Setup, Data (optional), and handshake transactions Setup Transaction SETUP PID=1101 DATA0 PID=0011 ACK PID=0010 Data Transaction OUT PID=0001 DATA1/0 PID=1011 ACK PID=0010 NAK PID=1010 Host sends Setup Packet followed by 8 bytes of data for the request. The device must return an ACK. Host sends OUT Packet along with the data for writes. Device responds with handshake. No response indicates a data error.
USB Transfers—Closer Look at a Control Transfer Control Read Transfers (IN)—contains Setup, Data (optional), and handshake transactions Setup Transaction SETUP PID=1101 DATA0 PID=0011 ACK PID=0010 Data Transaction IN PID=1001 DATA1/0 PID=1011 ACK PID=0010 Data error NAK PID=1010 Data error Status Transaction 0-LENGTH OUT DATA1 PID=0001 PID=1011 Host sends setup packet followed by 8 bytes of data for the request. The device must return an ACK.
USB Transfers—Actual Control Transfer Control Transfer Read Example — GET_STATUS command from Host Transfer Transaction Packet Hierarchy SETUP Phase DATA Phase Status Phase 0 length field 15 Here is an actual USB analyzer capture of data traffic for a control transfer. This is a control transfer (Get_Status) that a host has sent out to a device.
USB Transfers—Closer Look at Bulk/Interrupt Transfers Bulk and interrupt transfers Contains IN/OUT, Data, and handshake transactions Bulk schedules transfers as bus bandwidth permits Interrupt schedules transfers on regular intervals. Data may be delivered at a faster rate than the endpoint descriptor value. Data IN Transaction IN PID=1001 DATA PID=1011 ACK PID=0010 Data error NAK PID=1010 Host sends IN packet and the device responds with the data requested. Host responds with handshake.
USB Transfers—Actual Interrupt Transfer Bulk/interrupt transfer read example: Interrupt Transfer IN Transaction Token Packet Data Packet Handshake Packet 17 Here is a screen capture of actual USB data traffic using these Bulk/Interrupt transfer type. Notice that the transfer is composed of a single transaction.
USB Transfers—Closer Look at an Isochronous Transfer Isochronous transfer Contains IN/OUT and DATA transactions Fixed transfer rate with a defined number of bytes transferred Transferred in bursts Host guarantees time scheduled transfers per frame Insures data can get through on a busy bus even if the data does not need to transmit at real time Good for constant rate applications such as audio IN PID=1101 DATA0 PID=0011 Host sends IN packet and the device responds with the data requested.
USB Transfers—Actual Isochronous Transfer Isochronous transfer OUT example: OUT Transaction Transfer Transaction Packet Hierarchy Token Packet Data Packet 19 And a screen capture of the Isochronous transfer.
I Have to Know All of This? What part of the low level USB information do I need to be concerned with? The USB transceiver and the Serial Interface Engine (SIE) handles the low level USB interface and is done via the hardware. We are primarily concerned with the middle layer.
Silicon Labs Serial Interface Engine (SIE) Serial Interface Engine (SIE) is part of the USB hardware and handles data communications to the host in hardware Handles the handshake between the endpoint and the host device Generates an interrupt when valid data packets received Will not interrupt the CPU when an error in transmission occurs Moves valid data to/from the endpoint FIFOs Firmware only needs to be concerned with the data transferred Handles all the bit stuffing required 21 SIE Handl
Different Devices and the Transfers They Use What happens when all of these devices are plugged into the USB? Interrupt Host manages the bus bandwidth upon enumeration. If bandwidth is not available the host ignores the enumeration request and doesn’t allow the device access. Mouse and keyboard use Interrupt transfers to provide timely responses to user input. Interrupt provides guaranteed maximum latency. Scanners and printers use bulk since they are just sending data files.
USB Middle Layer 23
USB—Chapter 9 The host initializes a device through a series of device requests via control transfers to Endpoint 0. These are defined by the USB specification and have specific control transfer formats that we have discussed. Chapter 9 Defines The device states The standard request format The device descriptor format The process used to transfer all of the configuration information to endpoint 0 is called Enumeration.
Enumeration—Loading Descriptors Enumeration //-----------------------------------------------------------// Sample Standard Device Descriptor Type // Definition Fields //-----------------------------------------------------------Length (18) Descriptor Type (DEVICE, CONFIGURATION, INTERFACE, ENDPOINT, HID) USB Spec Release Number (0200h) Device class (hub type…Human Interface defined in other descriptor, CDC described here) Device Sub-class (00h) Device protocol (00h) Maximum Packet size (64 bytes – max fo
Enumeration: Finding a Driver Once all descriptors are communicated, the Windows host searches for a driver based on the vendor ID and product ID of the device Vendor ID [DeviceList] %DESCRIPTION%=DriverInstall,USB\VID_1ABC&PID_2XYZ [DriverCopyFiles] usbser.sys [DriverService] ServiceType=1 StartType=3 ErrorControl=1 ServiceBinary = %12%\usbser.
USB Descriptors Descriptors Data structures, or formatted blocks of information, that enable the host to learn about the device Each Descriptor contains information about either the device as a whole or an element in the device The host uses control transfers to obtain the descriptors from the device Descriptors typically reside in non-volatile data storage on the device. Most commonly set as C structures or variables located in code space.
USB Descriptors Types Device descriptor General info about a USB device (vendor ID, etc) Contains info that applies globally to the device Only one device descriptor Device Device Descriptor Descriptor Configuration Configuration Descriptor Descriptor Configuration descriptor USB devices can have multiple configurations Each configuration contains one or more interfaces All associated interface and endpoint descriptors get loaded with a request from the host for the configuration descript
Example Device Descriptor Spec (1 of 2) A look at a descriptor and its fields Offset Field Size Value Description 0 bLength 1 Number Size of this descriptor in bytes 1 bDescriptorType 1 Constant DEVICE Descriptor Type 2 bcdUSB 2 BCD USB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H) This field identifies the release of the USB Specification with which the device and its descriptors are compliant.
Example Device Descriptor Spec (2 of 2) A look at a descriptor and its fields Offset Field Size Value Description 6 bDeviceProtocol 1 Protocol Protocol code (assigned by the USB-IF). These codes are qualified by the value of the bDeviceClass and the bDeviceSubClass fields. If a device supports classspecific protocols on a device basis as opposed to an interface basis, this code identifies the protocols that the device uses as defined by the specification of the device class.
Device Descriptor Example A look at a device descriptor declared in code: //--------------------------// Descriptor Declarations //--------------------------const device_descriptor DeviceDesc = { 18, // bLength 0x01, // bDescriptorType 0x0002, // bcdUSB 0x02, // bDeviceClass 0x00, // bDeviceSubClass 0x00, // bDeviceProtocol EP0_PACKET_SIZE, // 0x40 0x10c4, // idVendor 0x3413, // idProduct 0x0000, // bcdDevice 0x01, // iManufacturer 0x02, // iProduct 0x00, // iSerialNumber 0x01 // bNumConfigurations }; //e
Getting the Descriptors How does the host get all of these descriptors from the MCU? The Standard Request. The data passed as part of the Setup phase of the control transfer is specified in the USB specification and each byte has a specific meaning.
Standard Device Request Format The host initializes a device through a series of device requests via control transfers to Endpoint 0 These are defined by the USB spec and have specific control transfer formats Offset 0 Field bmRequestType Size 1 Value Bitmap Description Characteristics of request: D7: Data transfer direction 0 = Host-to-device 1 = Device-to-host D6...5: Type 0 = Standard 1 = Class 2 = Vendor 3 = Reserved D4...0: Recipient 0 = Device 1 = Interface 2 = Endpoint 3 = Other 4...
Standard Requests Values These tables indicate the bRequest values and the wValue values defined by the USB spec From the previous slide it can be seen that the wValue field can take on several different meanings based on the request bRequest Field: What request? wValue Field: Get_Descriptor Request Standard Request Value Descriptor Type Value GET_STATUS 0 DEVICE 1 CLEAR_FEATURE 1 CONFIGURATION 2 Reserved for future use 2 STRING 3 SET_FEATURE 3 INTERFACE 4 Reserved for future use
Standard Request Exercise We are a host and we want to generate a request to a device in order to receive it’s device descriptor What values would we need to provide in our SETUP packet data phase? Determine the data values we need to send to the device in order for it to respond with its device descriptor values Offset Field Size Value 0 bmRequestType 1 0x80 1 bRequest 1 0x06 2 wValue 2 0x0100 4 wIndex 2 0x0000 6 wLength 2 0x0012 Notes: 1) The device descriptor is 18 bytes lon
Standard Requests Example Get_Descriptor(DEVICE): Standard request to get the device descriptor bmRequestType = 80h, bRequest = 06h (Get_Descriptor()) wValue = 0100h (DEVICE) wIndex = 0000h wLength = 0012h (18 bytes) 8 bytes of data found within the setup phase of the control transfer. Set_Address(3): Standard request to set device address to 3.
USB—Device States (1 of 3) After power up and throughout the enumeration process the MCU enters/exits several device states Idle state All drivers are off. Device speed determines Idle state based on the pull-up resistor attached. For full speed D+ is more positive than D- and vice versa for low speed. Suspend state Low power state with < 500 uA current consumption requirement. If remote wake-up capable then it is < 2.5 mA.
USB—Device States (2 of 3) Resume Any bus activity brings device out of suspend Host places bus in Data K state for 20 mS then low speed EOP Remote wake-up device drives the Data K state for 1 mS to 15 mS and then places drivers in High-Z state Powered Device has been attached to the USB port and draws power from VBUS It has not been reset Default Device has been reset from a powered state and has not been assigned an address It responds only to endpoint0 Addressed Device has bee
USB—Device States (3 of 3) State diagram 39 There are different device states defined in the USB specification. Here is a graphical view of the device states. As you can see they progress from the attach event all the way to configured.
Device Classes Device classes group common interfaces together Class definitions specify the number and types of endpoints May define data formats May define functions or capabilities of devices within the class Some types of defined classes Human interface class Communications device class Hub class Printer class Mass storage class Audio class 40 An additional set of specifications has been added to the overall USB 2.0 specifications.
Human Interface Device (HID) HID Class originally developed to for human interface objects such as mice and keyboards Interrupt transfers used for data transport Any device can use the HID drivers. It does not need to be a human interface device device.
Mass Storage (MSD) Used for file transfer for memory sticks, etc.
Communications Device Class (CDC) Bulk transfers used for data transport Any device can use the CDC drivers. It does not need to be a modem device. Volt meters Bar code readers Thermometers Anything that requires a serial port input to the host uses the Abstract Control Model (ACM) What do I need? Firmware side Firmware to detect and respond to Standard requests and the Class specific requests Standard and class specific descriptors defined.
Example Class Specific Descriptor Structure CDC Class uses the Abstract Control Model **Device Device Descriptor Descriptor Bridge the gap between serial devices and USB Uses the Communications Class Interface and the Data Class Interface CDC defines a set of functional descriptors as part of the Communications Class Interface Configuration Configuration Descriptor Descriptor Data Data Class Class Interface Interface Descriptor Descriptor Standard descriptor using values from the CDC spec.
USB Firmware 45
USB Firmware Descriptor Variable Defined Device Descriptor Structures 46 Here is a snapshot of some sample code that implements USB. On the left are the definitions for the specific descripors and on the right is the actual code that places these descriptor values into the flash of the MCU.
Code Flow—One Example USB ISR Routine ISR generated whenever USB event occurs 1 Handle_Setup Routine 4 Parse the ISR to determine USB event Data that gets written to USB endpoint 0 FIFO 3 2 5 47 In these samples we can follow the firmware after the interrupt is received. The example here is showing how the firmware determines what type of request was received and how the data is returned to the host.
What is Required and Where to Get Help Requirements Vendor ID—obtained from the USB Forum See following slide about how Silicon Labs can help Product ID—unique number identifying the product family of the equipment Typically obtained from the USB Forum Serial Number—unique identifier for each specific equipment developed under the PID Get help here USB Implementers Forum (USB-IF) www.usb.org USB 2.
USB Solutions Offered by Silicon Labs 49
Certification and Compliance Testing Silicon Labs allotment system Silicon Labs has a unique VID (0x10C4) If a customer uses the Silicon Laboratories VID, they must ask Silicon Laboratories to assign a unique PID to their product Contact Silicon Labs MCU technical support to receive a PID USB Implementer’s Forum (USB-IF), found at www.usb.
Silicon Labs USB MCU Products Mixed-Signal USB 2.
Highly Integrated USB MCUs High-speed 8051 core up to 48 MIPS Up to 64Kb Flash and 4K RAM for application code Complete 2.
Most Powerful Mixed-Signal USB MCU In-system debug No need for emulators High-speed 8051 core operating up to 48 MIPS Up to 64 kB Flash and 5376B of RAM Integrated Voltage Regulator Allows bus powered operation Internal oscillator No external crystal 17 ch. 10-bit, 200 ksps ADC USB transceiver No external resistors 53 Silicon labs controller solutions fall into two main classes: fixed function and fullyprogrammable mixed-signal MCUs with integrated USB controller.
Single-Chip USB to UART Bridge CP210x family of devices Fixed function USB to UART bridges provide the easiest method for upgrading legacy RS232 systems with USB Requires no firmware or driver development Most integrated USB to UART bridge solution 1024 Bytes of EEPROM for customization Integrated transceiver Integrated precision clock On-chip voltage regulator 5x5 mm2 QFN28 package Simplifies and enables legacy system upgrades Full royalty-free driver support No software design n
Single-Chip CP2103 USB to UART Bridge Integrated voltage regulator Allows bus powered operation Integrated oscillator No external crystal 4 Host controlled GPIO LED drive capability CP2103 VBUS Voltage Regulator GPIO 48 MHz Oscillator Complete UART Up to 1 Mbps D+ USB Transceiver D– USB Function Controller 640 B TX Buffer UART 576 B RX Buffer UART I/F (Modem) 1024 B EEPROM USB transceiver No external resistors EEPROM Custom baud rates Stores VID, PID Security lock function D
USB Software Support Fixed-function Support Software Full royalty-free driver support for Windows, MAC OS, and Linux WHQL certified MCU Support Software USBXpress: Allows the developer to implement a USB application without USB expertise Royalty Free, Windows Certified Device Driver that can be customized and distributed Design Examples: Mass Storage Device (MSD) Data Logger Human Interface Device w/ Boot Loader USB Streaming Audio / Isochronous Control, Bulk and Interrupt firmware
USBXpress—Features General USBXpress information Implements a bulk pipe between host and peripheral Operates at full speed using bulk transfers Maximum transaction size is 4096 bytes Max throughput = 960 kB/sec Allocates one IN endpoint and one OUT endpoint on the C8051F32x/34x devices Multiple USBXpress devices may reside on the same bus Distributed as a Keil software library 57 After the previous slides all of this makes sense right? The key to USBXpress is that there is no OS driver dev
USB Development Solutions Evaluation kits for USB/UART bridge CP2102EK, CP2103EK VCP Driver CD included Full development kits for Flash-based USB MCUs CP2103 Evaluation Board C8051F320DK C8051F326DK C8051F340DK Integrated IDE, assembler, compiler, linker, debugger On-chip debug hardware (breakpoints, watchpoints, single-step) Mass storage daughter card ToolStick daughter cards ToolStick321DC ToolStick327DC ToolStick342DC USB MCU Development Kit Free downloadable USBXpress fir
Learn More at the Education Resource Center Visit the Silicon Labs website to get more information on Silicon Labs products, technologies and tools The Education Resource Center training modules are designed to get designers up and running quickly on the peripherals and tools needed to get the design done http://www.silabs.com/ERC http://www.silabs.com/mcu http://www.silabs.com/usb http://www.silabs.
Appendix An Actual CDC Class Enumeration & Data Transfer Example 60
Enumeration Tabular form of what we listed in our device descriptor structure.
Get_Descriptor (Device) Remember our exercise slide 35? We parsed the data and returned the device descriptor Status phase terminating the transfer 62 62
Passing the Config Descriptor (1 of 2) Data toggle in action — our max packet size is 64 bytes. Our config descriptor is 67 bytes so we need multiple data phases to complete the transfer.
Passing the Config Descriptor (2 of 2) The data shown corresponds to the data set-up in the USB_DESCRIPTORS.c file. It is transferred in response to a Get_Descriptor(Configuration) request. Last 3 bytes of the configuration request First 64 bytes of the configuration including 2 interface descriptors and their endpoint descriptors. The Abstract Control Model values are part of this response.
More Enumeration Why the red X? We broadcast USB 2.0 compliant so this request is to find out if the device supports an other speed. We don’t so we stall the response.
USB Setting the Baud Rate When we set HyperTerminal to the baud rate and selected “Connect”, the driver sends the device a command to set its UART to that rate. Class request 0x20 is SetLineCoding. 0xE100 = 57600 Class request 0x21 is GetLineCoding. We return what we received to verify.
We Use Our Bulk Endpoints Now that the communications link is established we are ready to transfer data. We hit keys while the HyperTerminal window is active and the host is using the Bulk transfers we set up during enumeration to send data. Bulk OUT transfers to send the keys we hit. This example shows “hello” being typed.
www.silabs.