USB Component  Version 6.12.0
MDK Middleware for USB Device and Host Communication
 All Data Structures Functions Variables Enumerations Enumerator Groups Pages
USB Communication

USB is a polled bus, where the USB Host initiates all data exchanges. The data travels to or from Endpoints in an USB Device. The client in the USB Host stores data in buffers, but does not have endpoints. The USB Host and the peripheral USB Device have distinct layers, as shown in the picture below. The connections between the layers are logical Host-Device interfaces between each horizontal layer. Between the logical connections data is transferred using Pipes.

Logical Connections Between USB Host Clients and USB Device Endpoints


Basically, two types of pipes exist:

  • Message pipes have a defined USB format and are host controlled. Message pipes allow data to flow in both directions and support Control Transfers only.
  • Stream pipes have no defined USB format and can either be controlled by the host or by the device. The data stream has a predefined direction, either IN or OUT. Stream pipes support Interrupt Transfers, Isochronous Transfers, and Bulk Transfers.

Most pipes come into existence when an USB Device has been connected to the USB Bus and configured by the USB Host. A pipe originates from a data buffer within the host client and terminates inside the USB Device at an Endpoint.


Transfers (data flow types) can consist of one or more transactions. A pipe supports only one of the following transfer types:

  • Control Transfers are typically used to setup an USB device. They always use IN/OUT Endpoint 0.
  • Interrupt Transfers can be used where data is sent regularly, for example for status updates.
  • Isochronous Transfers transmit real-time data such as audio and video. They have a guaranteed, fixed bandwidth, but no error detection.
  • Bulk Transfers can be used to send data where timing is not important, for example to a printer.


Endpoints can be described as data sources or sinks and exists in USB Devices only. The data stored at an endpoint may either be received from or waiting for being sent to the USB Host. An endpoint can be configured to support four transfer types defined in the USB specification (Control Transfers, Interrupt Transfers, Isochronous Transfers, and Bulk Transfers). Within the limits of the hardware, endpoints can be configured using the USB Middleware (e.g. limit an endpoint to a certain transfer type).
An endpoint acts as a kind of buffer. A USB Host's client may send data to Endpoint 1 for example. Coming from the USB Host, the data will be sent to the OUT Endpoint 1. The program on the microcontroller will then read the data as soon as it is ready to do so. Returning data has to be written to the IN Endpoint 1, as the program cannot access the USB bus freely (the USB bus being controlled by the USB Host). The data in IN Endpoint 1 stays there until the host sends an IN packet to Endpoint 1 requesting the data.

These rules apply to all microcontroller devices:

  • A device can have up to 16 OUT and 16 IN endpoints.
  • Each endpoint can have only one transfer direction.
  • Endpoint 0 is used for control transfers only and can not be assigned to any other function.
  • OUT always refers to the direction pointing from the host to the device.
  • IN always refers to the direction pointing towards the host.
The total number of endpoints and the capability of each endpoint is defined by the underlying hardware. Please consult the hardware reference manual of your microcontroller.