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

Home > Mass Storage

The Mass Storage Page

Resources for developers of USB devices in the mass storage device class, other mass-storage devices, and embedded hosts that support mass storage.

Basics | Specifications | Devices | Hosts

Basics

The USB mass-storage class encompasses devices that transfer files in one or both directions. Typical devices are floppy, hard, CD, DVD, and Flash drives. Cameras can use the mass-storage class to enable accessing picture files in a camera’s memory. In Windows computers, devices that use the mass-storage driver typically are formatted with a file system that Windows understands and appear as drives in My Computer. The file system enables users to copy, move, and delete files in the devices.

Almost all USB mass-storage devices use the bulk-only transport (BOT, also called BBB) protocol defined by the USB mass-storage class specification. (An exception is some full-speed floppy drives, which use the control, bulk, interrupt (CBI) protocol.) USB mass-storage devices also use SCSI commands defined by various SCSI standards.

The SCSI command sets specify a protocol for transferring blocks of data and status and control information such as a device's capacity and readiness to exchange data. Devices with USB and other hardware interfaces can use the SCSI command sets.

The mass-storage bulk-only protocol defines how a USB host can send commands and receive responses using the bulk transfers defined by the USB specification. In the bulk-only protocol, each exchange of information requires two or three USB transfers. In the first transfer, the host sends a command in a structure called a Command Block Wrapper (CBW). Many CBWs are followed by a transfer that contains data sent to the host or device. In the final transfer, the device returns status in a structure called a Command Status Wrapper (CSW).

USB Mass StorageUSB Mass Storage: Designing and Programming Devices and Embedded Hosts

My Mass Storage FAQ.

USB mass storage device class. From Wikipedia.

Debugging

Reported Device Errors. Problems to avoid in your designs.

Tips for USB pen drives. From Uwe Sieber.

Directory Snoop enables viewing the contents of sectors on FAT and NTFS drives. From Briggs Softworks.

Specifications

USB mass-storage communications use specifications from several sources.

Storage Cornucopia has dozens of links to standards information and other storage-related information. From Berg Software Design.

USB

The mass storage class specifications from USB-IF.

USBCV. USB-IF's compliance tools.

Media-specific Protocols and Command Sets

SCSI

Hard drives, flash drives, and other USB mass-storage devices support commands in the SCSI Primary Command (SPC) Set and SCSI Block Command (SBC) Set from www.t10.org (INCITS Technical Committee T10).

ATA/ATAPI

ATAPI CD/DVD devices comply with the ATA/ATAPI specification from www.t13.org (INCITS Technical Committee T13) and the MultiMedia Command (MMC) Set from www.t10.org. (An earlier version of the ATA/ATAPI specification was called SFF-8020i.)

Media Structure

Partition types and partition-table information. From Andries Brouwer.

File Systems

Mass-storage devices typically store data in files. An operating system can format a USB mass-storage device to use any of a number of file systems, such as FAT32, FAT16, and NTFS. In a Windows system, a formatted mass-storage device appears as a drive in My Computer, and users can read and write files in the same way they access files on other system drives.

For many mass-storage devices, including hard drives and flash drives, the sole purpose of the device is to enable the host to store and retrieve files. For these devices, the device firmware doesn't have to know or care what file system the host is using. The firmware just stores and sends blocks of data as requested by the host.

Other devices require firmware support for a file system. For example, a still-image camera might store its images as files. When the camera connects to a host computer, the camera appears as a system drive, making it easy for users to access the images. Or a data-acquisition device might gather and store data in files. When the data-acquisition device connects to a host computer, users can access the data as files on a drive. Device firmware might also want to read configuration data or other information that the host has stored in a file on the device. The firmware has to understand the file system to be able to store files that the host computer can retrieve and to read files that the host computer has stored.

Flash drives and other small-capacity devices typically use the FAT16 file system, while larger-capacity devices typically use FAT32 or NTFS. Which FAT file system to use depends entirely on the number of data clusters in the drive's partition. Microsoft's FAT32 specification shows how to determine what file system to use. The host system can format the device or the firmware can do the formatting. The NTFS specification is proprietary to Microsoft, so devices whose firmware must understand the file system will likely use FAT16 or FAT32.

Microsoft Extensible Firmware Initiative: FAT32 File System Specification

The Microsoft FAT file system technology license. Portions of the FAT file system are protected by patents.

Articles

Local File Systems for Windows. From Microsoft.

Understanding FAT32 Filesystems. From Paul Stoffregen.

