Application Note. USB Mass Storage Device Implementation. USB Microcontrollers. References. Abbreviations. Supported Controllers



Similar documents
AT89C5131A Starter Kit... Software User Guide

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

General Porting Considerations. Memory EEPROM XRAM

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. C51 Bootloaders. C51 General Information about Bootloader and In System Programming. Overview. Abreviations

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

8-bit Microcontroller. Application Note. AVR400: Low Cost A/D Converter

AVR106: C functions for reading and writing to Flash memory. 8-bit Microcontrollers. Application Note. Features. Introduction

Application Note. 8-bit Microcontrollers. AVR270: USB Mouse Demonstration

AVR134: Real Time Clock (RTC) using the Asynchronous Timer. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit Microcontroller. Application Note. AVR222: 8-point Moving Average Filter

8-bit RISC Microcontroller. Application Note. AVR182: Zero Cross Detector

AT91 ARM Thumb Microcontrollers. AT91SAM CAN Bootloader. AT91SAM CAN Bootloader User Notes. 1. Description. 2. Key Features

AT91 ARM Thumb Microcontrollers. Application Note. Interfacing a PC Card to an AT91RM9200-DK. Introduction. Hardware Interface

8-bit Microcontroller. Application Note. AVR415: RC5 IR Remote Control Transmitter. Features. Introduction. Figure 1.

8-bit Microcontroller. Application Note. AVR105: Power Efficient High Endurance Parameter Storage in Flash Memory

AVR030: Getting Started with IAR Embedded Workbench for Atmel AVR. 8-bit Microcontrollers. Application Note. Features.

8-bit. Application Note. Microcontrollers. AVR282: USB Firmware Upgrade for AT90USB

How to Calculate the Capacitor of the Reset Input of a C51 Microcontroller 80C51. Application Note. Microcontrollers. Introduction

AVR287: USB Host HID and Mass Storage Demonstration. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit RISC Microcontroller. Application Note. AVR236: CRC Check of Program Memory

Application Note. 8-bit Microcontrollers. AVR280: USB Host CDC Demonstration. 1. Introduction

AVR245: Code Lock with 4x4 Keypad and I2C LCD. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR115: Data Logging with Atmel File System on ATmega32U4. Microcontrollers. Application Note. 1 Introduction. Atmel

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary

Quick Start Guide. CAN Microcontrollers. ATADAPCAN01 - STK501 CAN Extension. Requirements

Tag Tuning/RFID. Application Note. Tag Tuning. Introduction. Antenna Equivalent Circuit

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel Microcontrollers. Application Note. Features.

8-bit RISC Microcontroller. Application Note. AVR155: Accessing an I 2 C LCD Display using the AVR 2-wire Serial Interface

Application Note. Migrating from RS-232 to USB Bridge Specification USB Microcontrollers. Doc Control. References. Abbreviations

8-bit Microcontroller. Application Note. AVR314: DTMF Generator

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

Using CryptoMemory in Full I 2 C Compliant Mode. Using CryptoMemory in Full I 2 C Compliant Mode AT88SC0104CA AT88SC0204CA AT88SC0404CA AT88SC0808CA

Application Note. 8-bit Microcontrollers. AVR272: USB CDC Demonstration UART to USB Bridge

8-bit Microcontroller. Application Note. AVR201: Using the AVR Hardware Multiplier

8-bit Microcontroller. Application Note. AVR461: Quick Start Guide for the Embedded Internet Toolkit. Introduction. System Requirements

USB 2.0 Full-Speed Host/Function Processor AT43USB370. Summary. Features. Overview

AVR32110: Using the AVR32 Timer/Counter. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

USB Test Environment ATUSBTEST- SS7400. Summary

AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS

Application Note. 8-bit Microcontrollers. AVR293: USB Composite Device

AVR32100: Using the AVR32 USART. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1900: Getting started with ATxmega128A1 on STK bit Microcontrollers. Application Note. 1 Introduction

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

