Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AVR UC3 USB Software Framework for Mass Storage

Description

This embedded application source code illustrates how to implement a USB mass-storage application on the AVR UC3 A3/A4 microcontroller.

As the AVR UC3 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 true false true
USB_HOST_FEATURE false true true
conf_access.h
LUN_USB false true true
ACCESS_USB true false true

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.

About the Sample Application

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):
  • 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:

Using the USB Device Mode

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.

Architecture

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.

Configuration

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.

Limitations

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.

Contact Information

For further information, visit Atmel AVR UC3.