Usb 2.o
Usb 2.o
The
host can send the data and receive the data from the buffer.
USB device can have max 32 endpoints.(16 IN and 16 OUT).
Since EP0 IN and EP0 OUT are set aside as control endpoints.
The maximum endpoints available to transmit the data.
Endpoint uses to check the CRC’S and to detect errors in
transactions.
Endpoints are of 4types :-
Control endpoint
Interrupt endpoint
Bulk endpoint
Isochronous endpoint.
Endpoint Transfer Type Features
USB Communication Protocol
HAND
TOKEN PACKET DATA PACKET SHAKE
PACKET
Types of packets
Token packets
Data packets
Hand shacking packets
Special packets
Token packets
Token packets are four types they are
IN : IN token packet are used to request the data from the device.
OUT : OUT token packet are used to transfer the data to the device.
Setup : SETUP Token packet are used to send the commands.
SOF : SOF token packet are used to mark the frames.
With an IN,OUT, SOF and SETUP token packets there is a 7-bit device
address ,4-bit endpoint ID and 5-bit CRC
DATA Packets
Data packet follows IN ,OUT and SETUP token packets.
The packet ID toggles between DATA0 and DATA1 for each successful data packet
transfer ,and the packet closes with the 16-bit CRC.
The data field can carry 0- 1023 bytes of data.
Data must be always sent in multiple of bytes.
For low speed devices, maximum data field is of 8bytes.
For full speed devices, maximum data field is of 1023bytes.
For high speed devices, maximum data field is of 1024bytes
The data toggle is updated at the host and device for each successful data packet
transfer.
One advantage to the data toggle is acts as an additional error detection method .
If a different packed ID is received then than what is expected ,the device also to
be know there was an error in the transfer and it can be handled appropriately. An
example where the data toggle is used is if an ACK is sent but not received.
Handshake Packets
Handshake packets conclude each transaction.
Each handshake includes an 8-bit packet ID
and is sent by the receiver of the transaction.
Each USB speed has several options for a
handshake response. Which ones are
supported depend on the USB speed:
ACK: Acknowledge successful completion.
(LS/FS/HS)
NAK: Negative acknowledgement. (LS/FS/HS)
STALL: Error indication sent by a device.
(LS/FS/HS)
NYET: indicates the device is not ready to
receive another data packet. (HS Only).
Special Packets
The USB specification defines four
special packets.
PRE: Is issued to hubs by the host to
indicate that the next packet is low
speed.
SPLIT: Precedes a token packet to
indicate a split transaction. (HS Only)
ERR: Returned by a hub to report an
error in a split transaction. (HS Only)
PING: Checks the status for a Bulk
OUT or Control Write after receiving a
NYET handshake (HS Only).
USB Descriptors
A Descriptor contains information like type of the device, Vendor
ID, Compliant USB Version, number of configurations device
supports, number of endpoints, etc. The USB peripheral must
respond with descriptors when requested by the host. During
enumeration, the host uses control transfer to request the device
for descriptors.
Descriptors types :-
Device Descriptors
Configuration Descriptors
Interface Descriptors
Endpoint Descriptors
String Descriptors
Example Full-Speed USB Device Descriptors
/*********************************************************************
Device Descriptors
*********************************************************************/
uint8 CYCODE USBFS_1_DEVICE0_DESCR[] =
{ /* Descriptor Length
/* Descriptor Type: DEVICE
/* bcdUSB (Ver 2.0)
/* bDeviceClass
/* bDeviceSubClass
/* bDeviceProtocol
/* bMaxPacketSize0
/* idVendor
/* idProduct
/* bcdDevice
/* iManufacturer
/* iProduct
/* iSerialNumber
/* bNumConfigurations
};
Configuration Descriptor
/*********************************************************************
Config Descriptor
*********************************************************************/
uint8 CYCODE USBFS_1_DEVICE0_CONFIGURATION0_DESCR[] = {
/* Config Descriptor Length
/* Descriptor Type: CONFIG
/* wTotal Length
/* bNum Interfaces
/* bConfiguration Value
/* iConfiguration
/* bm Attributes
/* bmaxpower
};
/*********************************************************************
Interface Descriptor
/*********************************************************************
Interface Descriptor
*********************************************************************/
/* Interface Descriptor Length
/* Descriptor Type: INTERFACE
/* bInterface Number
/* bAlternate Setting
/* bNum Endpoints
/* bInterfaceClass
/* bInterface Subclass
/* Protocol
/* iInterface
/********************************************************************
Endpoint Descriptor
/*********************************************************************
Endpoint Descriptor *********************************************************************/
/* Endpoint Descriptor Length
/* DescriptorType: ENDPOINT
/* bEndpointAddress
/* bmAttributes
/* wMaxPacketSize
/* bInterval
};
/********************************************************************
String Descriptor
/*********************************************************************
String Descriptor: "USB Example"
*********************************************************************/
/* Descriptor Length */ 0x18u,
/* Descriptor Type: STRING */ 0x03u,
'U', 0,'S', 0,'B', 0,' ', 0,'E', 0,'x', 0,'a', 0,'m', 0,'p', 0,'l', 0 ,'e', 0,
/*********************************************************************/
/* Marks the end of the list. */ 0x00u
};
/*********************************************************************/
USB Enumeration and Configuration