8-bit Microcontroller. Application. Note. AVR204: BCD Arithmetics. Features. Introduction. 16-bit Binary to 5-digit BCD Conversion bin2bcd16

AVR034: Mixing C and Assembly Code with IAR Embedded Workbench for AVR. 8-bit Microcontroller. Application Note. Features.

AVR442: PC Fan Control using ATtiny13. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1922: Xplain Board Controller Firmware. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Two-wire Automotive Serial EEPROM AT24C01A AT24C02 AT24C04 AT24C08 (1) AT24C16 (2)

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1600: Using the XMEGA Quadrature Decoder. 8-bit Microcontrollers. Application Note. Features. 1 Introduction. Sensors

AVR241: Direct driving of LCD display using general IO. 8-bit Microcontrollers. Application Note. Features. Introduction AVR

AVR1318: Using the XMEGA built-in AES accelerator. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary. Features. Applications. 1. Description

AVR353: Voltage Reference Calibration and Voltage ADC Usage. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR120: Characterization and Calibration of the ADC on an AVR. 8-bit Microcontrollers. Application Note. Features. Introduction

DIP Top View VCC A16 A15 A12 A7 A6 A5 A4 A3 A2 A1 A0 I/O0 I/O1 I/O2 GND A17 A14 A13 A8 A9 A11 A10 I/O7 I/O6 I/O5 I/O4 I/O3. PLCC Top View VCC A17

AVR32138: How to optimize the ADC usage on AT32UC3A0/1, AT32UC3A3 and AT32UC3B0/1 series. 32-bit Microcontrollers. Application Note.

How To Use An Atmel Atmel Avr32848 Demo For Android (32Bit) With A Microcontroller (32B) And An Android Accessory (32D) On A Microcontroller (32Gb) On An Android Phone Or

AT86RF230 (2450 MHz band) Radio Transceiver... User Guide

How To Prevent Power Supply Corruption On An 8Bit Microcontroller From Overheating

8-bit. Application Note. Microcontrollers. AVR273: USB Mass Storage Implementation. Features. 1. Introduction

Table of Contents. Section 1 Introduction Section 2 Getting Started Section 3 Hardware Description

AVR2006: Design and characterization of the Radio Controller Board's 2.4GHz PCB Antenna. Application Note. Features.

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

32-bit AVR UC3 Microcontrollers. 32-bit AtmelAVR Application Note. AVR32769: How to Compile the standalone AVR32 Software Framework in AVR32 Studio V2

AT91SAM ARM-based Flash MCU. Application Note

8-bit RISC Microcontroller. Application Note. AVR910: In-System Programming

AVR1510: Xplain training - XMEGA USART. 8-bit Microcontrollers. Application Note. Prerequisites. 1 Introduction

Two-wire Serial EEPROM AT24C1024 (1)

ATF15xx Product Family Conversion. Application Note. ATF15xx Product Family Conversion. Introduction

Application Note. Atmel ATSHA204 Authentication Modes. Prerequisites. Overview. Introduction

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

AVR32788: AVR 32 How to use the SSC in I2S mode. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. Atmel CryptoAuthentication Product Uses. Atmel ATSHA204. Abstract. Overview

AT88CK490 Evaluation Kit

2-wire Serial EEPROM AT24C1024. Advance Information

AT91 ARM Thumb Microcontrollers. Application Note. GNU-Based Software Development on AT91SAM Microcontrollers. 1. Introduction. 2.

AVR068: STK500 Communication Protocol. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

2-Wire Serial EEPROM AT24C32 AT24C64. 2-Wire, 32K Serial E 2 PROM. Features. Description. Pin Configurations. 32K (4096 x 8) 64K (8192 x 8)

APPLICATION NOTE. Atmel LF-RFID Kits Overview. Atmel LF-RFID Kit. LF-RFID Kit Introduction

