µC/USB-MSD Overview
You are here : Micrium
: Products : µC/USB-MSD :
Overview
µC/USB-MSD stack enables you to use your embedded target device as a USB mass storage device. Without the need to develop a kernel mode driver for the host operating system, you can simply plug-in your device and use it just like an ordinary disk drive. This is possible because the mass storage class is one of the standard device classes, defined by the USB Implementers Forum. Virtually every major operating system on the market supports these device classes out of the box
No custom kernel mode drivers necessary
Since nearly every major OS already provides kernel mode drivers for USB mass storage devices, there is no need to implement your own. Your target device will be recognized as a mass storage device and can be accessed directly.
Plug and Play
Let’s say your target system is a digital camera. Using µC/USB-MSD stack, you can access videos or photos taken by this camera conveniently with your file system explorer. All you have to do is to connect the camera to the host. That’s all.
Key features of µC/USB-MSD stack are
- Can be used with RAM, parallel flash, serial flash or mechanical drives
- Support for Full speed (12 MBit/s) and High speed (480 MBit/s) transfer rates
- Easy to use
- Easy to port
- No custom USB host driver necessary
- Highly portable, efficient, commented ANSI C source code
- OS-Abstraction: Use with any RTOS, no OS required for MSD only devices
- Hardware abstraction layer allows rapid addition of new devices support
Typical applications
- Digital camera
- USB stick
- MP3 player
- DVD player
- Any target with USB interface: Easy access to configuration and data files
Requirements
Target system
Hardware
Your target system must have a USB controller. The memory requirements are approximately 10kB ROM and approximately 1kB of RAM (Only used for buffering—systems with less RAM can also be used). Additionally memory for data storage is required of course, typically either on-board flash memory (parallel or serial) or an external flash memory card is required.
Software
A real-time kernel is required only if your application uses multiple tasks. In case of using µC/USB-MSD stack as the only task, an RTOS is not needed. µC/USB-MSD stack requires the USB-Bulk stack which is included.
Development environment
An ANSI-compliant C compiler is required. If your compiler has some limitations, please let us know and we will inform you if they will cause problems when compiling the software. Any compiler for 16/32/64-bit CPUs or DSPs that we know of can be used. Most 8-bit compilers can be used as well.
A C++ compiler is not required, but can be used. The application program can there-fore also be programmed in C++ if desired.
How does it work?
Use file system support from host OS
A device which uses µC/USB-MSD will be recognized as a mass storage device and can be used like an ordinary disk drive. If the device is unformatted when plugged-in, the host operating system will offer to format the device. Any file system the host provides can be used. Typically FAT is used, but other file systems such as NTFS are possible too. If one of those file systems is used, the host is able to read from and write to the device using the storage functions of the µC/USB MSD component, which define unstructured read and write operations. Thus there is no need to develop extra file system code if the application only accesses data on the target from the host side. This is typically the case for simple storage applications, such as USB memory sticks or ATA to USB bridges.
Only provide file system code on the target if necessary
Mass storage devices like USB sticks does not require its own file system implementation. File system program code is only required if the application running on target device has to access the stored data. The development of a file system is a complex and time-consuming task and enhances the time-to market. Thus we recommend the use of commercial file system like µC/FS, Micrium's file system for embedded applications. µC/FS is a high performance library that has been optimized for minimum memory consumption in RAM and ROM, high speed and versatility. It is written in ANSI C and can be used on any CPU and on any media.
FAQs
Do I need a real-time operating system (RTOS) to use µC/USB-MSD?
No, if your target application is a pure storage application. Yes, if your target has other things to do. You don’t need an RTOS if all you want to do is running µC/USB-MSD stack as the only task on the target device. If your target application is more than just a storage device and needs to perform other tasks simultaneously, you need an RTOS which handles the multi-tasking.
Do I need a file system to use µC/USB-MSD stack?
No, if you access the target data only from the host. Yes, if you want to access the target data from within the target itself. There is no extra file system code needed if you only want to access the data on the target from the host side. The host OS already provides several file systems. You have to provide file system program code on the target only if you want to access the data from within the target application itself.
Do I need a kernel mode driver on the host OS ?
No. Using µC/USB-MSD stack, your target device will be recognized as a mass storage device and the host OS provides the driver out of the box. Simply plug-in your device and use it.
Do I need a USB-Bulk stack?
µC/USB-MSD stack sits on top of the USB-Bulk stack. The bulk stack is needed to handle lower level USB communication and comes with µC/USB-MSD.
Background Information
USB: Quick Overview
The "Universal Serial Bus" (USB) is an external bus architecture for connecting peripherals to a host computer. It is an industry standard—maintained by the USB Implementers Forum—and because of its many advantages it enjoys a huge industry wide following. Over the years a number of USB-capable peripherals appeared on the market, e.g. printers, keyboards, mice, digital cameras etc. Among the top benefits of USB are:
- Excellent plug-and-play capabilities allow devices to be added to the host system without reboots ("hot-plug"). Plugged-in devices are identified by the host and the appropriate drivers are loaded instantly.
- USB allows easy extensions of host systems without requiring host-internal extension cards.
- Device bandwidths may range from a few Kb/s to hundreds of Mb/s.
- A wide range of packet sizes and data transfer rates are supported.
- USB provides internal error handling. Together with the already mentioned hot-plug capability this greatly improves robustness.
- The provisions for powering connected devices dispense the need for extra power supplies for many low power devices.
- Several transfer modes are supported which ensures the wide applicability of USB.
|
Not only did these benefits lead to broad market acceptance, but this in turn added several advantages as well, such as low costs of USB cables and connectors or a wide range of USB stack implementations. Last but not least the major operating systems such as Microsoft Windows XP, Mac OS X or Linux provide excellent USB support.
Important USB Standard Versions
USB 1.1 (September 1998)
This standard version supports isochronous and asynchronous data transfers. It has dual speed data transfer of 1.5 Mb/s for low speed and 12 Mb/s for full speed devices. The maximum cable length between host and device is five meters. Up to 500 mA of electric current may be distributed to low power devices.
USB 2.0 (April 2000)
As all previous USB standards, USB 2.0 is fully forward and backward compatible. Existing cables and connectors may be reused. A new "high speed" transfer speed of 480 Mb/s (40 times faster than USB 1.1 at full speed) was added.
USB System Architecture
A USB system is composed of three parts, a host side, a device side and a physical bus. The physical bus is represented by the USB cable and connects host and device. The USB system architecture is asymmetric. Every single host can be connected to multiple devices in a tree-like fashion using special hub devices. You can connect up to 127 devices to a single host, but the count must include the hub devices as well.
USB Host
A USB host consists of a USB host controller hardware and a layered software stack. This host stack contains a host controller driver (HCD) which provides the functionality of the host controller hardware, the USB Driver (USBD) Layer which implements the high level functions used by USB device drivers in terms of the functionality provided by the HCD, and finally the USB Device drivers which establish connections to USB devices. The driver classes are also located here and provide generic access to certain types of devices such as printers or mass storage devices.
USB Hub
Two divisions of devices exist: hubs and functions. Hubs provide the ability to provide additional USB attachment points. Functions provide capabilities to the host and are able to transmit or receive data or control information over the USB bus. Every peripheral USB device represents at least one function but may implement more than one function. A USB printer for instance may provide file system like access in addition to printing.
Here, we treat the term USB device as synonymous with functions and won’t consider hubs.
Each USB device contains configuration information which describe its capabilities and resource requirements. Before it can be used, USB devices must be configured by the host. When a new device is connected for the first time, the host enumerates it, requests the configuration from the device and performs the actual configuration. In case of µC/USB-MSD, your embedded device will appear as a USB Mass Storage device and the host OS provides the driver out of the box. This relieves you from the necessity to develop a custom driver to communicate with your target device.
Descriptors
A device reports its attributes via descriptors. Descriptors are data structures with a standard defined format. A USB device has one device descriptor which contains information applicable to the device and all of its configurations. It also contains the number of configurations the device supports. For each configuration a configuration descriptor contains configuration specific information. The configuration descriptor also contains the number of interfaces provided by the configuration. An interface groups the endpoints into logical units. Each interface descriptor contains information about the number of endpoints. Each endpoint has its own endpoint descriptor which states the endpoint’s address, transfer types etc.
As can be seen, the descriptors form a tree. The root is the device descriptor with n configuration descriptors as children, each of which has m interface descriptors which in turn have k endpoint descriptors each.
Transfer Types
The USB standard defines 4 transfer types: control, isochronous, interrupt and bulk. Control transfers are used in the setup phase. The application can basically select one of the other 3 transfer types. For most embedded applications, bulk is the best choice since it allows the highest possible data rates.
Control transfers
Typically used to configure a device when attached to the host. It may also be used for other device specific purposes, including control of other pipes on the device.
Isochronous transfers
Typically used for applications which need guaranteed speed. Isochronous transfer is fast but with possible data loss. A typical use is audio data which requires a constant data rate.
Interrupt transfers
Typically used by devices that need guaranteed quick responses (bounded latency).
Bulk transfers
Typically used by devices that generate or consume data in relatively large and bursty quantities. Bulk transfer has wide dynamic latitude in transmission constraints. It can use all remaining available bandwidth, but with no guarantees on bandwidth or latency. Since the USB bus is normally not very busy, there is typically 90% or more of the bandwidth available for USB transfers.
Setup phase / Enumeration
The host first needs to get information from the target, before the target can start communicating with the host. This information is gathered in the initial setup phase. The information is contained in the descriptors, which are in the configurable section of µC/USB-MSD stack. The most important part of target device identification are the product and vendor IDs. During the setup phase, the host also assigns an address to the client. This part of the setup is called enumeration.
Product / vendor IDs
A vendor ID can be obtained from the USB Implementers Forum, Inc. (www.usb.org). This is necessary only when you finish development of the product; during the development phase, you can use the vendor and product IDs supplied as samples.
Mass Storage Device (MSD)
Command Protocols
| 01h |
Reduced Block Commands (RBC) T10
Project 1240-D |
Typically, flash devices use RBC command blocks, but RBC may be used by any mass storage device. |
| 02h |
SFF-8020i, MMC-2 (ATAPI) |
Typically a C/DVD device uses SFF-8020i or MMC-2 command blocks for its mass storage interface. |
| 03h |
QIC-157 |
Typically used by tape devices. |
| 04h |
UFI |
Typically a floppy disk drive (FDD) device. |
| 05h |
SFF-8070i |
Typically used by floppy disk drive (FDD) devices, but other devices may use SFF-8070i as well. |
| 06h |
SCSI transparent command set |
|
| 07h — FFh |
Reserved for future use. |
|
µC/USB-MSD stack supports the SCSI transparent command set (06h) only.
Transport Protocols
| 00h |
Command/Bulk/Interrupt protocol
(with command completion interrupt) |
USB mass storage class control/bulk/interrupt (CBI) transport |
| 01h |
Command/Bulk/Interrupt protocol
(without command completion interrupt) |
USB mass storage class control/bulk/interrupt (CBI) transport. |
| 50h |
Bulk-Only transport |
USB mass storage class bulk-only transport |
| 02h—4Fh |
Reserved |
|
| 51h—FFh |
Reserved |
|
µC/USB-MSD stack supports bulk-only transport (50h) only.
References
For additional information see the following documents:
- Universal Serial Bus Specification, Revision 2.0
- Universal Serial Bus Mass Storage Class Specification Overview, Rev 1.2
- UFI command specification: USB Mass Storage Class, UFI Command Specification, Rev 1.0
|
|