The developer's resource for computer interfacing, especially USB, serial (COM) ports, mass storage, and embedded networking. (Formerly Lvr.com)

Home > USB Mass Storage > From the Introduction

USB Mass StorageUSB Mass Storage

From the Introduction

A USB device controller enables a mass-storage device to share its data with other computers. For example, a data logger can collect data in the field and then connect to a PC, where an application reads the data from the logger’s storage media. Or a robot can attach to a PC to receive a file containing configuration data to use in robotic tasks.

Flash-memory cards provide convenient storage for many small systems. Other systems function as USB hosts that can access files in off-the-shelf USB flash drives and hard drives.

If you’re involved with designing or programming devices that incorporate a USB mass-storage device or host interface, this book will help you get your projects up and running. You’ll also find the book useful if you’re designing or programming devices that use flash-memory cards for data storage, whether or not the devices have USB interfaces.

Interfaces, Protocols, and Technologies

Designing and programming a USB mass-storage device or embedded USB host involves a variety of interfaces, protocols, and structures.

Every USB mass-storage device must support two interfaces:

A USB device interface to enable the device to communicate with a PC or other USB host.

An interface between the device’s microcontroller or other CPU and the storage media. Flash-memory cards typically use the Serial Peripheral Interface (SPI), MultiMediaCard bus, SD-Card bus, or a bus derived from the ATA interface or PC-Card bus. Hard drives typically use the ATA parallel interface.

A USB mass-storage device must implement these protocols and structures:

Generic USB protocol. Every USB device must respond to requests sent by the USB host and other events on the bus.

USB mass-storage protocol. Every USB mass-storage device must detect and respond to requests that are specific to the USB mass-storage class.

SCSI commands. USB hosts access mass-storage devices via commands originally developed for devices that use the Small Computer Systems Interface (SCSI).

Media-specific protocol. The storage media’s controller typically supports a command set for accessing the media’s contents. Many flash-memory cards use the MultiMediaCard protocol or the SD Card protocol. Hard drives use the ATA protocol.

Reading and writing data to a mass-storage device also involves understanding logical structures in the media:

Media structure. Program code accesses the storage area in drives as a series of logical blocks, or sectors. Dedicated areas in the media store information about the logical blocks and other logical structures in the media.

File system. If the device firmware reads or writes to files on its own, rather than via a USB host, the device must implement a file system such as FAT16 or FAT32.

This book shows how to put all of these interfaces, protocols, and structures to work in a USB mass-storage device. The book assumes you have a basic familiarity with microcontroller programming and interfacing. For more about USB, I recommend my book, USB Complete: Everything You Need to Develop Custom USB Peripherals.

About the Code

This book include code examples written for the Microchip PIC18F4550 microcontroller using Microchip’s MPLAB® C18 C compiler. On my website (janaxelson.com) you can find links to complete mass-storage firmware for this chip and example mass-storage firmware for other microcontrollers.

Partner Links