Application Note. 8-bit Microcontrollers. AVR091: Replacing AT90S2313 by ATtiny2313. Features. Introduction

8051 Flash Microcontroller. Application Note. A Digital Thermometer Using the Atmel AT89LP2052 Microcontroller

USER GUIDE. ZigBit USB Stick User Guide. Introduction

SMARTCARD XPRO. Preface. SMART ARM-based Microcontrollers USER GUIDE

Atmel AVR4950: ASF - USB Host Stack. 8-bit Atmel Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. Atmel AT02985: User s Guide for USB-CAN Demo on SAM4E-EK. Atmel AVR 32-bit Microcontroller. Features. Description.

Atmel AVR1017: XMEGA - USB Hardware Design Recommendations. 8-bit Atmel Microcontrollers. Application Note. Features.

Designing Feature-Rich User Interfaces for Home and Industrial Controllers

AVR2004: LC-Balun for AT86RF230. Application Note. Features. 1 Introduction

APPLICATION NOTE. Atmel AT04389: Connecting SAMD20E to the AT86RF233 Transceiver. Atmel SAMD20. Description. Features

APPLICATION NOTE. AT07175: SAM-BA Bootloader for SAM D21. Atmel SAM D21. Introduction. Features

APPLICATION NOTE Atmel AT02509: In House Unit with Bluetooth Low Energy Module Hardware User Guide 8-bit Atmel Microcontroller Features Description

USER GUIDE EDBG. Description

AVR055: Using a 32kHz XTAL for run-time calibration of the internal RC. 8-bit Microcontrollers. Application Note. Features.

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

Application Note. USB Microcontrollers. USB PC Drivers Based on Generic HID Class. 1. Introduction

Transcription:

USB Mass Storage Device Implementation References Universal Serial Bus Specification, revision 2.0 Universal Serial Bus Class Definition for Communication Devices, version 1.1 USB Mass Storage Overview, revision 1.2 USB Mass Storage Bulk Only, revision 1.0 USB Microcontrollers Application te Abbreviations USB: Universal Serial Bus VID: Vendor Identifier PID: Product Identifier LUN: Logical Unit Number USB-IF: USB Information Forum SCSI: Small Computer System Interface Supported Controllers AT89C5131A Rev. 1

Introduction Scope Overview The floppy disk is over! Too slow, too fragile, not enough capacity... USB is now on every PC under Windows or Linux, on every Mac. And you can very easily find USB Mass Storage keys that are automatically recognized by the Operating System, with high capacities and excellent speed performances. The USB Mass Storage device replaces Floppy, and can be used in many other applications: USB mouse for laptop with Mass Storage integrated External Hard Drive, data storage Access to internal memory of a mobile phone or MP3 player Firmware Upgrade of a system Small capacity memory to store private information or preferences (Smart Card Reader, Control Access, Electronic Wallet...) etc. The aim of this document is to describe how to implement the USB Mass Storage class (with an example on the AT89C5131A product) and the firmware functions delivered by Atmel. Figure 1. Application Overview USB Mass Storage Memory What is USB Mass Storage Inside the computer, many Mass Storage peripherals (the hard drive for example) can be accessed using the SCSI command set. te: SCSI = Small Computer System Interface The USB Mass Storage class defines the USB wrapper of the SCSI commands. USB Mass Storage is no more than the SCSI command set for the USB. In order to access several memories at the same time, for a multiple-memory card reader for example, the Host selects the LUN (Logical Unit Number) whose SCSI command is addressed. 2

Operating Systems and USB Mass Storage Figure 2. Mass Storage Device seen by a USB Host Currently, most Operating Systems support USB and have built-in drivers to support the USB Mass Storage: Windows XP : native driver Windows 2000 : native driver Windows Me : native driver Windows 98SE : Vendor specific driver required Linux : USB mass storage is available in kernel 2.4 or later. USB mass storage is available in Mac OS 9/X or later This is very convenient for the final user who can now transfer any file from his own computer to any other. For every Operating System, a USB Mass storage device is composed of: the Default Control Endpoint (0), to perform the enumeration process, to determine the number of LUN (Logical Unit Number), and to perform a reset recovery in case of mass storage error. a Bulk OUT Endpoint, used by the Host Controller to send the wrapped SCSI commands and to send the data to write inside the memory. a Bulk IN Endpoint, used by the Host Controller to read the wrapped SCSI status and to read data from the memory. USB Mass Storage Device Bulk OUT Endpoint SCSI Commands Data to Write USB Host USB Host Memory Bulk IN Endpoint SCSI Status Data to Read USB USB Host Enumeration Mass Storage Specific Requests Default Control Endpoint 3

USB Mass Storage Device Firmware Stack architecture Figure 3. USB Mass Storage Device Firmware architecture Figure 3. shows the architecture of the USB Mass Storage firmware stack. At89c5131A Hardware Sof tware Hardware USB Memories Data to write USB Bulk OUT Endpoint (command, data to write) Bulk IN Endpoint (status, data to read) USB Drivers USB Mass Storage Protocol Decoder Data to read SCSI Decoder Control Access Memory Drivers Def ault Control Endpoint Generic Enumeration Process Mass Storage Descriptors Mass Storage Specif ic Requests Firmware Stack Deliv ered by ATMEL The standard enumeration process (USB chapter 9 support) is performed by a generic function. The parameters and the descriptors are specific for each application. The USB Mass Storage class also requires specific request support. You can see that the commands coming from the USB Host controller are first unwrapped by the USB Mass Storage Protocol Decoder function before entering into the SCSI decoder. Each SCSI command is then decoded and transmitted to the appropriate memory through a command set (Read, Write, is memory present, is memory write protected,...). The memory answers are converted in SCSI status before being wrapped in USB CSW (Command Status Wrapper) and sent to the USB Host controller. Remember that because the USB bus is a one master bus (the USB Host), each data transfer is initiated by the USB Host, following a specific Command-Data-Status flow (see Figure 4.). This firmware is based on a scheduler with only the USB task running. Other application tasks can be very easily added into the scheduler without disturbing the USB management. 4

Figure 4. Command / Data / Status flow Ready Command Transport (CBW) Data OUT (from Host) Data IN (to Host) Status Transport (CSW) The CBW (Command Block Wrapper) contains some USB information such as the LUN addressed, the length of the SCSI command, and of course, it also contains the SCSI command for the memory. The data stage is not compulsory, depending on the SCSI command. For example, if the SCSI command is TEST UNIT READY, there is no data phase. The CSW (Command Status Wrapper) contains the SCSI status. If the status is GOOD, the Host will send the next following command. If the status is different from GOOD (FAILED, PHASE ERROR,...), the Host will ask for more information regarding the error by sending a REQUEST SENSE command. 5

Memory Organization Overview Figure 5. Memory logical organization overview From a USB Host point of view, the USB memory is organized in logical blocks (sectors) of 512 Bytes. MBR (Master Boot Record) PBR (Partition Boot Record) 512 Bytes 512 Bytes Data / FAT X sectors of 512 Bytes Logical disk 1 PBR (Partition Boot Record) 512 Bytes Data / FAT Y sectors of 512 Bytes Logical disk 2 The Host always addresses the memory with: the logical sector number the number of contiguous sectors to read / write. The MBR (Master Boot Record) is always located at address 0. It contains information regarding the whole memory and the number of logical partitions inside. In case of a memory that has only 1 partition, the MBR is optional and can be replaced directly by the PBR (Partition Boot Record) that contains information regarding the logical partition and the entry point of the FAT (File Allocation Table). 6