FAT16 Structure Information and FAT32 Structure Information. From Jack Dobiash.

FAT16 File System Driver for CompactFlash. From Larry Wolcott.

The FAT File Systems. From ntfs.com

FAT System Guide. From FOXy2K.

Code

Portable FAT Library for MCU Applications by Ivan Sham, William Hue & Pete Rizun. March 2005 Circuit Cellar. The FAT firmware.

Sources for file systems for embedded systems with support for FAT16/32 and wear leveling include Unicoi Systems, Inc. and HCC Embedded.

Hardware

The GHI Electronics has an ALFAT board with a FAT file system stack on a chip. From GHI Electronics.

Also see Host chips for embedded systems.

Wear Leveling

Flash memory can withstand a limited number of erase/write cycles, however. A typical guaranteed number of cycles for the NAND memory used in storage devices is 100,000. Firmware that repeatedly writes to the same addresses will wear out that portion of the memory. To extend the life of a flash-memory chip, firmware can implement wear leveling, which uses various techniques to access all areas of the memory more equally.

Devices

Cards, chips and firmware for mass storage devices.

SD/MMC

SD Cards and MultiMediaCards (MMC) contain memory and a controller.

Memory Cards Complete Guide. From Varun Krishnan.

Memory Sticks page from One Stop Site for Formats.

CompactFlash

Implementing FAT on CompactFlash cards, SD/MMC cards and USB sticks. From CompuPhase.

Chips

Sources for device-controller chips with support for mass-storage interfaces and devices (IDE, ATA, ATAPI, floppies, flash memory).

Alcor Micro
Atmel
Cypress Semiconductor
NEC Electronics
Oxford Semiconductor
PLX Technology
Prolific Technology Inc.
SMSC (Standard Microsystems Corporation)
STMicroelectronics
Texas Instruments
Via Technologies, Inc.

Example Firmware

Generic

FatFs generic FAT file system module for small embedded systems. Freeware from Electronic Lives Manufacturing.

Atmel

Atmel's AT90USBKey demonstration board for the AT90USB AVR microcontroller has a mass-storage application.

Cypress Semiconductor

USB 2.0 USB to ATA Reference Design. Search www.cypress.com for CY4611B.

Hi-speed USB 2.0-to-ATA/ATAPI Bus-Powered Reference Design (with EZ-USB AT2LP). Search www.cypress.com for CY4615B.

Microchip

The Microchip Library for Applications includes a mass-storage example.

File I/O Functions Using Microchip's Memory Disk Drive File System Library. Application note and source code from Microchip.

USB Enumeration and Mass Storage Device firmware code for the Microchip PIC18F4550. From Andrew Holbrook.

MMC Project: PIC16F876 3.3volt Prototype. From COMPSys.

NXP

RDHCS12UF32TD: USB Thumb Drive Reference Design using the Freescale MC9S12UF32.

LPC2148 example from Keil.

Device Stacks

HCC Embedded has mass-storage device support.

MCCI's USB DataPump supports mass storage.

Micro Digital's smxUSBD USB Device Stack includes a mass-storage class emulator.

Hosts

Windows and other OSes with mass-storage support.

Windows

The mass-storage driver for USB devices is usbstor.sys, provided with Windows 2000 and later. Support for multiple LUNs (partitions) was added in Windows 2000 SP3.

From Microsoft

(Microsoft frequently changes the URLs of its content. If you get a File Not Found error, try a web search on the page's name.)

In the WDK documentation, see the Storage section.

Storage Technologies from Windows Hardware Developer Central.

USB Storage - FAQ for Driver and Hardware Developers.

Sample mass storage driver for Windows 98. Article ID 257751.

Other sources

Enumeration logs for various devices in Windows Me. From Alan Stern.

How to disable USB sticks and limit access to USB storage devices on Windows systems. From Hannes Schmidt.

Embedded Hosts

An embedded system that wants to communicate with flash-memory sticks or other mass storage devices must include USB host hardware and firmware with support for the mass-storage class.

Host chips for embedded systems. Includes links to GHI Electronics and FTDI, which have chips with built-in support for mass storage. My article Access Flash Drives with a Microcontroller shows how to use the USBwiz, with example code.

Example code

Access Flash Drives with a Microcontroller by Jan Axelson.

EZ-Host Mass Storage Reference Design. Search www.cypress.com for CY4640.

Micro Digital's smxUSBH USB Host Stack includes a mass-storage class driver.