USB Thumb Drive: Designer Reference Manual
USB Thumb Drive: Designer Reference Manual
USB Thumb Drive: Designer Reference Manual
HCS12 Microcontrollers
freescale.com
by:
Kenny Lam, Derek Lau, and Dennis Lui Applications Engineering Microcontroller Division Hong Kong
To provide the most up-to-date information, the revision of our documents on the World Wide Web will be the most current. Your printed copy may be an earlier revision. To verify you have the latest information available, refer to: http://www.freescale.com/
Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. This product incorporates SuperFlash technology licensed from SST. Freescale Semiconductor, Inc., 2004. All rights reserved. USB Thumb Drive Designer Reference Manual, Rev. 0 Freescale Semiconductor 3
Revision History
The following revision history table summarizes changes contained in this document. For your convenience, the page number designators have been linked to the appropriate location.
Revision History
Date September, 2004 Revision Level N/A Initial release Description Page Number(s) N/A
Table of Contents
Chapter 1 System Overview
1.1 1.2 1.3 1.4 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . System Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Mass Storage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 7 8 8
Chapter 3 Hardware
3.1 3.2 3.2.1 3.2.2 3.2.3 3.2.4 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . System Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . UF32 Microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . NAND Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Voltage Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Integrated Queue Module (IQUE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 13 13 13 14 14
Chapter 4 Firmware
4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 4.11 4.12 System Software Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . UF32 Memory Mapping for Thumb Drive. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Logical to Physical interrelation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Logical to Physical Block Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Physical Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Logical Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Logical to Physical Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . SCSI Command Handling Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . SCSI Command Read Packet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . SCSI Command Write Packet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Write Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . UF32 Thumb Drive Firmware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 16 17 17 18 18 19 19 20 21 22 22
Table of Contents
1.2 Features
USB2.0 high speed and full speed compliance Windows 2000 and Windows XP compatible No specific driver required Small size and easy to use Store all your data, pictures, music, and movies
Figure 1-1. Enlarged Photograph of the USB Thumb Drive Reference Design
System Overview
THUMB DRIVE
Personal Computer
USB2.0 Interface
SmartMedia Interface
Figure 2-1. Removable Disk Figure 2-1 shows the Removable Disk as F: drive since this systems CD-ROM is assigned as E: drive.
Basic Function
2.5 Unplug
You can remove the device after you finish the action with the device. However, in Windows ME and Windows 2000, please follow the safe removal procedure. You can find a safe removal icon on your computers notification area. Double click the safe removal icon; the Unplug or Eject Hardware window will be pop up. You can select the device you want to remove. Then, click the [Stop] button. After that you can unplug the device from the USB port of your computer. When you want to remove the USB FLASH DRIVE device, make sure the LED is not flashing. When the LED flashes quickly, there are some traffic on going between the OS and the USB FLASH DRIVE device. Dont remove the USB FLASH DRIVE at this moment. Otherwise, it will cause some damages to the data or even the USB FLASH DRIVE device itself. WARNING In Windows ME and Windows 2000 operating systems, you must use the hardware safe removal procedure, otherwise data loss caused by the write cache issue may happen.
Figure 2-2. Safe Removal Icon Figure 2-2 shows the Safely Remove Hardware icon for user unplug the USB MS device.
Unplug
Figure 2-3. Unplug the USB Mass Storage Device Figure 2-3 shows the Unplug USB Mass Storage device. User has to click it and select Stop USB Mass Storage Device - Drive (F:) before physically unplugging the Thumb Drive.
Basic Function
Chapter 3 Hardware
3.1 Introduction
The UF32 has 32K-bytes of Flash memory, 30MHz bus speed, a Smart Media (hereafter referred as SM) module and appropriate number of I/O pins makes this MCU suited for thumb drive solutions. The main features of the reference design include: USB interface 480Mbps data transfer rate LED display
USB2.0 Interface
SmartMedia Interface
Hardware
9S12UF32
PORTE
VDDX
3.3V
PORTA
Figure 3-2. Voltage Configuration Figure 3-2 shows the voltage configuration for UF32.
S12 CPU
USB USB
IQRAM
IQUEUE RAM
Figure 3-3. Integrated Queue Module (IQUE) Figure 3-3 shows the Integrated Queue Module (hereafter referred as IQUE). The IQUE module is designed to allow the data transfer to and from between NAND Flash memory and PC host without CPU interruption. It can help to minimize the overhead at CPU side.
Chapter 4 Firmware
4.1 System Software Architecture
MCU Resources (Timer) Mini-Kernel for UF32 Mass Storage Interface Module Mass Storage Device
SM Protocol Module
Figure 4-1. System Software Architecture Figure 4-1 shows the system software architecture for the UF32 Thumb Drive. The mini-kernel is designed for the multi-tasks operation. In this application, mini-kernel is mainly working for the USB event task after system initialization. The initialization subroutines are for the system initialization, such as for timer module, 3.3 voltage regulator, SM module, IQUE module, IQUE RAM mapping, SM RAM for logical to physical look up table and USB module. The main program continually checks the tasks and to serve the event once the request is made. It will decode to invoke the SCSI commands if the request is made from PC via USB2.0 interface. All data will pass through the IQUE RAM and read/write to NAND Flash.
Firmware
NOTES:
$C000 16K FLASH $FF00 $FFFF Vectors Normal Mode
QRAM is mapped to $2000$25FF by writing 0x21 to the INITEE register. SM Mode is enabled by setting the SMMODE bit of the SMRAM configuration register.
Figure 4-2. UF32 Memory Mapping for Thumb Drive Figure 4-2 shows memory mapping for Thumb Drive application. It is to configure 2K x 10-bit RAM for RAM block 0 ($0800$0FCF) and RAM block 1 ($1000$17CF). The system RAM is located from $1BC4 to $1FFF. The firmware is stored to upper flash block $C000$FFFF. The RAM block (0,1) are designed to store the look up tables for the logical to physical block conversion. The RAM block 0 is to store the conversion table for the physical segment 0 of the NAND Flash, which is to store boot record, FAT table, and directories content. The RAM block 1 is to store the conversion tables for the physical segment 1 to 3 of the NAND Flash for the file data content.
Figure 4-3. Logical to Physical interrelation Figure 4-3 shows the interrelation between PBA and LBA. The cluster is configured as 16K (32 sectors or pages) in the above example. Normally, the cluster can be configured as 1K, 2K, 4K, etc., in FAT16 format.
Application File File Management LBA Device Driver PBA NAND Flash
Thumb Drive Physical Format Card Information Structure Zone Boundary Concept Logical Block Address (LBA) ECC Area
Figure 4-4. Logical to Physical Block Format Figure 4-4 shows the logical to physical block format in the Thumb Drive application. The UF32 is working from the Device Driver down to NAND Flash physical layer.
Firmware
Figure 4-5. Physical Format Figure 4-5 shows the NAND Flash physical relationship between the blocks and the pages (or sectors). The physical block is defined as memory erase unit and the physical page is defined as memory write/read unit. In this case, one physical page has 512 bytes and one physical block has 32 physical pages.
sector 127413
Figure 4-6. Logical Format Figure 4-6 shows the logical format in the Thumb Drive application. FAT16 is selected as the system format, which can be recognized by Windows 2000 and Windows XP.
1 2 3
999
PBA no.
10-bit
Figure 4-7. Logical to Physical Address Translation Table Figure 4-7 shows the logical to physical translation table. It reads the ExtraDataArea of physical block of the NAND Flash to retrieve the logical address and store to the table. For high speed processing, it is desirable to construct a table of alternate blocks, as well as the logical/physical translation table. In this firmware, the RAM block 0 is to store the conversion table for the physical segment 0 of the NAND Flash, which is to store boot record, FAT table and directories content. The RAM block 1 is to store the conversion tables for the physical segment 1 to 3 of the NAND Flash for the file data content.
SmartMedia
SM_SCSICommand()
USB_MS
Firmware
Figure 4-8 shows the flow of the SCSI command handling flow. The host sends the Command Block Wrapper (hereafter referred as CBW) to UF32 via USB2.0 interface. The SCSI command handling firmware will then respond to the host regarding to the corresponding SCSI command.
Get LBA
RTS
Figure 4-9. SCSI Command Read Packet Figure 4-9 shows the flow of the SCSI command read packet. The data of the corresponding LBA will be sent to the host via USB2.0 interface once the UF32 receives a SCSI command (0x28). The firmware gets the LBA and determines its corresponding segment for update the logical to physical table LogToPhyTbl if necessary. The Physical Block Address (hereafter referred as PBA) can be converted from the LogToPhyTbl. The data can be retrieved from NAND Flash according to this PBA by the UF32 and sends them to PC host via USB2.0 interface.
Get LBA
Even when updating only one sector/page in a block, be sure to write all pages from the lowest number page
Update LogToPhyTbl
RTS
Figure 4-10. SCSI Command Write Packet Figure 4-10 shows the flow of the SCSI command write packet. Similarly, the data of the corresponding LBA will be sent from host via USB2.0 interface through UF32 IQUE module to NAND Flash. The firmware gets the LBA and determines its corresponding segment for update the logical to physical table LogToPhyTbl if necessary. The PBA can be converted from the LogToPhyTbl. The data can be written to NAND Flash according to this PBA by the UF32 from PC host via USB2.0 interface
Firmware
5.2 Customizing
5.2.1 Hardware
5.2.1.1 NAND Flash The Toshiba NAND Flash used in this reference design was a random selection. User can choose from any NAND Flash vendors.
5.2.2 Firmware
5.2.2.1 NAND Flash Size 512 Mbit NAND flash size is used in this reference design. User needs to change the parameters in boot_64M() subroutine if a 1-Gbit NAND Flash size is used.
Information in this document is provided solely to enable system and software implementers to use Freescale Semiconductor products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits or integrated circuits based on the information in this document. Freescale Semiconductor reserves the right to make changes without further notice to any products herein. Freescale Semiconductor makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpose, nor does Freescale Semiconductor assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. Typical parameters which may be provided in Freescale Semiconductor data sheets and/or specifications can and do vary in different applications and actual performance may vary over time. All operating parameters, including Typicals must be validated for each customer application by customers technical experts. Freescale Semiconductor does not convey any license under its patent rights nor the rights of others. Freescale Semiconductor products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which the failure of the Freescale Semiconductor product could create a situation where personal injury or death may occur. Should Buyer purchase or use Freescale Semiconductor products for any such unintended or unauthorized application, Buyer shall indemnify and hold Freescale Semiconductor and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that Freescale Semiconductor was negligent regarding the design or manufacture of the part. Freescale and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. Freescale Semiconductor, Inc. 2004.