Memory Management As seen in Figure 3., each memory is interfaced to the Atmel firmware by a specific memory driver, interfaced in the ctrl_access.c and ctrl_access.h files. The following 8 functions have to be implemented in order to support a memory with the USB Mass Storage Device firmware. In order to support a new memory, the developer has to write the memory driver according to this memory interface. Some functions only return the status of the memory (present, write protected, total capacity and if the memory can be removed). The other functions are used to read or write into the memory. The functions read_10 and write_10 open the memory at a specific location. The functions usb_read and usb_write manage the data transfer between the USB Controller and the memory. Please refer to the Annex 1 and the Annex 2 for the write of these 2 functions. Most of these functions returns a Ctrl_status byte that could be: CTRL_GOOD: function is PASS and another command can be sent CTRL_FAIL: there is a fail in the command execution CTRL_NO_PRESENT: the memory is not present CTRL_BUSY: the current memory is not initialized or its status has changed Test_unit_ready Ctrl_status <mem>_test_unit_ready(void) This function test the state of memory. present? Return CTRL_NO_PRESENT Memory has changed? Return CTRL_BUSY Read_capacity Return CTRL_GOOD present? Return CTRL_NO_PRESENT Memory has changed? Return CTRL_BUSY Ctrl_status <mem>_read_capacity(u32 *u32_nb_sector) This function returns the address of the last valid sector, stored in u32_nb_sector. The sector size is fixed to 512 Bytes for OS compatibility. For example, a memory of 16KBytes returns ((16 x 1024)/512) -1) = 31 Write last sector address Return CTRL_GOOD 7

Write Protect Bool <mem>_wr_protect(void) This function returns FALSE if the memory is not write protected. This function returns TRUE if the memory is write protected. Write Protected? Return TRUE Return FALSE Bool <mem>_removal(void) This function returns FALSE if the memory can t be removed. This function returns TRUE if the memory can be removed. Removal removable? Return TRUE Return FALSE Read_10 Ctrl_status <mem>_read_10(u32 addr, U16 nb_sector) This function sets the sector address (addr) and the number of consecutive sector (512Bytes each) to read. present? Return CTRL_NO_PRESNT Memory has changed? Return CTRL_BUSY Store address and number of sectors to read Return CTRL_GOOD 8

Ctrl_status <mem>_usb_read(void) This function manages the data transfer from the memory to USB. The memory address and the number of sectors to read was previously defined by the <mem>_read_10(addr, nb_sector) function. Refer to the Annex 2 for copy data to USB. Usb_read present? Return CTRL_NO_PRESNT Copy data from memory to USB following Read_10 parameters Return CTRL_GOOD Write_10 Ctrl_status <mem>_write_10(u32 addr, U16 nb_sector) This function sets the sector address (addr) and the number of consecutive sector (512Bytes each) to write. present? Return CTRL_NO_PRESNT Memory has changed? Return CTRL_BUSY Store address and number of sectors to write Return CTRL_GOOD Usb_write Ctrl_status <mem>_usb_write(void) This function manages the data transfer from USB to the memory. The memory address and the number of sectors to read was previously defined by the <mem>_write_10(addr, nb_sector) function. Refer to the Annex 2 for copy data from USB. present? Return CTRL_NO_PRESNT Copy data from USB to memory following Write_10 parameters Return CTRL_GOOD 9

Integration of a Memory The integration of a memory on the USB Mass Storage stack is performed in the conf_access.h. The corresponding LUN has to be first set to ENABLE and the corresponding functions have to be defined. The USB Mass Storage stack supports up to 8 different LUN. Here is an example with the virtual memory sets as LUN_0: // Active the Logical Unit #define LUN_0 #define LUN_1 #define LUN_2 #define LUN_3 #define LUN_4 #define LUN_5 #define LUN_6 #define LUN_7 ENABLE DISABLE DISABLE DISABLE DISABLE DISABLE DISABLE DISABLE // LUN 0 DEFINE #define LUN_0_INCLUDE "lib_mem\virtual_mem\virtual_mem.h" #define Lun_0_test_unit_ready() virtual_test_unit_ready() #define Lun_0_read_capacity(nb_sect)virtual_read_capacity(nb_sect) #define Lun_0_wr_protect() virtual_wr_protect() #define Lun_0_removal() virtual_removal() #define Lun_0_read_10(ad, sec) virtual_read_10(ad, sec) #define Lun_0_usb_read() virtual_usb_read() #define Lun_0_write_10(ad, sec) virtual_write_10(ad, sec) #define Lun_0_usb_write() virtual_usb_write() 10

