AVR32 USB Software Framework for Mass Storage
Use of this program is subject to Atmel's End User License Agreement.
Please read the Copyright Notice at the bottom of this page.
This embedded application source code illustrates how to implement a USB mass-storage application on the AVR32 microcontroller.
As the AVR32 implements a device/host USB controller, the embedded application can operate in one of the following USB operating modes:
- USB device;
- USB reduced-host controller;
- USB dual-role device (depending on the ID pin). This is the default configuration used in this example.
The next table shows the customization to do (into the conf_usb.h and conf_access.h configuration files) in order to support one of the USB operating modes:
| USB device | USB reduced-host | USB dual-role |
conf_usb.h |
USB_DEVICE_FEATURE | ENABLED | DISABLED | ENABLED |
USB_HOST_FEATURE | DISABLED | ENABLED | ENABLED |
conf_access.h |
LUN_USB | DISABLED | ENABLED | ENABLED |
ACCESS_USB | ENABLED | DISABLED | ENABLED |
To optimize embedded code/RAM size and reduce the number of source modules, the application can be configured to use one and only one of these operating modes.
By default the sample code is delivered with a simple preconfigured dual-role USB application. It means that the code generated allows to operate as a device or a host depending on the USB ID pin:
- Attached to a mini-B plug (ID pin unconnected) the application will be used in the device operating mode. Thus, the application can be connected to a system host (e.g. a PC) to operate as a USB mass-storage device (removable drive):
EVK1100 USB Device Mode
EVK1101 USB Device Mode
EVK1104 USB Device Mode
EVK1105 USB Device Mode
- Attached to a mini-A plug (ID pin tied to ground) the application will operate in reduced-host mode. This mode allows to connect a USB mass-storage device:
EVK1100 USB Host Mode
EVK1101 USB Host Mode
EVK1104 USB Host Mode
EVK1105 USB Host Mode
- In both modes, the application can be connected to a serial terminal (e.g. HyperTerminal under Windows systems or minicom under Linux systems; UART settings: 57600 bauds, 8-bit data, no parity bit, 1 stop bit, no flow control), from where the user can access a simple command line interpreter (uShell) to perform file-system accesses.
Connect the application to a USB mass-storage host (e.g. a PC) with a mini-B (embedded side) to A (PC host side) cable. The application will behave as a USB key. It will allow to access files on the on-board virtual, data flash and SD/MMC memories.
Connect the application to a USB mass-storage device (e.g. a USB key). The application will behave as a USB mass-storage reduced host. It will allow to exchange files between the on-board virtual, data flash and SD/MMC memories and the mass-storage device.
Connected to a serial terminal the uShell command line interpreter allows to:
- access the file system (both on-board virtual, data flash and SD/MMC memories and connected USB mass-storage device):
- disk: get the number of drives,
- a:, b:, etc.: go to selected drive,
- mount drivename (a, b, etc.): go to selected drive,
- format drivename (a, b, etc.): format selected drive,
- fat: get FAT type used by current drive,
- df: get free space information for all connected drives,
- cd dirname: go to selected directory,
- cd..: go to upper directory,
- mark: bookmark current directory,
- goto: go to bookmarked directory,
- ls: list files and directories in current directory,
- rm filename: remove selected file or empty directory,
- rm*: remove all files or empty directories in current directory,
- cp filename: copy filename to bookmarked directory,
- mv src_filename dst_filename: rename selected file,
- mkdir dirname: make directory,
- deltree dirname: remove directory and its content,
- touch filename: create file,
- append filename: append to selected file from terminal input,
- cat filename: list file contents;
- get information about the connected device and to perform miscellaneous commands:
- lsusb: when in USB host mode, get USB information,
- usbsync {device|host}: when in USB host mode, synchronize device or host USB drive,
- suspend: when in USB host mode, suspend USB bus activity,
- resume: when in USB host mode, resume USB bus activity,
- reboot: reset the application,
- help: get help about uShell commands.
As illustrated in the figure below, the application entry point is located in the
mass_storage_example.c file. The main function first performs the initialization of services and tasks and then runs them in an infinite loop.
The sample mass-storage application is based on four different tasks:
- The USB task (usb_task.c associated source file) is the task performing the USB low-level enumeration process in device or host mode. Once this task has detected that the USB connection is fully operational, it updates various status flags that can be checked within the high-level applicative tasks.
- The device mass-storage task (device_mass_storage_task.c associated source file) performs SCSI bulk-only protocol decoding and flash memory accesses.
- The host mass-storage task (host_mass_storage_task.c associated file) manages the connected device mass-storage interface by performing SCSI bulk-only protocol encoding and flash memory accesses.
- The USB shell task (ushell_task.c associated file) manages the processing of terminal commands.
Architecture Overview
The sample application is configured to implement both host and device functionalities. Of course it can also be configured to be used only in device or reduced-host mode (see the
conf_usb.h file). Depending on the USB operating mode selected, the USB task will call either the USB host task (usb_host_task.c), or the USB device task (usb_device_task.c) to manage USB specification chapter 9 requests.
Example configuration files can be found in SERVICES\USB\CLASS\MASS_STORAGE\EXAMPLES\CONF.
Some mass-storage devices do not present directly a mass-storage-class interface, which may e.g. be hidden behind a hub-class device. These devices are not supported by this example and the current mass-storage software framework.
For further information, visit
Atmel AVR32.
Support and FAQ:
http://support.atmel.no/
Copyright (c) 2009 Atmel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. The name of Atmel may not be used to endorse or promote products derived from this software without specific prior written permission.
4. This software may only be redistributed and used in connection with an Atmel AVR product.
THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE