CY4611B – FX2LP USB to ATA/CF Reference Design Notes
Introduction
Cypress has two USB 2.0 High Speed Mass Storage
solutions. The AT2LP is a low-power fixed-function
Mass Storage solution for ATA devices. The
CY4611B is a flexible bridge solution that enables
additional features to be added to a USB 2.0 bridge
device. The Cypress EZ-USB FX2LP Mass Storage
reference design connects the EZ-USB FX2LP to
the following device types:
• IDE devices 3.5”, 2.5” Hard disk drives
• Compact Flash & micro drives
• ATAPI devices
ZIP drives
CD-ROM/R/RW drives
DVD-ROM/RAM/RW drives
Reference Design Contents
•FX2LP Mass Storage Reference Design
PCBA
•Reference Design Schematic in both PDF
and OrCAD source files
• Reference Design BOM
• Firmware source and object code
• Reference Design Notes (this document)
• UDMA White Paper
• Driver INF and .SYS files
• Operating Instructions
• Manufacturing tools
• Release Notes
• Errata
Background Information
You should be familiar with the USB Mass Storage
Class specification and general operation of
Cypress’ EZ-USB FX2LP to get the most from this
document. For more information please refer to
these specifications or Cypress’s EZ-USB FX2LP
Technical Reference Manual.
Mass Storage Class Specification
The USB Mass Storage Class specification contains
two subclasses, the CBI (Command, Bulk, Interrupt),
and the newer Bulk Only Transport. This reference
design complies with the Bulk Only subclass of the
USB Mass Storage Specification. The Bulk Only
subclass is supported by the Windows XP, 2000 and
ME drivers as well as MacOS 9 and X. Cypress
provides custom drivers for Windows and Macintosh
operating systems to add support for security and
SMART monitoring. The latest driver versions are
available on the Cypress website.
Firmware Overview
Note: CBW, CSW, dataTransferLength, and
“Persistent Stall” are defined in the “USB Mass
Storage Class, Bulk Only Transport” document
referenced below.
The firmware for the device is a straightforward
implementation of a USB Bulk Only Mass Storage
Device. After reset, it waits for a CBW packet,
checks it and then executes the data phase of the
command (if any). Once the data phase is
complete, the firmware sends a CSW packet to the
host. SETUP commands are handled in an ISR. A
timer ISR is used to poll VBUS and GPIOs. The
only commands that the firmware generates on its
own are SCSI Identify Device (to get the device
name) and ATA Identify Device (to get the device
serial number).
The CY4611B firmware supports both high speed
(480Mbps) and full speed (12Mbps) hosts.
Firmware Details
Refer to the flowchart on the following page for more
details.
There are three main sections in the firmware:
• Initialization
• Command (CBW) processing
• ISRs
The initialization code sets up the hardware, reads
the EEPROM configuration and detects the attached
drives. Initialization routines include
resetATAPIDevice, ATAInit, initUSB, TD_Init,
detectSCSIvsATA, and ATAPIIdDevice. When the
initialization code is complete, the hardware is set
up, drives are fully enumerated, GPIF is loaded and
the firmware is ready to accept CBW commands.
The CBW processing takes place in the TD_Poll()
loop. This loop also polls the sleep flag to determine
Cypress Semiconductor Corporation • 3901 North First Street • San Jose • CA 95134 • 408-943-2600
7/11/05
EZ-USB FX2LP USB to ATA Reference Design Notes
if it is time for USB suspend. The final function of
the main loop is to poll for new removable (CF)
devices.
The ISRs have two main functions. They handle
SETUP command processing and background
polling for events like VBUS removal, GPIO changes
and ATA_ENABLE changes.
Main()
This routine calls the TD_Init and ATAInit routines
and then starts the master while(1) loop. The
while(1) loop polls the sleep flag and calls TD_Poll,
the main command processing routine.
ATAInit()
On a hard reset, TD_init() is called, which initializes
the hardware using initUSB(). The
resetATAPIDevice() routine is called to reset the
drive. After the drive has been reset the drive
discovery algorithm, detectSCSIvsATA(), is called
once for the master device and again for the slave
device.
Hardware
Reset of FX2
Initialize Hardware
[TD_Init, initUSB]
Initalize ATA Device
Detect ATAPI vs IDE
[resetATAPIDevice]
Wait for CBW
[TD_Poll()]
(USB Reset) or
(ATA_ENABLE -> disable)
in any state
Send CSW
[sendUSBS()]
detectSCSIvsATA()
The detectSCSIvsATA routine determines whether
the attached device is IDE or ATAPI by reading the
byte count registers. The scsi flag is set to 1 to
indicate an ATAPI device, scsi is set to 0 on an IDE
device. This routine sets the bDevicePresent flag
when a drive is successfully detected.
ATAPIIdDevice()
This routine is called to collect information from the
drive into internal data structures. This information
includes the max PIO or UDMA speed supported
and the serial number of the drive. If the device
supports PIO-3, PIO-4 or UDMA, this routine will
program the drive to run at the new speed.
LUN changed?
No
SCSI device?
[processCBW]
No
Translate ATAPI to IDE
command
generalIDEInCommand
generalIDEOutCommand
Send command to
device
[ideReadCommand
ideWriteCommand]
Yes
Change GPIF
Yes
Send command to
[sendSCSICommand]
TransferLen >
Transfer data via
PIO or UDMA
[Read/WritePIO16
Read/WriteUDMA()]
waveform s
device
data
0
Yes
No
Figure 1: Overall program flow
2
EZ-USB FX2LP USB to ATA Reference Design Notes
TD_Poll()
As in all Cypress Frameworks based code, the main
code loop is called TD_Poll(). This routine is called
repeatedly until it detects a packet in the OUT buffer.
TD_poll() checks the received packet for a valid
CBW signature. If one is found, it calls
processCBW(). If the packet is not a valid CBW, the
device enters a “persistent stall” condition awaiting a
device reset. ProcessCBW() checks to see if the
LUN has changed from the previous command. If
so, it reloads the GPIF with the proper waveforms
for the new LUN. It then calls
generalIDEInCommand() or
generalIDEOutCommand() depending on the
direction flag in the CBW. If the dataTransferLength
is non-zero, the readPIO16() or writePIO16()
routines are called to pass data directly from the
USB buffers to the drive using the GPIF.
SETUP messages are handled in an ISR, so they
may be received and responded to at any time. The
entire SETUP message will be handled within the
ISR, therefore long SETUP traffic will adversely
affect disk performance. This is not expected to be
an issue since Windows does not use SETUP
Filename Purpose
Dscr.a51 Descriptor table containing product/vendor ID, endpoint descriptions and other
information reported to the host on startup.
memcmp.a51 Fast memory compare routine
reset.a51 Assembly routine used to branch to 0 on USB reset.
Startup.a51 Modified Keil startup file that does not initialize any variables.
USBjmptbl.a51 USB interrupt vector table and other fixed-address blocks including space
allocation for EEPROM loader.
Atacb.c Processes ATACB (ATA Command Block) requests. The optional ATACB facility
allows IDE commands to be embedded within CBWs. This enables ANY
command to be sent to the device. This facility is used to allow access to security
features and SMART commands that do not have analogous SCSI commands.
atareset.c Contains hard reset routine, selection of IDE vs ATAPI protocol. Identifies device
characteristics, including serial number, capacity and transfer rate. Selects
transfer rate by loading new GPIF waveforms. Contains timer ISR that checks
VBUS and ATA_ENABLE.
fw.c Frameworks based main routine. This fw.c has major differences from the fw.c
released with the dev kit, since several implementation-specific functions have
been merged with the general startup code in this file.
gpif.c EZ-USB FX2LP low level i/o routines. Waveform descriptors. Routines for
loading the GPIF memory with the waveform descriptors.
Globals.c, Globals2.c Global variable definitions. The globals are split into two files to help the linker.
The linker will place all of the variables in a .c file in a single block. Splitting the
globals into two files allows some variables to be placed below the bit-
addressable memory (at 0x20) and some to be placed above the bit-addressable
memory.
packets after enumeration except to clear STALL
conditions.
These data transfer routines activate the GPIF to
move data to/from the FIFO memory to/from the
ATA bus. The data is read from the drive to the EP6
buffer. Write data moves from the host through the
EP2 buffer.
Resets
The firmware performs a hard reset of the drive on a
hard reset (power on). The firmware performs a soft
reset of the 8051 and drives on a USB Reset or
Mass Storage Class Reset.
File Descriptions
The FX2LP firmware is stored in its own directory.
All of the FX2LP firmware is contained in the FX2LP
source directory on the CD.
The purpose of the files in the source directory is
shown in the following table:
3
EZ-USB FX2LP USB to ATA Reference Design Notes
Filename Purpose
ide.c Translates SCSI (ATAPI) commands sent by the host driver into IDE commands.
Calls low-level transfer routines in gpif.c.
periph.c TD_Init and TD_Poll(), misc init routines, misc util routines including our smaller
version of memmove.
scsi.c High level data transfer routines for ATAPI devices. (Named SCSI.c because
ATAPI devices use the SCSI command set.) Calls low-level transfer routines in
gpif.c.
Globals.h Global variable references
atapi.h Header file containing application specific items.
gpif.h Header file containing hardware specific items.
scsi.h SCSI command set
CY4611B.Opt Options for UV2 project
CY4611B.hex Output file from the linker. Combine.bat is used to merge this file with a
configuration file like AT2_Legacy_pinout.iic to produce a full image like
CY4611B_AT2_pinout.iic.
CY4611B.Uv2 UV2 project file
AT2_Legacy_pinout.iic ~200 byte configuration file produced by blaster.exe
cy4611b_AT2_PINOUT.iic ~16K EEPROM binary image
0000
EEPROM configuration area
Many of the commonly changed items in the
CY4611B configuration have been moved to a
dedicated EEPROM configuration area. Locating
these items in a dedicated area allows customization
of many firmware attributes like Vendor ID and
Product ID without compiling the firmware.
The format of this EEPROM configuration area is
copied from the AT2LP and AT2. If the EEPROM
configuration starts with 0x4d4d, the 56-pin package
pinout will match the AT2 pinout. If the EEPROM
configuration bytes 0 and 1 are 0x534b then the 56pin pinout will match AT2LP. See the end of this
document for a full description of the EEPROM
config space format. A configuration tool is provided
to assist you in creating and downloading your
configuration file. This configuration utility
(blaster.exe) can be found in the “manufacturing
tools” directory on your CD. Blaster.exe can
program or modify the EEPROM configuration on
your CY4611B board.
The area allocated to EEPROM can be changed by
modifying the value of CONFIG_SPACE_START in
atapi.h and changing the –x argument passed to
hex2bix. If your application needs more than 0x100
bytes of EEPROM configuration, several areas of
the code will have to change. One area is
sendDescriptor, which uses a BYTE offset within the
EEPROM config space.
0x3eff
0x3f00
0x3fff
Figure 2: EEPROM memory map
The EEPROM settings can be programmed in two
ways, interactively via blaster.exe or by creating a
file. To program the EEPROM interactively, insert
the “MFG mode” jumper and cycle power on your
board. The board will bind to the manufacturing
driver. You can then use the “write to device” button
in blaster.exe to program your EEPROM.
Available for user code
CY4611.hex
EEPROM configuration
AT2LP_pinout.iic
4
EZ-USB FX2LP USB to ATA Reference Design Notes
Figure 3: MFG Mode jumper location
The default build script will automatically build a
unified image by combining cy4611b.hex with either
AT2_legacy_pinout.iic or AT2LP_pinout.iic to
produce CY4611B_AT2_PINOUT.iic or
CY4611B_AT2LP_PINOUT.iic.
The configuration section of the EEPROM can also
be modified without using the Keil tools. This
enables you to modify some settings (like the
Vendor ID and device name) without buying the Keil
tools. Just use the combine.bat file on the CD to
invoke hex2bix.exe.
cy4611b.hex
Output from Keil linker
hex2bix.exe
@0
CY4611B_AT2LP_PINOUT.iic
Binary file loaded to EEPROM
~16K bytes
AT2LP_PINOUT.iic
Saved from Blaster.exe
~200 bytes
hex2bix.exe
@0x3f00
Figure 4: Output files
Compile Time Configuration Settings
The most common configuration settings are
contained in the EEPROM configuration space
described above. However, command line options
and #defines control some of the compile time
settings used by the code. The major ones are
explained in the section below. To change some of
these settings, right-click on the project name in
uVision2 and select “options for target”, then select
the C51 tab.
Atapi.h contains additional #defines that can be
used to further customize the behavior of the
firmware. These can be found in a section of atapi.h
labeled “Configuration Settings”.
If you have one target platform, you will want to do
your customization in atapi.h. Creating defines in
the “options for target” tab allows you to create
multiple targets with different #defines. This is
useful if you have multiple targets (like debug vs
production).
DEVICE_TYPE_IS_SCSI
Setting this flag to 0 will remove most of the ATAPI
code from the EEPROM image. The resulting image
will only work with hard drive type devices. Set this
option to 0 to reduce code size.
Default Setting: 1
DEVICE_TYPE_IS_IDE
Setting this flag to 0 will remove most of the hard
drive / CF code from the EEPROM image. The
resulting image will only work with ATAPI devices.
Set this option to 0 to reduce code size.
Default Setting: 1
REVC_4611_BOARD
The first 4611 board with compactFlash support
changes several settings to make room for
compactFlash. These changes include moving the
interrupt input pin from PA0 to wakeup, and
multiplexing the VBUS sense with ATA_RESET.
This pinout is not recommended for new designs.
Default Setting: 0
Serial numbers
The USB Mass Storage specification requires that
each device have a unique serial number. Cypress
provides manufacturing tools to program your device
with a VID/PID and unique serial number. See the
5
EZ-USB FX2LP USB to ATA Reference Design Notes
“manufacturing tools” directory on the CD for more
information.
Some customers want to read the serial number
from the ATA or ATAPI device rather than from the
EEPROM. The following flags enable this function
in the firmware:
USE_ATA_DEVICE_SERIAL_NUMBER
For ATA devices, determines if the firmware uses
the serial number reported by the device as the USB
serial number. If TRUE, firmware uses the serial
number reported by the device in response to the
IDENTIFY_DEVICE command. If FALSE, the
firmware sets the USB serial number index to 0 (i.e.
no serial number string is reported in the device
descriptor).
Default Setting: FALSE
USE_ATAPI_DEVICE_SERIAL_NUMBER
For ATAPI devices, determines if the firmware uses
the serial number reported by the device as the USB
serial number. If TRUE, firmware uses the serial
number reported by the device in response to
IDENTIFY_DEVICE command. If FALSE, the
firmware sets the USB serial number index to 0 (i.e.
no serial number string is reported in the device
descriptor). Many ATAPI devices do not report a
unique serial number. It is better to report no serial
number than to report a non-unique serial number.
Default Setting: FALSE
NIBBLE_CONVERT_SERIAL_NUMBER
Determines if the firmware converts each nibble of
the serial number reported by the device into a
single character of the USB serial number. The
Bulk-only mass storage class spec only allows HEX
characters (0-9 and A-F) in the device serial
number. Some devices report other ASCII
characters. Converting each nibble into HEX
assures spec compliance while maintaining the
uniqueness of the serial number.
Default Setting: FALSE
Build Targets
There are two build targets for the CY4611B. They
use exactly the same options for everything except
one item. The CY4611B_AT2LP_PINOUT target
includes the AT2LP_PINOUT.iic when it calls
hex2bix.exe while the
CY4611B_AT2_LEGACY_PINOUT Includes the
AT2_LEGACY_PINOUT.iic configuration file.
6
EZ-USB FX2LP USB to ATA Reference Design Notes
Building the Software
Since the software is distributed on a CD, many
operating systems will set the read-only flag when
copying the data to your local directory. This flag
must be turned off before uVision2 will properly build
the .hex file. To do this, use “attrib –r *.*” at the
DOS command line or select all of the files in
Explorer, select “properties” and turn off the “readonly” checkbox in the “general” tab.
Once the files are no longer read-only, start the full
uVision2 or uVision3 environment (available
separately from www.keil.com
all” button. This will generate an image that can be
loaded with the control panel or the debugger. See
below for more information on debugging.
The firmware in this Reference Design has only
been tested with the release of the 3684 Dev Kit
contained on the release CD. Please install the
current Dev Kit before building.
The hex2bix.exe file in the software directory is
newer than the version in the CY3684 install.
Please use the version in the software directory.
You may have to delete the ezusb.lib file from your
project and add it again to get the correct path in the
Keil tools. The ezusb.lib file is installed at
c:\cypress\usb\target\lib by default.
Note: This Reference Design is too large to
compile with the 4K-demo version of the Keil
tools that is shipped with Cypress’ development
kits.
Warnings
When the firmware is linked, it will generate three
warnings. These warnings are expected. The linker
may have to run several iterations to optimize the
code and may generate this list two or three times
(and report six or nine warnings).
EZUSB_Delay is called from the timer0 ISR and
from the background code. This is not an issue
because any calls to the EZUSB_Delay function in
the ISR are followed by a soft reset.
The EEPROM read and write routines are only used
by the ISR during manufacturing and debugging
) and click the “build
operations. The background code is not active
during these operations.
*** WARNING L15: MULTIPLE CALL TO
FUNCTION
NAME: _EZUSB_DELAY/DELAY
CALLER1: ?C_C51STARTUP
CALLER2: ISRTIMER0/ATARESET
*** WARNING L15: MULTIPLE CALL TO
FUNCTION
NAME: _EEPROMWRITEBLOCK/EEPROM
CALLER1: ?C_C51STARTUP
CALLER2: ISR_SUDAV/PERIPH
*** WARNING L15: MULTIPLE CALL TO
FUNCTION
NAME: _EEPROMREAD/EEPROM
CALLER1: ?C_C51STARTUP
CALLER2: ISR_SUDAV/PERIPH
Using a CY3681 or CY3684 Board
The CY4611B software will run with the Keil
debugger on the FX2LP development board
(CY3684). This is a useful environment for
debugging startup issues by single stepping the
firmware. Note that the following changes to the
3684 board will be necessary:
1. Short solder points SP1, SP2 and SP3 to enable
ATA pullups.
2. Remove JP2 to remove VBUS power to the
board.
3. Connect VBUS (JP2 pin 2) to PA6 (P2 pin 13).
Put a 10K pulldown on this signal. This gives the
CPU the ability to sense VBUS.
4. Provide external 5v/ground to the board (JP2 pin
1 is a good 5v input). It will be very easy to use
the board if you solder a disk drive connector to
these pins.
5. Cut the Key pin (pin 20) on the ATA connector
(P8)
6. Add a 10K pulldown on DD7 (pin 3 on the 40-pin
connector).
7. Use the AT2_LEGACY configuration file.
Debugging without the Mass Storage Driver
Debugging specific commands requires a different
approach because the Mass Storage driver will
timeout while you are single stepping and may lock
up or reboot the host machine. The CY4611B
firmware can be bound to the Cyusb generic driver
by following these steps:
7
Loading...
+ 15 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.