USB Configuration and Customizing USB Clock The USB clock is automatically configured using the FOSC value. The FOSC value is the oscillator frequency, in KHz, and is defined in the config.h file. For example, the value of FOSC is set to 16000 for an oscillator frequency of 16 MHz. Enumeration Parameters Vendor ID / Product ID Strings For an application based on the USB Mass Storage stack, the Vendor ID and the Product ID have to be changed with the ID assigned to the manufacturer by USB-IF. The Vendor ID and Product ID are defined in the conf_usb.h file. For this demo, these parameters are: #define VENDOR_ID 0xEB03 // Atmel vendor ID = 03EBh #define PRODUCT_ID 0x1320 // Product ID: 2013h = Mass Storage The manufacturer can change the USB strings in the conf_usb.h file. These strings are: Manufacturer Name Product Name Serial Number (at least 12 characters) Do not forget to adapt the string length definitions according to the modifications: #define USB_MN_LENGTH 5 #define USB_PN_LENGTH 28 #define USB_SN_LENGTH 13 Endpoint If an application uses different Endpoints than those used in the demo, this can be done in the conf_usb.h file by changing these define: #define EP_MS_IN 4 #define EP_MS_OUT 5 In such a case, do not forget to specify in the conf_usb.h file if the endpoints to use support the Ping-Pong mode or not: #define NO_SUPPORT_USB_PING_PONG or no define. 11

Annex 1: Reading Data from USB The figures below show how to manage a Bulk OUT endpoint. These algorithms can be used to build your own <mem>_usb_write function required by the USB Mass Storage Device stack. In case the OUT endpoint declared for the Mass Storage class does not support the Ping-Pong mode, the #define NO_SUPPORT_USB_PING_PONG has to be set in the conf_usb.h file. This disable the automatic management of the Ping-Pong for the mass storage endpoint. In case the OUT endpoint declared for the Mass Storage class does support the Ping- Pong mode, the #define NO_SUPPORT_USB_PING_PONG has to be removed in the conf_usb.h file. Figure 6. Reading data from USB In every case, the following functions of the USB driver can be used: Is_usb_receive_out(): this function check if a new OUT message has been received, for a ping-pong endpoint or not. Usb_read_byte(): this function return the current byte store in the endpoint FIFO. Usb_ack_receive_out_ms(): this function frees the last bank in the endpoint FIFO to allow a new OUT message to be stored. The behavior of this function is different if the endpoint support the ping-pong mode or not, that s why the user has to check if the #define NO_SUPPORT_USB_PING_PONG is correctly set or removed. #define NO_SUPPORT_USB_PING_PONG Ping-Pong supported RXOUT? ==0 RXOUTB0 or RXOUTB1? ==0 ==1 ==1 Read data from Endpoint data = Usb_read_byte(); Read data from Endpoint data = Usb_read_byte(); Clear RXOUT bit Usb_ack_receive_out_ms(); Clear RXOUTB0 or RXOUTB1 bit Usb_ack_receive_out_ms(); 12

