Lakeview Research home > Mass Storage

The Mass Storage Page

Resources for Developers of USB Devices in the
Mass Storage Device Class

brought to you by Jan Axelson

Basics | Specifications | Devices | Hosts

This page has links to information and code samples for USB mass-storage-class devices and hosts.

USB Mass StorageUSB Mass Storage

My book USB Mass Storage: Designing and Programming Devices and Embedded Hosts will help you in your designs.

newAccess Flash Drives with a Microcontroller

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).

My Mass Storage FAQ.

Reported Device Errors. Problems to avoid in your designs.

USB mass storage device class. From Wikipedia.

Specifications and Other Requirements

USB mass-storage communications use specifications from several sources.

USB Mass Storage

The mass storage class specifications from USB-IF.

Draft of the Mass Storage Class Compliance Test Specification. Describes tests that will be incorporated into the USBCV compliance tool, including required and optional commands for different device types. From USB-IF.

USBCV R1.3. A Beta version of the USB-IF's compliance tool, which now includes mass-storage-class tests.

Cdb Complete includes a discussion of the Thirteen Cases from the USB bulk-only transport specification. From Pat LaVarre.

Media-specific Protocols and Command Sets

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).

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

ATA/ATAPI

ATAPI CD/DVD devices follow 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.)

ATA FAQ. From ATA-ATAPI.COM

Media Structure

How it Works. About the MBR sector and partition tables. From ata-atapi.com.

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.

Articles

Microsoft Extensible Firmware Initiative: FAT32 File System Specification. From Microsoft.

The Microsoft FAT file system technology license. Portions of the FAT file system are protected by patents. A previous Microsoft web page that talked about required licensing for some consumer devices appears to be gone from the web.

Search www.microsoft.com for the article, "Local File Systems for Windows". (No direct link because Microsoft changes the URLs too often to keep up with.)

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.

Tools

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

Hardware

The ALFAT is a FAT file system stack on a chip. From GHI Electronics. Using ALFAT with Proton Plus PICBASIC.

Wear Leveling

Flash memory is a popular choice for smaller drives. 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 quickly 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.

SanDisk Flash Memory Cards: Wear Leveling. White paper from SanDisk.

TrueFFS Wear-Leveling Mechanism. Technical note from Data I/O.

Devices

Cards, chips and firmware for mass storage devices.

Flash Drives

The USB Flash Drive Alliance.

SD/MMC

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

Embedded SD Card/MMC Card. Includes a comparison chart of the different card types and image files of the contents of various cards as they ship from the factory. From Mark Whitis.

Memory Cards Complete Guide. From Varun Krishnan.

Hirose Connectors has card connectors.

SanDisk OEM Card Manuals.

A comparison of the different MultiMediaCard and SD Card variants, plus other card types. From the Memory Stick Developers Site.

CompactFlash

Programming the Compact Flash card or Memory Stick. From CompuPhase.

Chips

Device-controller chips with specific support for mass-storage devices (IDE, ATA, ATAPI, floppies, flash memory) are available from these sources:

Alcor Micro
Atmel
Cypress Semiconductor
NEC Electronics
Oxford Semiconductor
Philips Semiconductors
Prolific Technology Inc.
SMSC (Standard Microsystems Corporation)
STMicroelectronics
Sunplus Technology Company, Ltd.
Texas Instruments
Transdimension
Via Technologies, Inc.

Example Firmware

Microchip's mass-storage example for the USB PIC18F4550. A complete SD/MMC-card mass-storage application. From Microchip.

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

Atmel's USB mass-storage firmware for AT89C5131 USB Flash microcontroller.

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

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

NXP LPC214x example from Keil.

Philips has a variety of mass-storage evaluation kits.

8051 USB Mass Storage Reference Design. from Silicon Labs.

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.

The TUSB6250DEMO reference design acts as a bridge between a USB 2.0 high-speed bus and an ATA/ATAPI device. From Texas Instruments.

Procyon AVRlib. C code, including MMC SPI drivers. For Atmel AVRs.

MMC Project: PIC16F876 3.3volt Prototype. From COMPSys.

Device Stacks

MCCI's USB DataPump supports mass storage.

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

Software Tools

EndPointScan checks what drives and other devices have been connected to computers in a network. Free. From GFI.

Hosts

Information about Windows support for mass storage and other hosts with mass-storage support.

PLScsi command-line utility for SCSI communications. For DOS, Linux, Mac, and Windows. From Pat LaVarre.

Windows Specific

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

In the Windows DDK documentation, see the Storage Devices section.

In Windows Hardware and Driver Central, search for "Storage - Architecture and Driver Support".

Microsoft's USB Storage FAQ.

Microsoft's sample mass storage driver for Windows 98. (Article ID 257751).

Hardware Design for Surprise Removal. White paper from Microsoft.

How to get the USBdisk's drive letter properly. How to determine if a drive is a USB drive.

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.

Linux

USB Mass Storage Driver for Linux

Usb-storage is an e-mail group that mainly focuses on the Linux USB mass-storage driver. Much of the discussion is about patches needed to enable communications with devices that don't fully comply with the mass-storage and other specifications. Archives are available.

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.

Hosts for Embedded Systems

usbwiz_demo is my Visual Basic .NET application that demonstrates communications between a USBwiz-OEM board from GHI Electronics and flash drives. The PC provides host-controller software for the USBwiz-OEM. Use this application to test communications that you can then port to a microcontroller.

USB Mass Storage development kit from GHI Electronics.

Access Flash Drives with a Microcontroller

A mass-storage host using a Microchip 18F452 microcontroller and Cypress SL811HS host controller.

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.

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

Projects

Rewriting the software for a USB Wireless PC Lock. From Scott Hanselman.