Future Technology Devices International Ltd. Technical Note TN_116 USB Data Packet Structure Document Reference No.: FT_000200 Version 1.0 Issue Date: 2009-11-11 The intention of this technical note is to give a brief overview of the construction and format of a USB message packet. Future Technology Devices International Limited (FTDI) Unit1, 2 Seaward Place, Centurion Business Park, Glasgow G41 1HH United Kingdom Tel.: +44 (0) 141 429 2777 Fax: + 44 (0) 141 429 2758 E-Mail (Support): [email protected] Web: http://www.ftdichip.com Copyright © 2008 Future Technology Devices International Limited Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 TABLE OF CONTENTS 1 Introduction............................................................................................ 2 2 USB Speed ............................................................................................. 3 3 USB DATA FORMAT .............................................................................. 4 4 USB Data States .................................................................................... 5 5 Fields ...................................................................................................... 6 6 5.1 Sync Field............................................................................................................. 6 5.2 Packet Identifier Field ......................................................................................... 6 5.3 Address Field ....................................................................................................... 6 5.4 Endpoint Field...................................................................................................... 6 5.5 Data Field ............................................................................................................. 6 5.6 CRC Field ............................................................................................................. 7 5.7 EOP Field.............................................................................................................. 7 USB Packets .......................................................................................... 8 6.1 USB TOKEN Packets ........................................................................................... 8 6.2 USB DATA Packets ............................................................................................. 8 6.3 USB Handshake Packets .................................................................................... 8 6.4 USB Start of Frame Packets ............................................................................... 8 7 How FTDI Help ....................................................................................... 9 8 Contact Information............................................................................. 10 Appendix A – Terminology ....................................................................... 12 Appendix B – References.......................................................................... 13 Appendix C – Revision History ................................................................. 14 Copyright © 2009 Future Technology Devices International Limited 1 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 1 Introduction Many devices on the market today connect via the USB interface. This technical note will attempt to explain the protocol used for data transfers between USB hosts and USB devices. Copyright © 2009 Future Technology Devices International Limited 2 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 2 USB Speed There are 3 speed USB grades currently on the market: Slow speed – 1.5Mbps Full speed – 12Mbps High speed – 480mbps A 4th class specification – super speed at 4.8Gbps has now been ratified, which should result in even faster devices coming to the market soon. Copyright © 2009 Future Technology Devices International Limited 3 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 3 USB DATA FORMAT USB data is sent in packets Least Significant Bit (LSB) first. There are 4 main USB packet types :Token, Data, Handshake and Start of Frame. Each packet is constructed from different field types, namely SYNC, PID, Address, Data, Endpoint, CRC and EOP. The packets are then bundled into frames to create a USB message. Copyright © 2009 Future Technology Devices International Limited 4 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 4 USB Data States The USB data is transferred on a differential serial line (USB DP and USB DM), using NRZI coding. Many documents refer to the J and K states on the USB data lines. These are used for USB packet synchronisation and defining the end of USB packets. A J state has a differential signal on USB DP and USB DM >= +300mV. A K state has a differential signal on USB DP and USB DM >= -300mV. A Single Ended Zero (SE0) is where both USB DM and USB DM are at 0V. Copyright © 2009 Future Technology Devices International Limited 5 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 5 Fields Fields are the building blocks of a USB packet. These describe the data at individual bit level. 5.1 Sync Field Each USB packet starts with a SYNC field. This is basically used to synchronise the transmitter and the receiver so that the data can be transferred accurately. In a USB slow / full speed system this SYNC field consists 3 KJ pairs followed by 2 K’s to make up 8 bits of data. In a USB Hi-Speed system the synchronisation requires 15 KJ pairs followed by 2 K’s to make up 32 bits of data. 5.2 Packet Identifier Field Following on directly after the SYNC field is the Packet Identifier Field. The Packet Identifier Field consists of a 4 bit identifier and a further 4 bits which are the one’s compliment of the identifier. PID0 PID1 Figure 5.2: PID Field. PID2 PID3 /PID0 /PID1 /PID2 /PID3 5.3 Address Field The address field is 7 bits long. It is used with the endpoint field to address a function. Address 0 is a special case reserved for access immediately after power up and reset. ADDR0 ADDR1 Figure 5.3: Address Field. ADDR2 ADDR3 ADDR4 ADDR5 ADDR6 5.4 Endpoint Field The endpoint field is 4 bits long and allows for additional flexibility in addressing. Endpoints are usually split for data going IN or OUT. Endpoint 0 is a special case referred to as the CONTROL endpoint and every device has an endpoint 0. EP0 EP1 EP2 Figure 5.4: Endpoint Field. EP3 5.5 Data Field The data field is not a fixed length. It is within the range of 0 - 8192 bits long, and always an integral number of bytes. Copyright © 2009 Future Technology Devices International Limited 6 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 5.6 CRC Field There are two CRC fields. The CRC5 is 5 bits long and used with the token packet and the start of frame packet. CRC0 CRC1 Figure 5.6.1: CRC5 Field CRC2 CRC3 CRC4 The CRC16 is 16 bits long and used with the data packet. CRC CRC CRC CRC 0 1 2 3 Figure 5.6.2: CRC16 Field CRC 4 CRC 5 CRC 6 CRC 7 CRC 8 CRC 9 CRC 10 CRC 11 CRC 12 CRC 13 CRC 14 CRC 15 These fields are used for cyclic redundancy checking, that is they are used for error detection 5.7 EOP Field Each packet is terminated with an End of Packet (EOP) field. This consists of a single ended zero (SE0) for two bit times followed by a J for 1 bit time. Copyright © 2009 Future Technology Devices International Limited 7 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 6 USB Packets 6.1 USB TOKEN Packets The USB token packet is used to access the correct address and endpoint. It is constructed with the SYNC, PID, an 8 bit PID field, followed by a 7 bit address, followed by a 4 bit endpoint and a 5 bit CRC. FIELD SYNC #BITS 8/32 Figure 6.1: TOKEN Packet. PID 8 ADDRESS 7 ENDPOINT 4 CRC5 5 EOP 3 Both the address and endpoint field must be correctly decoded for correct operation. 6.2 USB DATA Packets The data packet may be of variable length, dependent upon the data. However, the data field will be an integral number of bytes. FIELD SYNC #BITS 8/32 Figure 6.2: DATA Packet. PID 8 DATA 0-8192 CRC16 16 EOP 3 6.3 USB Handshake Packets Handshake packets are used to signal the status of a transaction ie pass/fail. FIELD SYNC #BITS 8/32 Figure 6.3: Handshake Packet. PID 8 EOP 3 6.4 USB Start of Frame Packets To complete a full message the packets are grouped into frames. To identify the frame you need a Start of Frame packet (SOP). The frame number is 11 bits long. FIELD SYNC PID #BITS 8/32 8 Figure 6.4: Start of Frame Packet. Frame Number 11 CRC5 5 EOP 3 The start of frame packet is sent every 1ms on a USB full speed system to help synchronisation. On a USB Hi-Speed peed system a packet frame is transferred every 125us, resulting in 8 packets every 1ms. These 8 sub frames all contain the same frame number. Copyright © 2009 Future Technology Devices International Limited 8 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 7 How FTDI Help The construction of a USB message is not trivial as can be seen from the previous chapters. FTDI silicon handles this packet construction and deals with the USB protocol within the FTDI ICs. There is no need for a user to create drivers or software to encode or decode a USB message. It is all done for the designer, thus reducing development time and costs. For a complete listing of FTDI products please visit the website at: http://www.ftdichip.com/FTProducts.htm Copyright © 2009 Future Technology Devices International Limited 9 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 8 Contact Information Head Office – Glasgow, UK Future Technology Devices International Limited Unit 1, 2 Seaward Place, Centurion Business Park Glasgow G41 1HH United Kingdom Tel: +44 (0) 141 429 2777 Fax: +44 (0) 141 429 2758 E-mail (Sales) [email protected] E-mail (Support) [email protected] E-mail (General Enquiries) [email protected] Web Site URL http://www.ftdichip.com Web Shop URL http://www.ftdichip.com Branch Office – Taipei, Taiwan Future Technology Devices International Limited (Taiwan) 2F, No 516, Sec. 1 NeiHu Road Taipei 114 Taiwan, R.O.C. Tel: +886 (0) 2 8797 1330 Fax: +886 (0) 2 8751 9737 E-mail (Sales) [email protected] E-mail (Support) [email protected] E-mail (General Enquiries) [email protected] Web Site URL http://www.ftdichip.com Branch Office – Hillsboro, Oregon, USA Future Technology Devices International Limited (USA) 7235 NW Evergreen Parkway, Suite 600 Hillsboro, OR 97123-5803 USA Tel: +1 (503) 547 0988 Fax: +1 (503) 547 0987 E-Mail (Sales) [email protected] E-Mail (Support) [email protected] Web Site URL http://www.ftdichip.com Branch Office – Shanghai, China Future Technology Devices International Limited (China) Room 408, 317 Xianxia Road, ChangNing District, ShangHai, China Tel: +86 (21) 62351596 Fax: +86(21) 62351595 E-Mail (Sales): [email protected] E-Mail (Support): [email protected] E-Mail (General Enquiries): [email protected] Web Site URL: http://www.ftdichip.com Copyright © 2009 Future Technology Devices International Limited 10 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 Distributor and Sales Representatives Please visit the Sales Network page of the FTDI Web site for the contact details of our distributor(s) and sales representative(s) in your country. Neither the whole nor any part of the information contained in, or the product described in this manual, may be adapted or reproduced in any material or electronic form without the prior written consent of the copyright holder. This product and its documentation are supplied on an as-is basis and no warranty as to their suitability for any particular purpose is either made or implied. Future Technology Devices International Ltd will not accept any claim for damages howsoever arising as a result of use or failure of this product. Your statutory rights are not affected. This product or any variant of it is not intended for use in any medical appliance, device or system in which the failure of the product might reasonably be expected to result in personal injury. This document provides preliminary information that may be subject to change without notice. No freedom to use patents or other intellectual property rights is implied by the publication of this document. Future Technology Devices International Ltd, Unit 1, 2 Seaward Place, Centurion Business Park, Glasgow G41 1HH United Kingdom. Scotland Registered Number: SC136640 Copyright © 2009 Future Technology Devices International Limited 11 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 Appendix A – Terminology CRC Cyclic Redundancy Check EOP End of Packet FTDI Future Technology Devices International PID Product Identifier Field SE0 Single ended Zero USB Universal Serial Bus Copyright © 2009 Future Technology Devices International Limited 12 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 Appendix B – References USB Implementers Forum – www.usb.org USB Specification - http://www.usb.org/developers/docs/usb_20_052709.zip Copyright © 2009 Future Technology Devices International Limited 13 Document Reference No.: FT_000200 USB Data Packet Structure Version 1.0 Clearance No.: FTDI# 128 Appendix C – Revision History Version Draft First Draft Version 1.0 First Release 30/09/2009 11/11/2009 Copyright © 2009 Future Technology Devices International Limited 14