Using a USB Flash Drive with an Embedded Host


The content on this page is a condensed version of Microchip Technology’s Application Note AN1145, which can be downloaded for free at Visitors will also find information on other application notes, development systems, datasheets, technical training, samples and much more.

USB Flash drives are a popular, simple and inexpensive method of moving data from one PC to another. Their use in the embedded market has been limited, however, due to the requirement that a system must have USB host capability to communicate with a Flash drive.

In the past, this usually meant that the system needed to be a PC. However, with the introduction of Microchip’s 16- and 32-bit PIC® microcontrollers with USB embedded host capability means that embedded systems can now take advantage of this popular portable media. With the ability to store data to a USB Flash drive, a PIC microcontroller-based application now has virtually unlimited data storage.

This application note demonstrates a data logger application that can run on the Explorer 16 Demo Board with the USB PICtail™ Plus Daughter Board. It implements a file system with a simple, but powerful, set of commands. Based on the 32-bit PIC32 microcontrollers, the data logger application consists of three main components: file manipulation capability, command interface and data logging.

The data logger application stores two types of data:

  • Low data rate monitoring. This is done by polling the on-board potentiometer approximately once per second. The potentiometer reading and time and data stamp of the reading are saved to a file on the Flash drive.
  • Higher speed time measurement accuracy. This is done by reading the temperature sensor every 10 ms. The temperature reading and the count of elapsed milliseconds are saved to a file on the Flash drive.

This application also provides a set of simple commands to interface to the Flash drive (via a serial terminal interface) and directly manipulate files on the Flash drive.

The data logger application is actually a multi-layer stack, with different components of Microchip’s USB Embedded Host Support Package contributing to different layers.

The USB embedded host driver provides generic support for USB embedded hosts. The interface to this layer is provided automatically in the mass storage client driver. For more information, refer to Microchip Application Notes AN1140 “USB Embedded Host Stack” and AN1141 “USB Embedded Host Stack Programmer’s Guide.”

The next layer provides the client driver for the mass storage class, which is required for interfacing with mass storage devices, such as a USB Flash drive. Refer to Microchip Application Note AN1142 “USB Mass Storage Class on an Embedded Host” for more information.

The file system support layer is provided by the file system library described in Microchip Application Note AN1045, which uses five functions to interface with the hardware. By replacing these low-level functions with SCSI commands that utilize the mass storage client driver for communication, this application note can be used to provide the file system interface to the USB Flash drive.

Note: The Microchip name and logo, and PIC are registered trademarks of Microchip Technology Inc. in the USA and other countries. PICkit is a trademark of Microchip Technology Inc. All other trademarks mentioned herein are the property of their respective companies.

Contact Information

Microchip Technology Inc.

2355 W. Chandler Blvd.
Chandler, AZ, 85224

tele: 480.792.7200
toll-free: 888.MCU.MCHP
fax: 480.792.7277

Share and Enjoy:
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Google
  • TwitThis
Extension Media websites place cookies on your device to give you the best user experience. By using our websites, you agree to placement of these cookies and to our Privacy Policy. Please click here to accept.