USB Device using STM32
What is a universal synchronous bus USB?
USB was designed to standardize the connection of peripherals to personal computers, both to communicate with and to supply electric power. It has largely replaced interfaces such as serial ports and parallel ports and has become commonplace on a wide range of devices.
Examples of peripherals that are connected via USB include computer keyboards and mice, video cameras, printers, portable media players, mobile (portable) digital telephones, disk drives, and network adapters.
USB connectors have been increasingly replacing other types as charging cables of portable devices.
USB 1.x:
Released in January 1996, USB 1.0 specified signalling rates of 1.5 Mbit/s (Low Bandwidth or Low Speed) and 12 Mbit/s (Full Speed).
USB 2.0:
The USB2.0 supports three speeds:
- Low speed (LS): supports the transfer rate of 1.5 Mb/s. This speed is mainly dedicated to interactive devices (such as mouse, keyboards)
- Full speed (FS): supports the transfer rate of 12 Mb/s. This speed is mainly dedicated to phone and audio devices (such as microphones, speakers)
- High speed (HS): supports the transfer rate of 480 Mb/s. This speed is mainly dedicated to video and storage devices (such as printers, cameras).
| Connectors | USB 1.0 1996 | USB 1.1 1998 | USB 2.0 2001 | USB 2.0 Revised | USB 3.0 2008 | USB 3.1 2014 | USB 3.2 2017 | USB4 2019 | ||
|---|---|---|---|---|---|---|---|---|---|---|
| Data rate | 1.5 Mbit/s (Low Speed) 12 Mbit/s (Full Speed) | 1.5 Mbit/s (Low Speed) 12 Mbit/s (Full Speed) 480 Mbit/s (High Speed) | 5 Gbit/s (SuperSpeed) | 10 Gbit/s (SuperSpeed+) | 20 Gbit/s (SuperSpeed+) | 40 Gbit/s (SuperSpeed+, Thunderbolt 3 and 4) | ||||
| Standard | A | Type A | Type A | Deprecated | ||||||
| B | Type B | Type B | Deprecated | |||||||
| C | N/A | Type C (enlarged) | ||||||||
| Mini | A | N/A | Mini A | Deprecated | ||||||
| B | Mini B | |||||||||
| AB | N/A | Mini AB | ||||||||
| Micro | A | N/A | Micro A | Micro A | Deprecated | |||||
| B | N/A | Micro B | Micro B | Deprecated | ||||||
| AB | N/A | Micro AB | Micro AB | Deprecated | ||||||
| Connectors | USB 1.0 1996 | USB 1.1 1998 | USB 2.0 2001 | USB 2.0 Revised | USB 3.0 2011 | USB 3.1 2014 | USB 3.2 2017 | USB4 2019 | ||
USB Topology:
A maximum of 127 devices (functions or hubs) can be connected to one host (root hub) with a maximum of 5 hubs connected in series.
Detecting a Device has been Connected:
Determining the Device Speed :
- Toggle the voltage value for 0
- Keep the voltage value for 1
From being completely detached until being completely recognized by the USB Host and ensuring its function, the USB device goes through consecutive stages:
- Attached: it is the stage when the device is physically connected to the USB host but not yet powered. This stage is mainly ensured by hardware.
- Powered: it is the second stage and is corresponding to a device that was attached to USB Host and just powered. This stage is mainly ensured by hardware.
- Default: this stage is reached when the attached device is powered then reset by the host. This stage is assigned to the device by its software each time the device is newly attached then powered then reset or an old attached device received a reset. At this stage, the USB Device operates with convenient speed (selected by hardware during reset) and has the default address which is the address number 0.
- Addressed: after going through all the previous stages, the USB device reaches this state by receiving its unique address (different from 0) from the host. This stage is reached after the correct process of the host request by the device software.
- Configured: the device reaches this stage after receiving the convenient request from the host with a non-zero configuration number. This stage is reached after the correct process of the host request by the device software.
- Suspended: the device must enter this stage if there is no data on the traffic for a known period that depends on the speed. In fact, the host forces the device to enter this state electrically depending on its speed. When detecting this electrical indication, the USB device software must change its state into suspended.
Generally, the host (root hub) provides power for functions direct connection. Some hubs may supply power for directly connected downstream functions. For the functions, there are two types:
- Bus powered functions: these devices rely totally on the bus power coming from the upstream hub.
- Self powered functions: these devices are capable of providing their own power independently from the bus.
The USB communication is based on four main transfer types:
- Control transfer: used for the configuring of the newly attached device.
- Bulk transfer: used for large amounts of data transmission or reception.
- Interrupt transfer: used for limited data transmission with minimal latency.
- Isochronous transfer: used for data transfer with real-time requirements.
It is a source or destination data buffer that must be implemented on the device side. Each amount of data that is received from or sent to the host will be placed into an endpoint. Each endpoint is uniquely characterized by a number and direction which means that for a given number, there is a unique pair of endpoints of the same type and number but each one deals with the data of only one direction:
- IN Endpoint for data that will be transferred into the host.
- OUT Endpoint for data that will be transferred from the host.
A device has always more than one endpoint pair identified by their numbers:
- Endpoint zero: it is a pair of OUT and IN endpoints dedicated for control data transfers which means it is a control endpoint. It is required to establish the first communication transfers between the host and the device while the other endpoints are not yet configured.
- Other endpoints: will be configured after negotiation between the host and the device. Each endpoint is independent from the other and can handle a different transfer type.
- Each device/host has multiple endpoints
- The endpoint is a virtual communication channel between device and host
- Each endpoint can have a different type of USB transaction
- SETUP
- BULK
- Interrupt
- Isochronous
- Endpoint 0 is reserved for enumeration & configuration of the USB device
- Max. 16 Endpoints (bidirectional), depends on HW
Packet Structure
The USB peripheral implements an interface between a full-speed USB 2.0 bus and the APB1 bus.USB suspend/resume are supported which allows to stop the device clocks for low-power consumption.
USB main features
- USB specification version 2.0 full-speed compliant
- Configurable number of endpoints from 1 to 8
- Cyclic redundancy check (CRC) generation/checking, Non-return-to-zero Inverted (NRZI) encoding/decoding and bit-stuffing
- Isochronous transfers support
- Double-buffered bulk/isochronous endpoint support
- USB Suspend/Resume operations
- Frame locked clock pulse generation




Comments
Post a Comment