Annex 2: Writing Data to USB The figures below show how to manage a Bulk IN endpoint. These algorithms can be used to build its own <mem>_usb_read function required by the USB Mass Storage Device stack. The standard management can be used for a standard endpoint or a Ping-Pong endpoint. It consists of writing into the endpoint FIFO, advise the USB controller that a new IN message is ready and wait for the data to be sent on the USB before writing new data. In order to increase Mass Storage Read performances, the firmware can be optimized if the IN endpoint declared for the Mass Storage Device class support the Ping-Pong mode. Figure 7. Writing data to USB Standard management Optimized for IN Ping- Pong Data to send to Host? Data to send to Host? Write data to Endpoint Usb_write_byte(data_to_write); Write data to Endpoint Usb_write_byte(data_to_write); Set TXREADY bit and wait transmission complete Usb_send_in(); Set TXREADY bit Usb_set_in_ready (); Data to send to Host? Write data to Endpoint Usb_write_byte(data_to_write); Transmission complete? Transmission complete? Ack transmission complete Usb_ack_in_ready() ; Ack transmission complete Usb_ack_in_ready() ; 13

Annex 3: Implementation Example with 1 Nand Flash The schematic below is an example of the USB Mass Storage key. This example is based on the AT89C5131 microcontroller. This microcontroller integrates a USB macro which supports the Ping-Pong mode on several endpoints. The writing speed is between 300 and 550 kbytes/s, depending on the FAT implementation. The reading speed is about 700-800 kbytes/s. P0 and P2 ports are mandatory in order to access the Nand Flash using MOVX instructions. Figure 8. Implementation example with the AT89C5131A and 1 Nand Flash 3.3V regulator Vcc 10µF Tantal. 100nF 10µF Tantal. Vbus D+ D- GND USB connector 1.5k 27 27 VDD Vref D+ D- PLLF AVDD P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 I/O.0 I/O.1 I/O.2 I/O.3 I/O.4 I/O.5 Vcc 10nF 2.2nF P0.6 I/O.6 100 P0.7 I/O.7 optional PSEN Vcc Vcc 2.2k Vcc 100k AT89C5131A-M 2.2k 10k WP Nand Flash ISP EA P3.3 P2.4 P2.0 P2.1 R/B CLE ALE 22pF 24 MHz Xtal1 Xtal2 P3.7 P2.3 RE CE 22pF 1µF Ucap P3.6 P3.0 WE Vss AVss Vss Write Protection 2.2k 14

Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Regional Headquarters Europe Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland Tel: (41) 26-426-5555 Fax: (41) 26-426-5500 Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Atmel Operations Memory 2325 Orchard Parkway San Jose, CA 95131 Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 Microcontrollers 2325 Orchard Parkway San Jose, CA 95131 Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 La Chantrerie BP 70602 44306 Nantes Cedex 3, France Tel: (33) 2-40-18-18-18 Fax: (33) 2-40-18-19-60 ASIC/ASSP/Smart Cards Zone Industrielle 13106 Rousset Cedex, France Tel: (33) 4-42-53-60-00 Fax: (33) 4-42-53-60-01 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906 Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Scottish Enterprise Technology Park Maxwell Building East Kilbride G75 0QR, Scotland Tel: (44) 1355-803-000 Fax: (44) 1355-242-743 RF/Automotive Theresienstrasse 2 Postfach 3535 74025 Heilbronn, Germany Tel: (49) 71-31-67-0 Fax: (49) 71-31-67-2340 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906 Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Biometrics/Imaging/Hi-Rel MPU/ High Speed Converters/RF Datacom Avenue de Rochepleine BP 123 38521 Saint-Egreve Cedex, France Tel: (33) 4-76-58-30-00 Fax: (33) 4-76-58-34-80 Literature Requests www.atmel.com/literature Disclaimer: The information in this document is provided in connection with Atmel products. license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL S TERMS AND CONDI- TIONS OF SALE LOCATED ON ATMEL S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDEN- TAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Atmel s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. Atmel Corporation 2005. All rights reserved. Atmel, logo and combinations thereof, are registered trademarks, and Everywhere You Are SM are the trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. Printed on recycled paper. /xm