Analog Devices EE196 Application Notes

Engineer To Engineer Note EE-196
a
Technical Notes on using Analog Devices' DSP components and development tools
Contact our technical support by phone: (800) ANALOG-D or e-mail: dsp.support@analog.com Or vi sit ou r on-l ine re sourc es ht tp:// www.analog.com/dsp and http://www.analog.com/dsp/EZAnswer
ADSP-BF535 Blackfin® EZ-KIT Lite™ CompactFlash® Interface
Contributed by Hiren Desai June 4, 2003

Introduction

CompactFlash® storage cards provide the capability to easily transfer/store all types of digital information, such as data, audio, and images, between large varieties of digital systems. CompactFlash cards are high density (up to 1Gbytes of nonvolatile storage memory!), removable (i.e. hot-swappable), and very compact in size. CF™ cards can be used as memory storage devices for digital imaging, video, audio, PDAs, etc. but they can also be extended for I/O communications applications such as modems, Ethernet controllers, laser scanners, BlueTooth Wireless, 802.11 WiFi LAN, wireless digital cell phone cards, and GPS nodes.
This note describes one way to interface a CompactFlash Storage Card to the ADSP-BF535 EZ-KIT Lite™ Evaluation Board. The interface consists of a hardware and software implementation, both of which will be discussed in this application note. In this example, the interface will demonstrate the playing of MP3 tracks (stored on the CompactFlash card) by the ADSP-BF535 Blackfin® processor.
configured/formatted by a Windows host PC, it appears to the host as a standard ATA (IDE) disk drive.
Figure 1. CompactFlash Storage Card Block Diagram
Because of this, CompactFlash cards can be easily interfaced to the ADSP-BF535 Blackfiin processor’s Asynchronous Memory through the External Bus Interface Unit (EBIU). The EBIU provides glueless interfaces to external memories.
s

Overview

CompactFlash Cards conform to the CF and CF+
standard published by the CompactFlash
Association (CFA). There is an on-card intelligent controller that manages interface protocols, data storage and retrieval (see Figure
Figure 2. External Bus Interface Unit (EBIU)
1). Once the CompactFlash card has been
Copyright 2003, Analog Devices, Inc. All rights reserved. Analog Devices assumes no responsibility for customer product design or the use or application of customers’ products or for any infringements of patents or rights of others which may result from Analog Devices assistance. All trademarks and logos are property of their respective holders. Information furnished by Analog Devices Applications and Development Tools Engineers is believed to be accurate and reliable, however no responsibility is assumed by Analog Devices regarding technical accuracy and topicality of the content provided in Analog Devices’ Engineer-to-Engineer Notes.
a
]
]
]
[1]
]
[0]
[
]
The EBIU is clocked by the system clock (SCLK) of the ADSP-BF535 Blackfin processor. On the ADSP-BF535 Blackfin EZ-KIT Lite, SCLK is set to 120MHz, which will be more than sufficient for accesses to CompactFlash cards. Read/Write access times on CompactFlash cards are defined between 250ns – 300ns (~ 3 – 4 MHz). To find interface/bus timing, please refer to the CF/CF+ standard
.
CompactFlash cards function in three basic modes:
PC Card ATA using Common Memory Mode.
PC Card ATA using I/O Mode.
True IDE Mode.
This EE-Note will only deal with 16 bit transfers using Common Memory Mode.

ADSP-BF535 CompactFlash Interface Pin Mapping

