Freescale Semiconductor MC9S12, MC9S12UF32 User Manual

USB2.0 Card Reader
Designer Reference Manual
MC9S12 Microcontrollers
DRM065 Rev. 0.1 01/2005
freescale.com
USB2.0 Card Reader
Designer Reference Manual
by: Dennis Lui
Derek Lau Application 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 that you have the latest information available, refer to http://www.freescale.com
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
01/2005 0.1 Initial release N/A
Freescale Semiconductor 3
Revision
Level
MC9S12UF32 Card Reader Reference Design User Manual, Rev. 0.1
Description
Page
Number(s)
Revision History
MC9S12UF32 Card Reader Reference Design User Manual, Rev. 0.1
4 Freescale Semiconductor
Contents
Chapter 1
System Overview
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2 System Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.1 System Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.2 Cards Supported . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.3 MC9S12UF32 Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.3.1 MC9S12UF32 feature List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.4 System Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.4.1 Voltage Regulation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.4.2 Background Debug Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.4.3 USB Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.4.4 Memory Cards Interfaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Chapter 2 Hardware
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 M68EVB912UF32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3 Modifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Chapter 3
Software Overview
3.1 System Software Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Main Software Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.1 Main Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.1.1 USB Events Handler. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.1.2 USBMS Events Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.1.3 Card Insertion and Removal Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.2 Timer Interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2.3 USB Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3 Memory Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Chapter 4
USB Module
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2 Endpoints Configurations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.3 USB Device Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.4 Initialization the USB Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
MC9S12UF32 Card Reader Reference Design User Manual, Rev. 0.1
Freescale Semiconductor TOC-5
Chapter 5
Intelligence QUEUE Module
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.2 IQUEUE Request Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Chapter 6
USB Mass Storage Driver
6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.2 USB Mass Storage Class Bulk-Only Transport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.2.1 USB Command Block Wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
6.2.2 USB Command Status Wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.2.3 SCSI Command Descritpor Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.2.4 Example of Command Block Wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
6.3 Driver Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
6.3.1 Handling of USB Command Block Wrapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
6.3.1.1 Commands Without Data Transfer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
6.3.1.2 Host Sends out Data to Storage Device. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
6.3.1.3 Host Receives Data from Storage Device.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
6.3.2 Class Specific Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Chapter 7
Memory Cards Mass Storage Drivers
7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
7.2 RAM Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
7.3 Windows File Systems and MS/SM Data Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
7.4 Memory Card Mass Storage Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
7.4.1 Commands Without Data Transfer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
7.4.2 Host Sends out Data to card reader. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
7.4.3 Host Receives Data from Card Reader.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Chapter 8
Testing and Customization
8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
8.2 Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
8.2.1 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
8.2.2 Firmware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
8.2.2.1 UF32 Card Reader Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
8.2.2.2 Mini-Kernel Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Chapter 9
Glossary
MC9S12UF32 Card Reader Reference Design User Manual, Rev. 0.1
TOC-6 Freescale Semiconductor
Chapter 1 System Overview
1.1 Introduction
This manual describes a reference design of a Universal Serial Bus Card Reader solution by using the MC9S12UF32. The software was developed under the M68EVB912UF32 evaluation platform board. Some hardware modifications are required in order for the software to be used under the board. The firmware source codes are available as reference materials.
1.2 System Features
1.2.1 System Features
USB 2.0 High Speed and Full Speed Compliance.
Windows 98 SE, Windows 2000 and Windows XP Compatible
In Circuit Evaluation and Programming
1.2.2 Cards Supported
CompactFlash Card (Type 1 and II)
Memory Stick
Memory Stick Duo
•Magic Gate
Secure Digital
MultimediaCard
SmartMedia
1.3 MC9S12UF32 Features
The MC9S12UF32 microcontroller (hereafter referred as UF32) features an integrated Universal Serial Bus (USB) 2.0 controller and physical layer transceivers to provide comprehensive USB specification implementation for both high-speed (480 Mbps) and full-speed (12 Mbps) operations. The high-speed operation, running at bus speed of 30 MHz, implements fast large data transfers for applications such as real-time movies that were impractical at the previous lower-speed operation.
Besides standard USB functionality, the UF32 enables control of external hard disk drives, CD-ROM and DVD-ROM drives. The UF32 also enables controls of different common Flash memory devices including: CompactFlash, Secure Digital, MultiMediaCard, SmartMedia and Memory Stick memory cards.
The availability of up to 75 programmable I/O lines helps to minimize the system costs and enhance flexibility.
MC9S12UF32 Card Reader Reference Design User Manual, Rev. 0.1
Freescale Semiconductor 7
System Overview
C
The UF32 is designed to reduce overall system components count and to improve performance by off-loading peripheral overhead functions from the CPU. The on-board Flash enables the peripheral system to accommodate future software upgrades. The UF32 can be used in card readers for popular Flash memory cards, ATA/ATAPI bridges for external hard disks and DVD ROM, USB Flash disks and digital wallets.
There are 100-pin and 64-pin options for the UF32. The 100-pin device is designed for card reader and digital wallet applications while the 64-pin device is designed for ATA/ATAPI bridge with SD access or USB applications with SM, SD and MS access, and other USB applications that do not require so many I/O pins.
1.3.1 MC9S12UF32 feature List
HCS12 core
32K Bytes Flash, 3.5K Bytes RAM, 1.5K Bytes Queue RAM
Universal Serial Bus 2.0 controller and transceivers
Integrated Queue controller
ATA/ATAPI Host controller
CompactFlash Host controller
Secure Digital and MultiMediaCard Host controller
SmartMedia and NAND Flash Host controller
Memory Stick Host controller
8-channel, 16-bit timer
Serial Communications Interface
1.4 System Overview
5V
VDDR
REF3V
3.3V
VDD3X
VDD
VDDX
3.3V
3.3V
5V
2.5V
REG
2.5V
S12 Core
VDDA
USB
5/3.3V
5/3.3V
MC9S12UF32
PORTE5V
PORTQ
PORTP
PORTM
PORTJ
PORTT
PORTU
PORTS
PORTR
PORTB
PORTA
BDM
USB
SM
SD/MM
MS
CF
MC9S12UF32 Card Reader Reference Design User Manual, Rev. 0.1
8 Freescale Semiconductor
Figure 1-1. Block Diagram
System Overview
Since the UF32 is a highly integrated high-speed USB 2.0 device with embedded CF, MS, SD/MMC and SM host controllers, the major components to implement a card reader include only a UF32, a MOSFET for 3.3V regulation and the memory cards sockets.
The system functions can be divided into the following parts.
Voltage regulation
Background debug interface
USB interface
Memory card interfaces
1.4.1 Voltage Regulation
The UF32 is designed for a single 5V voltage input. There are three kinds of I/O:
Port E of 5V I/O
Port J, M, P and Q of 5V or 3.3V I/O powered by V
Port A, B, R, S, T and U of 5V or 3.3V I/O powered by VDDX
For UF32 used in card reader applications VDDX and VDD3X are set to 3.3V. Therefore, only the Port E is with 5V I/O while the others are with 3.3V I/O.
The UF32 has got four built-in regulators:
2.5V regulator for S12 core use
2.5V regulator for USB transceiver use
3.3V regulator for USB transceiver and PLL use
3.3V regulator that needed an external MOSFET
DD3X
The S12 core is powered by the internal 2.5V regulator. The USB transceivers and PLL is powered by the internal 3.3V regulator. The UF32 needs a 5V power supplied to V
DDR. The external MOSFET is
regulated by the analog output REF3V to provide 3.3V supply to VDD3X, VDDX and to the memory cards.
1.4.2 Background Debug Interface
The single-wired background debug pin BKGD is used for software development and programming.
1.4.3 USB Interface
The UF32 featured an integrated Universal Serial Bus (USB) 2.0 controller and physical layer transceivers. An external 1.5K pullup resistor and four serial resistors are required for USB connection.
1.4.4 Memory Cards Interfaces
The UF32 contains CF, MS, SM and SD host controller interfaces that can direct connect to the memory cards. Only pullup and pulldown resistors are needed to connect the UF32 to the memory cards.
MC9S12UF32 Card Reader Reference Design User Manual, Rev. 0.1
Freescale Semiconductor 9
System Overview
MC9S12UF32 Card Reader Reference Design User Manual, Rev. 0.1
10 Freescale Semiconductor
Chapter 2 Hardware
2.1 Introduction
The hardware used in the reference design is based on the M68EVB912UF32 evaluation platform board. Some hardware modifications are required in order for the software to be used under the board. Please refer to the user manual and the schematics of the board for detail operations. The board was not optimized design for a card reader. To implement a card reader, customer may refer to the schematic provided in this reference design.
2.2 M68EVB912UF32
The M68EVB912UF32 evaluation platform board (hereafter referred as EVB) consists of a 100-pin package UF32, a 12V to 5V DC-DC converter, a RS-232 transceiver and some other glue logics. It has built-in sockets for the mass storage memory cards. Please refer to the user manual of the board for detail operations.
Figure 2-1. M68EVB912UF32 Evaluation Board
MC9S12UF32 Card Reader Reference Design User Manual, Rev. 0.1
Freescale Semiconductor 11
Hardware
2.3 Modifications
The EVB allows the CompactFlash interface to be 5V or 3.3V by software configuration while the other memory cards interfaces are fixed to 3.3V. Some of the card detection pins are not connected to the UF32. The modifications are to fix the CF interface to be 3.3V and to connect the card detection pins to the UF32.
JP10
CF_CD
JP9 JP10
SD_CD
UF32
W19
SD_WP
MSSINS
JP16
CR5
Figure 2-2. Modifications Connections
Figure 2-2 shows the modifications required:
Short CR5 to bypass the diode (needed for EVB of revision 5 or older version)
Short W19 pin 1, 2 and 3
Connect JP10 pin 5 and JP9 pin 4 for CompactFlash card detection
Connect JP16 pin 12 and JP9 pin 5 for Secure Digital card detection
Connect JP16 pin 14 and JP9 pin 9 for Secure Digital card write protect detection
Connect JP16 pin 16 and JP9 pin 8 for Memory Stick card detection
MC9S12UF32 Card Reader Reference Design User Manual, Rev. 0.1
12 Freescale Semiconductor
Chapter 3 Software Overview
3.1 System Software Architecture
Mini-
Kernel
for UF32
MCU Resources (Timer, IRQ…)
Memory Device
Interface Module
Application Task
(Protocol Adapter)
USB Mass Storage
SCSI Command Module
USB Protocol Layer
Mass
Storage
Device
Figure 3-1. System Software Architecture
The software was developed under CodeWarrior Development Studio for HC(S)12 Microcontrollers version 3.1. Figure 3-1 shows the System Software Architecture for the UF32 Card Reader. The mini-kernel is designed for multi-tasks operation. In this application, it mainly handles the USB event tasks and the timer hook function tasks after system initialization. The initialization subroutines initialize the modules of Timer, Voltage Regulator, IQUEUE RAM, IQUEUE, and USB Controller. The main program continually checks and serves different event tasks. The memory card host controller will be initialized after the card is inserted.
MC9S12UF32 Card Reader Reference Design User Manual, Rev. 0.1
Freescale Semiconductor 13
Software Overview
MAIN PROGRAM
INITIALIZATION
USB EVENTS
HANDLER
USBMS EVENTS
HANDLER
CARD INSERTION &
REMOVAL HANDLER
3.2 Main Software Flow
TIMER INTERRUPT
CHECK AND SERVE
ANY HOOK FUNCTION
INCREASE GLOBAL TIMER
COUNTER FOR EVERY 1
RETURN
m
s
Figure 3-2. Main Software Flow
USB INTERRUPTS
USB ENDPOINT 0
HANDLER
USBMS BULK IN
HANDLER
USBMS BULK OUT
HANDLER
RETURN
3.2.1 Main Program
The USB events handler puts the UF32 into suspend when USB bus suspend is detected. The USB Mass Storage (USBMS) handler calls corresponding routines for different USBMS commands. The card insertion and removal handler checks any card is inserted into or removed from the sockets.
3.2.1.1 USB Events Handler
The USB Events Handler puts the UF32 into STOP mode when the USB suspend is detected.
3.2.1.2 USBMS Events Handler
The USB Events Handler handles the USB Mass Storage reset and the USB Mass Storage Command Block Wrapper.
3.2.1.3 Card Insertion and Removal Handler
The card insertion and removal handler checks any card inserted or removed from the sockets for every 100ms. The time interval is defined in the timer hook function. If any card is detected to be inserted, the handler will enable and initialize the card host controller. If any card is detected to be removed, the handler will disable the card host controller.
MC9S12UF32 Card Reader Reference Design User Manual, Rev. 0.1
14 Freescale Semiconductor
Loading...
+ 32 hidden pages