Page 78
TWR-MCF52259-USB April 7, 2010 Hareesh S Sr.FAE...
Page 79
K2u/USB Workshops-on-Demand Series This module contains • Introduction to USB • Basic Operation of USB hardware and software • USB Data Structures for K2/3u • USB API Calls for K2/3u...
In This Section: Motivation for the USB Standard History and Evolution of USB USB Topology USB Connectors...
Page 82
USB - Universal Serial Bus was born out of the need to provide designers and end-users with: • an alternative to Apple’s 1394 digital link ® standard (FireWire ) • a fast, bi-directional, low-cost, dynamically attachable serial interface • that removes the port availability constraints for the PC and other devices...
Page 83
Introduction to USB • and adds true plug-and-play attributes for a wide range of devices simultaneously • with minimal or no user intervention required for configuration • and is very end-user friendly...
Page 85
Introduction to USB Current USB Speeds and Limitations Spec Data Rate and Applications Notes Performance USB 1.1 Low- 1.5 Mbps / 10- Keyboard, Low cost but limited speed 100 Kbps mouse, joystick performance; type and number of USB 2.0 Low- endpoints are limited speed USB 1.1 Full-...
Page 86
Introduction to USB USB Spec Provides for a Flexible Tiered Star Topology • Single Host – The host controls communication with each device • Up to 127 devices can be attached • Devices are one of the following: – Hubs (provide additional attachment points) –...
Page 88
Introduction to USB Root Hub A-connector (upstream) B-connector (downstream) Connector types...
Page 89
Introduction to USB Software General Concepts...
Page 90
In This Section: How Data is Transferred in USB How Does the Host Know the Device’s Requirements? The Enumeration Process: What happens when a device is connected? A More Detailed Look at What Comprises a Frame API Calls: What happens after enumeration?
Page 91
How Data is Transferred in USB USB is a token-based (packet) standard. Data is transferred between the host and the device in a series of frames, transfers, transactions, and packets within1 Ms/1500 byte frames. Frame Transfer 1 Transfer 2 Transfer 3 Transaction Transaction 1 Transaction 2...
Page 92
How Data is Transferred in USB Frames are made up of transfers, which are made up of transactions, which are made up of packets. The USB host schedules these 1mS frames when communicating with the low and full speed devices. Frame Transfer Transfer...
Page 93
How Data is Transferred in USB Frame Transfer Transfer There are 4 types of data transfer: Interrupt Bulk Isochronous Control The type of transfer depends upon the type of device and its data requirements (this is discussed in more detail later).
Page 94
How Data is Transferred in USB Transfer Transaction Transaction Each transfer can contain multiple transactions and a transaction can span multiple frames The host schedules transactions within the 1mS frame.
Page 95
How Data is Transferred in USB Transaction Transaction For each transaction there are three types of packets that communicate the data between host and device: Token Packet – the header that defines what follows Optional Data Packet – contains the data being transmitted Status/Handshake Packet –...
Page 96
How Does the Host Know a Device’s Requirements? When a USB device is plugged into a USB port the host communicates with the device and configures each device according its unique requirements such Type of transfer required (interrupt, bulk, isochronous, or control Who supplies the power (host or device) Maximum packet size The number of configurations (e.g., a single device can be...
Page 97
How Does the Host Know a Device’s Requirements? These requirements are communicated to the host through a hierarchy of C program descriptors. The types of descriptors include: Device Descriptors Configuration Descriptors Interface Descriptors Endpoint Descriptors String Descriptors...
Page 98
How Does the Host Know a Device’s Requirements? This hierarchy of the most commonly used descriptors looks like this: Device Descriptor Configuration Configuration Descriptor Descriptor Interface Interface Interface Interface Descriptor Descriptor Descriptor Descriptor Endpoint Endpoint Endpoint Endpoint Endpoint Endpoint Endpoint Endpoint Descriptor Descriptor...
Page 99
How Does the Host Know a Device’s Requirements? //------------------------------------------------------------ Device Descriptor // Sample Standard Device Descriptor Type // Definition Fields //------------------------------------------------------------ Length (18 bytes) Since the device descriptor Descriptor Type (DEVICE) USB Spec Release Number (0200h) represents the entire device, Device class (hub type…Human Interface defined in there can be only one per other descriptor, CDC described here)
Page 100
How Does the Host Know a Device’s Requirements? Configuration //------------------------------------------------------------ Descriptor // Sample Standard Configuration Descriptor Type // Definition Fields //------------------------------------------------------------ The configuration descriptor is a Length (9 bytes) header to the interface descriptors. It Descriptor Type (CONFIGURATION) Total Length (total length in bytes of data returned) specifies how this configuration of the Number of Interfaces (number of interfaces present for this configuration)
How Does the Host Know a Device’s Requirements? //------------------------------------------------------------ // Sample Standard Interface Descriptor Type // Definition Fields Interface //------------------------------------------------------------ Descriptor Length (9 bytes) Descriptor Type (INTERFACE) Interface Number (interface number, zero based, and incremented once for each new interface descriptor.) Alternate Setting (value used to select alternative setting) Number of Endpoints (number of Endpoints used for...
Page 102
How Does the Host Know a Device’s Requirements? Endpoint Descriptor //------------------------------------------------------------ // Sample Standard Endpoint Descriptor Type // Definition Fields The endpoint descriptors define //------------------------------------------------------------ what transfer type to use, the Length (7 bytes) Descriptor Type (ENDPOINT) maximum packet size and time End Point Address (indicates what endpoint this descriptor is describing) interval used to poll the frames...
Page 103
How Does the Host Know a Device’s Requirements? Device Descriptor Configuration Configuration Descriptor Descriptor Interface Interface Interface Interface Descriptor Descriptor Descriptor Descriptor Endpoint Endpoint Endpoint Endpoint Endpoint Endpoint Endpoint Endpoint Descriptor Descriptor Descriptor Descriptor Descriptor Descriptor Descriptor Descriptor Upon detecting a USB device connection the host, using these descriptors, configures the device and loads the proper driver program.
Page 104
The Enumeration Process: What happens when a device is connected? Enumeration -Upon powering up, the host: queries all connected devices to determine the requirements of each (such as, class of device power source, number and types of endpoints) and assigns a unique address for each.
Page 105
The Enumeration Process: What happens when a device is connected? Host What device class are you? Here is your unique address. Do you supply the power or do I? What transfer mode do you want? How many and of what type of endpoints do you need? There are 4 types of data transfer:...
Page 106
The Enumeration Process: What happens when a device is connected? Host //------------------------------------------------------------ // 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)
Page 107
The Enumeration Process: What happens when a device is connected? Transfer Mode - The host then determines which type of transfer each device requires. There are three transfer modes: Interrupt Transfer - Devices that send very little data such as mice or keyboards would choose this type of transfer.
Page 108
The Enumeration Process: What happens when a device is connected? As the host enumerates each device it sets aside bandwidth for the devices that use the interrupt and isochronous transfer modes Interrupt transfer mode and keeps track of the total bandwidth used. These two transfer modes can use up to 90% of the total bandwidth.
Page 109
The Enumeration Process: What happens when a device is connected? 5. The available bandwidth is then divided into frames, and the host controls those frames which contain 1,500 bytes. Every millisecond a new frame begins. Within the frame, slots are reserved for isochronous and interrupt devices (up to 90%) so that they are guaranteed the bandwidth they need.
Page 110
Frames in More Detail Control, Interrupt, Bulk, Token Data Handshake Isochronous Transfer 1 Transfer 2 Transfer N Transfer 1 Transaction Transaction 1 Transaction 2 Transaction 3 Transaction 1 Transaction … 1 Ms Frame Transfers may span multiple frames. Each frame begins with a Start of The host schedules Frame packet followed by the transactions within 1mS...
Page 111
Packets in More Detail Packets are a 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. If you were to monitor D+ and D- you would see the packet fields: Packet Identifier Field Address...
Page 112
Packets Associated with Each Type of Transfer Transfer Type Stages (Transactions) Phases (Packets) Token Control Setup Data Handshake Token Data (IN or OUT) (optional) Data Handshake Status (IN or OUT) Token Data Handshake Token Bulk Data (IN or OUT) Data Handshake Interrupt Data (IN or OUT)
Page 113
• USB uses Non-Return to Zero, Inverted signaling – Separate clock signal not required to be delivered with data – ‘1’ on the data line indicates no change in level of NRZI signal – ‘0’ on the data line indicates transition in level of NRZI signal –...
Page 114
After enumeration the device is ready to perform the function it was designed for. It does so by issuing a set of properly sequenced API calls. Definition: Application Program Interface (API): A formalized set of firmware calls and routines that can be referenced by an application program to access driver functions.
Page 115
Commonly used API calls for host devices: •host_init() - Initialize the host controller •host_stop() - Disable the host controller •host_reset_bus() - Reset the USB bus and all connected devices •host_send_control() - Send configuration info •host_receive_control() - Get config info •host_send() - Send data on USB channel •host_receive() - Get data on USB channel...
Page 117
Note to reviewers…. what happens behind the scenes (after enumeration) between the host and device driver etc. (e.g., the host automatically polling the devices for data, receiving the data, and returning the status code, etc.) …….needs to go here.
Page 118
Note to reviewers….A short introduction to the demos should go here.
Page 119
Note to reviewers….Here should be a short discussion of what the programmer would have to do to modify the code in the Demo Kit or CMX Offerings for their specific device….e.g. they may just need to modify some descriptors and API calls.
Page 120
Introduction to USB Freescale and CMX have collaborated to provide a complimentary USB stack for ColdFire Microcontrollers Complimentary SW for the •Host HID Drivers MCF522xx Family of –Generic HID Microcontrollers: –HID keyboard –HID mouse •USB Basic Device Controller –HID joystick •HID device layer for the USB driver Host Mass Storage –...
Page 121
Introduction to USB These additional stacks are available for purchase from CMX USB Device Reviewers: Please update the delivery schedules here •Reliable Bootloader •Embedded Pipe •Mass Storage (for attached SD card or similar) •FAT file System (for attached SD card or similar) USB Host •FAT file System...
Page 122
Introduction to USB Appendix A USB On-the-Go...
USB On-the-Go: Introduction to USB What is it? Remember that previously we said that USB: 1. can be implemented as a device or a host 2. there can be only one host but many devices 3. and the host controls the devices. Host Device Device...
Page 124
USB On-the-Go: Introduction to USB What is it? By 2001, there was a proliferation of peripheral devices that could be interconnected and pass data to each other. Because of this interaction of peripheral devices, the USB Group saw the need for a USB device to sometimes act as a device and sometimes act as the host.
Page 125
USB On-the-Go: Introduction to USB What Applications would use it? Same OTG Device OTG Device in in host mode Peripheral mode Above is a typical applications that would use USB On-the-Go. On the left laptop is acting as the host controlling the flow of data to the camera phone and on the right the camera phone is acting as the host controlling the flow of data to the printer.
Page 126
USB On-the-Go: Introduction to USB How does it work? To implement OTG, two new protocols were added in the USB 2.0 addendum. These new protocols allow USB OTG host wake-up and role reversal respectively. They are: SRP = Session Negotiation Protocol HNP = Host Negotiation Protocol SRP introduces these new/expanded states: OTG-A device:...
Page 127
USB On-the-Go: Introduction to USB Initial declaration When using A and B plugs, initially the device using the A plug is declared the host and the one using the B plug is declared the device. When using the mini-AB receptacle the ID plug pin declares the initial state of a device as host or device.
Page 128
USB On-the-Go: Introduction to USB Negotiation process SRP (Session Request Protocol) Negotiations OTG-B (device) asks OTG-A (host) for a USB OTG session by signaling in one of two ways: • Pulsing an analog data line (D+ or D-), and • Pulsing V through a relatively high impedance ( >...
Page 129
USB On-the-Go: Introduction to USB Negotiation process HNP (Host Negotiation Protocol): OTG-A (host) enables OTG-B (device) to become host by sending SetFeature (b_hnp_enable) command to OTG-B (device). OTG-A (host) suspends bus signaling so that OTG-B (device) can now become host. OTG-B (device) detects Suspend condition and turns off pull-up resistor.
Page 130
USB On-the-Go: Introduction to USB Negotiation process Host Negotiation Protocol continued: To return control back to OTG-A (host) , OTG-B (device) stops using bus and becomes peripheral/device. OTG-A (host) sees lack of activity, disconnects and becomes host. Note: If the OTG-B (device) does not STALL the SetFeature(b_hnp_enable) command, the OTG-A (host) must give the OTG-B (device) an opportunity to become host before the OTG-A (host) may turn off...
Page 133
The USB Controller Continuum. Only from Freescale. RS08 ColdFire V1 ColdFire V2 ColdFire V3 ColdFire V4 8-bit 32-bit • USB is becoming the standard in Consumer and Industrial applications • Designers want a “one stop shop” USB solution. Freescale provides a complete USB solution to help you ►...
Page 134
“A panel of distinguished judges, representing a cross section of Chinese industry and academic specialists, plus EDN China’s editorial board, narrowed the list of award finalists from the total submitted. The award was decided by votes from readers and registered users of EDN China. ” •...
Page 135
USB Solutions (Low/Full Speed, Device, Host, OTG) MC9S08JS16/8...
Page 136
MCF52259 USB features • Dual Mode USB Controller • USB 1.1 and 2.0 complient full speed device controller • 16 bi-directional end points • DMA or FIFO data stream interface • Low power consumption • OTG protocol logic...
Page 140
LAB1 – HID ( Human interface device) • In this Lab the MCF52259 board (USB) will control the PC curser. • Install the “Coldfire_USB_Lite.exe” file, • This Exe will install the required project files for our Labs. • Open the codewarrior for Coldfire. - GO through the code warrior features •...
Page 141
Project file - HID Drag the *.mcp file to code warrior...
Page 149
Output of the Lab • Insert the USB Cable to MiniA connector on the peripheral board and other side to your system USB port. • Reset the board. • Look at the curser on your system, it should be oscillating.
Page 151
LAB2-CDC • This LAB will demonstrate the USB to serial and visa versa communication. • Open the project file from the installed folder. – D:\Profiles\r63554\Desktop\USB for MCF52259\usb-peripheral\projects\CodeWarrior\mcf52223\cdc- demo • Follow the Steps which we have followed in the LAB1 for flash programming. •...
Page 152
PC side drive file installation Driver file installation Choose the second option...
Page 155
COM Port at System side USB commport number Step1 – device manager...
Page 156
Hyper terminal for USB • Open the Hyper terminal • Select the USB port. • Set the baud rate -19200 • Data bit -8 • Parity -None • Stop bit- NO...
Page 157
Hyper terminal for UART • Open one more Hyper Terminal • Set the Baud rate 19200 • Type the character in one terminal, This shold be displayed in other terminal and visa versa.
Page 160
LAB3 – MSD(HOST) • In this LAB will achieve reading and writing to thumb drive. This will demonstrate the Host functionality. • Open the Lab from the Installed folder. • D:\Profiles\r63554\Desktop\USB for MCF52259\usb- host\projects\CodeWarrior\mcf52223\mass-storage • Follow the same steps followed in LAB2 for flash programming. •...