ADSP-BF535
PF8 CD1
AOE OE
AWE
AMS[1
A[11
A[10:2
D[15:0
Vcc
10 kOhm
Address Bus
GND
Data Bus
CompactFlash
WE
CE2 REG
A[10:2] A
ABE[3] / A[1
A
D
15:0]
CompactFlash Signal Descriptions – Common Memory Mode
A[10:1]: Address Lines
D[15:0]: Data Lines
/WE (Write Enable): This signal is driven by
the ADSP-BF535 and used for strobing memory write data to the registers of the CompactFlash.
/OE (Output Enable): This strobe is generated by the ADSP-BF535 and used to read data from the CompactFlash.
REG (Attribute Memory Select): This signal is to distinguish between Common Memory and Register (Attribute) Memory accesses. High for Common Memory, Low for Attribute Memory.
/CE1, /CE2 (Card Enable): These signals are used both to select the card and to indicate to the card whether a byte or a word operation is being performed. Since both of these signals are tied to AMS[1] of the ADSP-BF535, we will be doing word (16-bit) accesses only.
/CD1 (Card Detect): This signal is used by the ADSP-BF535 to determine that the CompactFlash is fully inserted into its socket.
A[0]: Address line 0 is connected to ground since this interface supports word accesses only.

Software Implementation

Since we are using the CompactFlash as a PC card ATA using memory mode, it will be seen by the ADSP-BF535 as a standard ATA disk drive. The following gives a brief explanation of the file system used on standard disk drives.
Figure 3: CF Interface Pin Mapping
Figure 3 shows the main pin-to-pin connections between the ADSP-BF535 and the CompactFlash card.
ADSP-BF535 Blackfin® EZ-KIT Lite™ CompactFlash® Interface (EE-196) Page 2 of 15

FAT file system

Standard disk drives use the FAT (File Allocation Table) file system. Currently there are three types of FAT file systems: FAT12, FAT16, and FAT32. In a FATnn file system, nn
a
represents the size, in bits, of the entries in the actual FAT structure on the disk. There are 12 bits in a FAT12 FAT entry, 16 bits in a FAT16 FAT entry and 32 bits in a FAT32 FAT entry. Currently, this interface supports FAT16 only but other FAT systems could be implemented.
There are 4 basic regions on a FAT volume:
Reserved Region
FAT Region
Root Directory Region (non FAT32)
File and Directory Data Region
Disk Structure Sector Offset
Boot Sector 0
FAT 1 1
FAT 2 (# of Sectors per FAT) + 1
Name
JumpBoot 3 Jump Instruction to boot
OEMName 8 Name string – MSWIN4.1. BytesPerSector 2 SectorsPerCluster 1 1, 2, 4, 8, 16, 32, 64, 128. ReservedSectors 2 1 for FAT12 and FAT16. FATCount 1 2 FAT data structures. RootEntCount 2 # of 32-byte entries in root
TotalSectors1 2 Total # of sectors on volume
MediaDescriptor 1 0xF8 for fixed media. 0xF0
SectorsPerFAT 2 # of sectors in one FAT. SectorsPerTrack 2 Tracks are broken down into
Size (in bytes)
Description
code.
, 1024, 2048, 4096.
512
directory.
Bits[15:0].
for removable media.
heads and cylinders.
Root Directory 2*(# of Sectors per FAT)+1
File Clusters (Data
Region)
Table 2. Disk Structure
2*(# of Sectors per FAT)+1+(# of
Root Directory Sectors)

Reserved Region

The Reserved Region contains the Boot Sector which is the first sector of the volume. A summary of the FAT16 structure of the Boot Sector is provide below, starting with the first word at byte offset 0 (also applies to FAT12):
The Boot Sector contains all the information about the physical structure of the CompactFlash. This information is needed to determine where data is stored on the CompactFlash for retrieval.
HeadCount 2 Relevant for previous field. HiddenSectors 4 Count of hidden sectors
preceding FAT volume.
TotalSectors2 4 Total # of sectors on volume
Bits[47:16]. DriveNumber 1 This field is OS specific. Reserved 1 Reserved. BootSignature 1 Extended Boot Sig. (0x29). VolumeID 4 Volume serial number. VolumeLabel 11 Volume label. Reserved 8 Reserved.
Table 3. Boot Sector

FAT Region

There are two FAT data structures on the volume. The reason there are two is to provide redundancy for the FAT data structure so that if a sector goes bad in one of the FATs, the data is not lost because it is duplicated in the other FAT.
Each FAT is a single linked list of the clusters of a file. These clusters map to the data region of
ADSP-BF535 Blackfin® EZ-KIT Lite™ CompactFlash® Interface (EE-196) Page 3 of 15
a
the volume. The first 2 entries in the FAT are reserved so logical cluster numbers begin at 2.
FAT16 Table
O
f f
0
1
2
3
4
5
… ………
N-1 0012
N FFFF
Figure 4. FAT File System
Entry
(Next
Cluster)
FFF8
FFFF
0003
0004
000A
0008
(EOF)
Data Region
FAT16 entry values:
0x0000: Unused Cluster
0xFFF0 – 0xFFF6: Reserved Cluster

Root Directory

The Root Directory is composed of a linear list of 32-byte structures which represent files stored on the disk. The following table describes the different fields of a 32-byte structure within the Root directory:
Name Size
(in bytes )
Name 11 Short name. (see note below) Attr 1 Bit 0: READ_ONLY
NTRes 1 Reserved for Windows NT use. CrtTimeTenth 1 File creation time. Millisecond
CrtTime 2 File creation time. 2 second
CrtDate 2 File creation date. LstAccDate 2 Last read/write date of file.
Description
Bit 1: HIDDEN Bit 2: SYSTEM Bit 3: VOLUME_ID Bit 4: DIRECTORY Bit 5: ARCHIVE Bit 6: LONG_NAME Bits 7 and 8: RESERVED
granularity.
granularity.
0xFFF7: Bad Cluster
0xFFF8 – 0xFFFF: End of Cluster/File
Other: Next Cluster in File
The first sector is of cluster 2 and is calculated as:
FirstDataSector = ReservedSectors + (FATCount * SectorsPerFAT) + RootDirSectors
FstClusHI 2 File’s first cluster number;
bits[31:16]. This is 0 for
FAT12 and FAT16 volume. WrtTime 2 Time of last write. WrtDate 2 Date of last write. FstClusLO 2 File’s first cluster number;
bits[15:0]. FileSize 4 File size in bytes.
Where
RootDirSectors = ((RootEntCount * 32) + (BytesPerSector – 1)) / BytesPerSector
The first sector of any cluster N is calculated as:
FirstSectorofCluster = ((N – 2) * SectorsPerCluster) + FirstDataSector
Table 4. 32-Byte Directory Entry Structure.
Note, if the first byte of the Name field =
0xE5: then the entry is free.
0x00: then the entry is free; there are no
more allocated entries after this one.
Values less than 0x20: Not Valid (except 0x05 Å used in Japan).
ADSP-BF535 Blackfin® EZ-KIT Lite™ CompactFlash® Interface (EE-196) Page 4 of 15
a
Long file names are not supported in this software interface.
For FAT32 file systems, the root directory can be of variable size and is a cluster chain.
For FAT12 and FAT16 file systems, the root directory immediately follows the last FAT and has a fixed location and fixed size on the disk. The first sector of the Root Directory is computed as:
FirstRootDirSec = ReservedSectors + (FATCount * SectorsPerFAT)
Blackfin External
Memory Address
0x2400 0800 D[7:0] 0 0 1 0 XX 0 Even RD Data Even WR Data 0x2400 0800 D[15:8] 0 0 1 0 XX 0 Error Feature 0x2400 0802 D[7:0] 0 0 1 0 XX 2 Sector Count Sector Count 0x2400 0802 D[15:8] 0 0 1 0 XX 2 Sector Number Sector Number 0x2400 0804 D[7:0] 0 0 1 0 XX 4 Cylinder Low Cylinder Low 0x2400 0804 D[15:8] 0 0 1 0 XX 4 Cylinder High Cylinder High 0x2400 0806 D[7:0] 0 0 1 0 XX 6 Select Card / Head Select Card / Head
ASM[1]
[ CE2 ] [ CE1 ]
A[11]
A[10] A[9:4]
[ REG ]

Software Accesses to the CompactFlash

In Common Memory Mode, accesses to the CompactFlash are done through a set of memory­mapped registers. The following lists them out (last two columns of Table 5) as well as the state of the pins required to access them:
A[3:0] (HEX)
AOE [ OE ] = 0
ATA Read Register
AWE [ WE ] = 0
ATA Write Register
0x2400 0806 D[15:8] 0 0 1 0 XX 6 Status Command 0x2400 0808 D[7:0] 0 0 1 0 XX 8 Dup. Even RD Data Dup. Even WR Data 0x2400 0808 D[15:8] 0 0 1 0 XX 8 Dup. Odd RD Data Dup. Odd WR Data 0x2400 080C D[15:8] 0 0 1 0 XX C Dup. Error Dup. Features 0x2400 080E D[7:0] 0 0 1 0 XX E Alt. Status Device Control 0x2400 080E D[15:8] 0 0 1 0 XX E Drive Address Reserved 0x2400 0C08 D[7:0] 0 0 1 1 XX 8 Even RD Data Even WR Data 0x2400 0C08 D[15:8] 0 0 1 1 XX 8 Odd RD Data Odd WR Data
Table 5. Memory Mapped Decoding
L PLEASE NOTE – Since we have A[0] tied to ground, we can only do 16-bit accesses to the
CompactFlash with this interface.
Detailed information of these registers can be found in the CF and CF+ standard
.
The ADSP-BF535 is connected to the CF via Asynchronous Bank 1 (ASYNC Bank 1) of the External Bus Interface Unit (EBIU). The starting location of ASYNC Bank 1 is memory mapped
to address 0x2400 0000 and uses AMS[1] as the memory bank select line.
From Table 5, we can see that each read/write access on the ADSP-BF535 will affect two CF registers. For example, the following piece of code shows how to set up the Cylinder registers
ADSP-BF535 Blackfin® EZ-KIT Lite™ CompactFlash® Interface (EE-196) Page 5 of 15
Loading...
+ 10 hidden pages