Trusted answers to developer questions

USB data transfer and packets

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

Every USB setup has only one host that connects to multiple USB devices or clients through the host controller. It is also the host controller that manages data transfers between the host and USB devices (from the host to the device and vice versa).

When you attach a device to a USB system, it gets assigned a unique address at the time it was connected. The USB device has endpoints, or data buffers, and each endpoint has a pipe where the transfer of data between the USB device and the USB host happens.

Now, USB data is transmitted in packets that are then bundled or grouped into frames to complete a message. In the transmission of data, where it is broken into bytes and bits, the least significant bit always goes out first.

There are four main types of packets:

  • The token packet contains the packet identifier byte (PID) and specifies the address and endpoint. Only the host can send tokens that will inform the USB device where the host wants to read or send information.
  • The data packet contains the actual intended message with the length depending on the data.
  • The handshake packet holds the status of a data transfer as ACK, NAK, NYET, and STALL. It essentially signals whether or not the transfer is successful.
  • The start-of-frame (SOF) packet indicates the start of a new frame that is sent every one millisecond. Frames, as noted earlier, will have resulted in a complete USB message.
widget

USB mass storage

USB drives offer to store large amounts of data in removable, portable, and durable (sometimes aesthetically appealing) solutions. You surely have ways to access, save, and send files online, but you always have USB flash drives to virtually back up all kinds of electronic files.

  • USB mass storage device class refers to the software or set of communication protocols that allow you to view the contents of your USB memory stick when you insert it into your computer. A device that has a USB interface is accessible by a host or computer, which treats it as an external hard drive.
  • Leading examples of devices that adopt this specification include, but are not limited to, USB flash drives, external hard drives, external CD/DVD optical drives, external solid-state drives (SSDs), digital cameras, portable audio players, and mobile phones.

RELATED TAGS

usb
storage
packet
data transfer

CONTRIBUTOR

Jamie Powell
Attributions:
  1. undefined by undefined
Did you find this helpful?