logo image - link to home page

Products | Support | Resources | PurchaseContact  | Basket  | Checkout

  Home
  What's New
  Products
  Distributors
  Purchasing Info
  Developer Resources
  Support
  Upgrades
  Site Index
  Contact Us
  Pb-Free Info (RoHS)
 

 

keyword search:
 


 

Products:
  Books:
    The LAB-X1 Tutorial and Resource Book
    PICBASIC PROJECTS - 30 Projects Using PICBASIC and PICBASIC PRO
    Programming PIC Microcontrollers With PICBASIC
    Running Small Motors with PIC™ Microcontrollers
    Making PIC™ based Laboratory Instruments and Controllers
    Serial Port Complete Second Edition
    USB Complete Third Edition
    USB Mass Storage
    Build Your Own Humanoid Robots
    PIC Robotics
    Insectronics : Build Your Own Walking Robot
    Amphibionics : Build Your Own Biologically Inspired Reptilian Robot
    Designing Embedded Systems with PIC Microcontrollers: Principles and Applications
    Easy Microcontrol'n - A Beginner's Guide to Using PIC16/17 Microcontrollers
    Easy Step'n - An Introduction to Stepper Motors for the Experimenter
    PIC Microcontroller Project Book
    Microcontrol'n Apps - PIC Microcontroller Applications Guide
    Time'n and Count'n using PIC® Microcontrollers
    Programming and Customizing PICmicro Microcontrollers
    Serial Communications
     

USB Mass Storage - $49.95

Purchase at mcumart.com

by Jan Axelson

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.

This book include code examples written for the Microchip PIC18F4550 microcontroller using Microchip’s MPLAB® C18 C compiler. 

287 pages.


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.

Contents
for USB Mass Storage

Introduction

1 Mass Storage Basics

When to Use a Storage Device

Benefits
Other Considerations

Requirements

Devices
Embedded Hosts

Selecting a Media Type

Drive Mechanisms
Addressing Methods
Reading and Writing Considerations
Removable Media and Devices
Hardware Interfaces

Hard Drives

Technology
Interfaces

Flash Memory

Technology
Options for Flash Memory
MultiMediaCard
SD Memory Card
CompactFlash

2 Supporting USB

The Interface in Brief

Hosts and Devices
Host Responsibilities
Device Responsibilities
Bus Speeds
Endpoints
Transfer Types
Transactions
The Data Toggle
Descriptors
Mass Storage Requirements

Choosing a Device Controller

Controllers with Support for Flash Memory
Controllers with support for ATA/ATAPI
Firmware Options

Microchip PIC18F4550

Architecture
Firmware Support
The USB Controller

3 The USB Mass Storage Class

Requirements

Specifications
Logical Block Addressing
Mass Storage Requests

Descriptors

Device Descriptor
Configuration Descriptor
Interface Descriptor
Endpoint Descriptors
String Descriptors

Responding to Commands

The Command Block Wrapper
The Command Status Wrapper
Managing Communications on the Bulk Endpoints
More about STALL
Thirteen Cases for Any Situation

PC Support

Windows
Linux

4 Accessing Flash Memory Cards

The Interface

Signals and Power
Example Circuit

Host Programming

Configuring
Hardware Ports
Firmware-controlled Ports

Transferring Data

Default States
SPI on the PIC18F4550
Configuring the Port
Writing a Byte
Reading a Byte

5 MultiMediaCard Protocol

Command and Response Formats

Commands
Response Types
Token Formats

The Commands

Classes
Commands Used by Mass-storage Devices
Registers

Sending Commands

Timing Considerations
Commands with No Data Transfer
Commands that Read Data from the Storage Media
Commands that Write Data to the Storage Media

Application Example

Detecting and Selecting a Card
Sending a Command
Reading a Sector
Writing a Sector
Initializing Communications

6 SCSI Commands

About the Commands

Specifications
Which Commands to Implement?

Sense Data

Fixed-format Sense Data
Setting Default Values

Primary Commands

INQUIRY
MODE SELECT
MODE SENSE
PREVENT ALLOW MEDIUM REMOVAL
REPORT LUNS
REQUEST SENSE
SEND DIAGNOSTIC
TEST UNIT READY

Block Commands

FORMAT UNIT
READ
READ CAPACITY
START STOP UNIT
SYNCHRONIZE CACHE
VERIFY
WRITE

Multimedia Commands

READ FORMAT CAPACITIES
READ TOC/PMA/ATIP

Handling Commands and Events

Decoding Commands
The UNIT ATTENTION Condition
Informing the Host about Media Changes
Reset Behavior

7 Media Structure

A Look Inside

Components of Formatted Media
Drives without an MBR Sector
Byte Order

The Master Boot Record Sector

Executable Code
The Partition Table
Extended Partitions
The Boot Signature

8 FAT File Systems

Inside a FAT16 Volume

Reserved Region
File Allocation Table Region
Root Directory Region
File and Directory Data Region

Inside a FAT32 Volume

Reserved Region
File Allocation Table Region
File and Directory Data Region

Selecting a File System

Cluster Sizes
A Hardware Solution

The File Allocation Table

The First Two Entries
Data Clusters

Accessing the FAT

Volume Information
File Information
Obtaining a Cluster’s Logical Block Address
Reading from the FAT
Writing to the FAT
Finding a File’s Next Cluster
Performing Sequential Reads
Finding an Empty Cluster

9 Directories

The Contents of an Entry

File Entries
Directory Entries
The Volume Label Entry
Subdirectory Entries

Handling Long File Names

LFN Entries
The Checksum
Creating a Short File Name

Using Directories

Storing an Entry
Reading an Entry
Getting the Main Entry
Updating an Entry
Updating the Time and Date

10 File Operations

Cluster Operations

Erasing a Cluster
Reserving an Available Cluster
Allocating a File’s First Cluster
Allocating Additional Clusters

Managing Files

Obtaining File Information
Finding a File
Creating a Directory Entry
Finding an Available Entry
Creating a File
Deleting a File
Opening a File

Reading from a File

Tasks
Performing a Read Operation

Writing to a File

Tasks
Performing a Write Operation
Closing a File

11 Embedded Hosts

Inside an Embedded Host

OTG Devices and Conventional Hosts
General Host Functions
Mass Storage Functions
Handling Non-compliant Devices

Host Options

Cypress EZ-HOST
Host Software
A Mass-storage Host Module

Index

 

Copyright 2008
microEngineering Labs, Inc.
Box 60039
Colorado Springs CO 80960
(719) 520-5323
(719) 520-1867 fax
email: support@melabs.com

Last Updated: 07/10/2008

Home | What's New | Products | Support
Resources
| Purchase | Index Contact

PIC, PICmicro, dsPIC, and  MPLAB are registered trademarks of Microchip Technology Inc. in the USA and other countries.  PICBASIC, PICBASIC PRO, PICPROTO, and EPIC are trademarks of Microchip Technology Inc. in the USA and other countries.   BASIC Stamp is a trademark of Parallax, Inc.

Microchip third-party partner  Microchip Consultant Program Member