EVK525 AT90USBxxx Dual role demonstration with file system
Use of this program is subject to Atmel's End User License Agreement.
Please read file lic_page for copyright notice.
This embedded application source code illustrates how to implement a dual role application with the AT90USBxxx controller.
As the AT90USBxxx implements a device/host usb controller, the embedded application can operates in one of the following usb operating modes:
- USB device
- USB reduced host controller
The application contains 3 Logical Units (LUN) :
- SD/MMC interface, size depends on user's card (EVK525)
- NAND Flash device, 256 MBytes by default, but user can add others devices (EVK525). The NandFlash suppoted listing is availabled here.
- DataFlash device, 4 MBytes (STK525)
- V2.0.3
USB Device:
- Fix bug about back drive voltage on D+ after VBus disconnect (USB Certification)
- Remove VBus interrupt and manage VBus state by pooling
- Fix bug during attach (the interrupt must be disable during attach to don't freeze clock)
- MassStorageClass :
- Fix error in sense command to support Vista and Windows Seven
- Add write Protect Management under MAC OS
- Improve MSC compliance
- Add MSC compliance with Linux 2.4 kernel
USB Host:
- Improve USB Host behavior
- Fix bug on stall management with dual banks
- improve disconnection detection
- MassStorageClass:
- Add read/write USB command for large block
- support multi LUN like multi card reader
- support disk with sector size different of 512B
- Fix bug when many MSC are connected to a hub
- Add read/write USB command for large block
SD/MMC driver:
- Fix SD/MMC driver initialization
NandFlash driver:
New ushell (MAJOR update)
- V2.0.2
USB Stack:
- Improve USB protocol for USB chap9 and MSC compliance
- Move VBus interrupt to VBus pooling
- Fix USB constant about Device Status
- Add three possibilities for SN on USB : No SN, Constant SN, Unique SN
- Add dual bank in USB host mode
- Add the switch USB mode by software not by HW reset
- update host MSC driver to support specific U-Disk
DataFlash driver:
- Add USB Write Protection management on DataFlash
- Fix error on DataFlash I/O initialization
MMC/SD driver:
NandFlash driver :
- add feature 2xCS
- new CLE/ALE pin management to fix error on specific NF references
New watchdog driver to control the specific sequence timing
FileSystem:
- Change short name creation to do more compliant with FAT32 white paper
- V2.0.1
USB Stack :
- clean stack constant
- Fix inquiry command
- clean and fix specific request
- fix bug in host MSC write
- V2.0.0 and before
Please, don't use the package "evk525_dms_host_ms_filesystem_hub-1_0_0" because this one include a major bug on NandFlash driver. Please read the EVK525 User Hardware Guide before connecting the EVK525 to STK525, and before using this program.
This source code is usable with the following compilers:
- IAR Embedded Workbench (5.11A and higher)
- AVRGCC (WinAVR 20080411 and higher).
Support for other compilers may required modifications or attention for:
- compiler.h file
- special registers declaration file
- interrupt subroutines declarations
By default the demonstration is preconfigured for 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 (PC) to operate as USB Device Mass Storage (removable drive).
- Attached to a mini A plug (ID pin tied to ground) the application operates in reduced host mode. This mode allows to connect a USB mass storage device
- In both modes, the STK525&EVK525 can be connected to a serial terminal, where the user can acess a simple command line interperter (ushell) to perform file system access. To use the simple shell application, connect the STK525&EVK525 to a serial terminal emulator (like Hyperterminal under windows systems). The serial port settings are:
- 57600 bauds
- 8bits data, no parity
- no flow control To use the application, the SK525&EVK525 should be configured to be self powered at 3.3V(see STK525 hardware manual and EVK525 manual).
Connect the STK525&EVK525 to a PC host system with a miniB (STK525 side) to plugA (PC host) cable
- Several removable drive allows to read/write files on:
- the STK525 on-board data flash memory
- the EVK525 on-board nand flash memory
- the EVK525 MMC/SD memory
- Connected to a USB Mass Storage Device (MSD), files can be exchange with the on-board data flash disk and the MSD.
- The right direction of the joystick allows to read the content of a MSD "OUT" directory and to write it to an on-board data flash "IN" directory.
- The left direction of the joystick allows to write the content of an on-board data flash "OUT" directory to a MSD "IN" directory.
The optional hub support included in this demonstration allows to connect up to two USB MSD to the STK525. The AT90USB1287 as an OTG device does not fully support usb hubs. This demonstration implements many firmware tricks in order to support a hub with USB mass storage devices. The hub support firmware included within this demonstration is suitable only for bulk only peripherals. Support for other usb device interfaces with either interrupt or isochronous transfer mode will not work.
Connected to a serial terminal emulator the Usheel command line interpreter allows to:
- Navigate in the file system (on-board memories and a USB mass storage device connected to the USB host interface). The following commands are supported:
- a: , b: ... goto selected drive
- cd dirname
- ls
- touch filename
- append filename
- mark: bookmark current directory
- cp filename: copy filename to bookmark
- rm filename: erase file or empty directory
- format drivename, with drivename: a, b...
- deltree dirname
- cat filename
- cd..
- mount disk(a,b,..)
- mkdir dirname
- disk: get number of drives
- goto: goto bookmark
- df: get free space information
- cat filename
- rm*: rm *
- Get information about the connected device and misc commands
- lsusb
- suspend: suspend USB bus activity
- resume: resume USB bus activity
- reboot: reset the application
For more information about File System module see File System
As illustrated in the figure bellow, the application entry point is located is the main.c file. The main function first performs the initialization of a scheduler module and then runs it in an infinite loop. The scheduler is a simple infinite loop calling all its tasks defined in the conf_scheduler.h file. No real time schedule is performed, when a task ends, the scheduler calls the next task defined in the configuration file (conf_scheduler.h).
The sample dual role application is based on several 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 operationnal, it updates different status flags that can be check within the high level application tasks.
- The storage task performs SCSI bulk only protocol decoding and performs flash memory access.
- The host_ms_task manages the Device Mass Storage interfaceconnected
- The ushell_task manages the terminal commands process
Generated on Wed Sep 23 09:17:02 2009 for ATMEL by
1.5.3