How to Use Spansion LLD v5.13 to Implement a Flash Driver ™

How to Use Spansion™ LLD v5.13 to
Implement a Flash Driver
Application Note
By Victor Li
1. Overview
The Spansion Low Level Driver (LLD) is a production-grade driver toolbox that manages command initiation
and polling operations for the full range of Spansion memory devices featuring both MirrorBit® and floating
gate memory technologies.
Hardware capabilities available through the LLD interface include write buffer programming, suspend/resume
functions for program and erase, general purpose polling logic, and advanced sector protection.
Using the Spansion LLD, developing custom Flash drivers for your hardware platform or application is
relatively simple. The following is an example of how to use the LLD to communicate with a S29GL512N
(3V, 512 Mbit, x8/x16) device mounted on a PISMO PCI Card 3.1 using a simple API.
The tools being used include:
1. Spansion LLD v5.13
This source code can be obtained from the Spansion web site
http://www.spansion.com/support/drivers_software/index.html
2. Software tools
Microsoft® Visual C++
3. Hardware development tools
Spansion PCI v3.1
Magma PCI-to-PCMCIA
Spansion S29GL512N PISMO module
Figure 1.1 Hardware Development Tools
Windows PC
w/Visual C++
Magma
PCI-to-PCMCIA
Spansion
PCI Card v3.1
Publication Number LLD_v5.13_to_Flash_Driver
Spansion
S29GL512N
PISMO Module
Revision 01
Issue Date April 13, 2007
A pplication
Note
4. API (Application Program Interface)
The PISMO PCI Card 3.1 API is the library that provides the basic control function for the Spansion
PISMO module. Using this API, the user can implement the basic communication between the
Flash and the PC side.
2. Basic Communication Implementation between PC and Flash
The following eight functions are available when using the PISMO PCI Card 3.1 API library to implement
basic control between the PC and Flash:
1. SpPciLibEnumDevice
The SpPciLibEnumDevice function enumerates Spansion PISMO PCI cards, returning the device
identifier and the device name of one Spansion PCI card device with each call.
2. SpPciLibOpenDevice
The SpPciLibOpenDevice function returns a handle to an existing Spansion PISMO PCI card
device object.
3. SpPciLibCloseDevice
The SpPciLibCloseDevice function closes an open Spansion PISMO PCI card device object
handle.
4. SpPciLibGetMemoryBank
The SpPciLibGetMemoryBank function retrieves setup information and configuration settings
about a PISMO memory bank.
5. SpPciLibReadMemory
The SpPciLibSetMemoryBank function controls configuration settings such as signal timing or
bus cycle modes of a PISMO memory bank.
6. SpPciLibWriteMemory
The SpPciLibWriteMemory function drives a single write cycle to a PISMO memory bank.
7. SpPciLibGetSignal
The SpPciLibGetSignal function determines the current value or status of a hardware signal.
8. SpPciLibSetSignal
The SpPciLibSetSignal function controls a hardware signal.
The API libraries files SpPciLib.h and SpPciLib.lib are provided with the PCI 3.1 driver.
Before operating the Flash, please follow the flow shown in Figure 2.1 on page 3 to enumerate the device.
Example 1 shows how two configure the data bus into 16-bits mode. The memory bank's nWordsize should
be set to two. This means memory bank uses 16-bit data bus.
2
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
April 13, 2007
App l ic atio n
No t e
Figure 2.1 Operation Flow Chart
Start
SpPciLibEnum
SpPciLibOpenDevice
Failed
PASS
Set the memory bank
Flash read/write operation
Failed to open the device
Close device after
finishing operation
Example code:
/*1) Enumerate device*/
while (SpPciLibEnumDevice(nDevice, &xDeviceId, &xDeviceName))
{
/* Open the device for operation */
hDevice = SpPciLibOpenDevice(&xDeviceId);
if (hDevice)
{
xBank.nWordSize = 2;
SpPciLibSetMemoryBank(hDevice,SPPCILIB_BANK_CS0,&xBank);
/*/////////////
//start flash operation
////////////*/
SpPciLibCloseDevice(hDevice); //close device
}else
{
printf(" ERROR: Spansion PISMO(TM) PCI Card found.\n");
printf(" Please install card and run program again. \n");
}
}
April 13, 2007
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
3
A pplication
Note
/*2) ReadFlash function*/
typedef unsigned short FLASHDATA;
FLASHDATA FlashCmdRead(DWORD raddress)
{
FLASHDATA rdata;
raddress = raddress *2;
/* cuz setting xbank.wordsize = 2;16bit offset*//
*printf("%x\t",raddress);*/
SpPciLibReadMemory(hDevice,SPPCILIB_BANK_CS0,raddress,&rdata);
return rdata;
}
/*3) WriteFlash function*/
void FlashCmdWrite(DWORD waddress, FLASHDATA wdata)
{
waddress = waddress * 2;
SpPciLibWriteMemory(hDevice,SPPCILIB_BANK_CS0,waddress,wdata);
}
Note: These APIs require the Spansion PCI card for proper functionality. Users may instead implement their
own read/write function to establish basic communication.
3. Spansion Low Level Driver (LLD) Introduction
Spansion LLD includes the following files:
1. required files
lld.c, lld.h
lld_target_specific.h
--- Core LLD Functions
--- Customize LLD Configuration
2. Optional files
lld_bdsxxx_asp.c, ld_bdsxxx_asp.h
lld_wsxxx_asp.c, lld_wsxxx_asp.h
lld_cfi.c, lld_cfi.h
trace.c, trace.h
3.1
|
| --- Advanced Sector Protect
--- CFI Interpretation Code
--- Trace Buffer Code
Flash Functions Explanation
For all flash operation commands, please refer to the Memory Array Commands. Before coding the flash
functions, read the command list carefully.
The functions are now described in detail. All these functions can be found in file lld.c (GL512-N as the
example).
4
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
April 13, 2007
App l ic atio n
3.1.1
No t e
Device ID and Read Operation
Read Data Command
1
addr
data
RA
AD
Just use 1 cycle to read data from given address. Function used:
FLASHDATA FlashCmdRead(DWORD raddress)
Read Device ID Command
1
2
3
4
5
6
addr
data
addr
data
addr
data
addr
data
addr
data
addr
data
555
AA
2AA
55
555
90
X01
227E
X0E
2223
X0F
2201
– 1st cycle, write data 0xAA to address 0x555
– 2nd cycle, write data 0x55 to address 0x2AA
– 3rd cycle, write data 0x90 to address 0x555
– 4th cycle, read 1st device ID from address 0x01, (expected data=0x227E)
– 5th cycle, read 2nd device ID from address 0x0E, (expected data=0x2223)
– 6th cycle, read 3rd device ID from address 0x0F, (expected data=0x2201)
Example code:
unsigned int lld_GetDeviceId
(
FLASHDATA * base_addr
/* device base address in system */
)
{
unsigned int id;
FlashCmdWrite(0x555, 0xAA);
FlashCmdWrite(0x2AA,0x55);
FlashCmdWrite(0x555, 0x90);
id
= (unsigned int)(FlashCmdRead( 0x0001) & 0x000000FF) << 16;
id |= (unsigned int)(FlashCmdRead( 0x000E) & 0x000000FF) <<
id |= (unsigned int)(FlashCmdRead( 0x000F) & 0x000000FF)
8;
;
return(id);
}
Result: return Device ID is 0x7E2301 for GL512N device
April 13, 2007
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
5
A pplication
3.1.2
Note
Program
Program Data Command
1
2
3
4
addr
data
addr
data
addr
data
addr
data
555
AA
2AA
55
555
A0
PA
PD
– 1st cycle, write data 0xAA to address 0x555
– 2nd cycle, write data 0x55 to address 0x2AA
– 3rd cycle, write data 0xA0 to address 0x555
– 4th cycle, write program data PD to target address PA.
Example code:
void lld_ProgramCmd
(
ADDRESS offset,
/* address offset from base address */
FLASHDATA *pgm_data_ptr
/* variable containing data to program */
)
{
FlashCmdWrite(0X555, 0XAA);
FlashCmdWrite(0X2AA, 0X55);
/* Write Program Command */
FlashCmdWrite( 0X555, 0xA0);
/* Write Data */
FlashCmdWrite(offset, *pgm_data_ptr);
}
„ The program can only change a data bit from 1 to 0. Before programming make sure the previous location
to be programmed has been erased; or if updating previously programmed data, that the bits are only
going to be changed from '1' to '0'.
„ After programming, any other operation should wait until the program operations has finished. The toggle
bit can be used to check the programming status. Please refer to Toggle Bit Polling on page 8.
6
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
April 13, 2007
App l ic atio n
3.1.3
No t e
Chip Erase
Chip Erase Command
1
2
3
4
5
6
addr
data
addr
data
addr
data
addr
data
addr
data
addr
data
555
AA
2AA
55
555
80
555
AA
2AA
55
555
10
– 1st cycle, write data 0xAA to address 0x555
– 2nd cycle, write data 0x55 to address 0x2AA
– 3rd cycle, write data 0x80 to address 0x555
– 4th cycle, write data 0xAA to address 0x555
– 5th cycle, write data 0x55 to address 0x2AA
– 6th cycle, write data 0x10 to address 0x555
Example code:
void lld_ChipEraseCmd(void)
{
/* Issue Chip Erase Command Sequence */
FlashCmdWrite(0X555, 0xAA);
FlashCmdWrite(0X2AA, 0x55);
FlashCmdWrite(0X555, 0x80);
FlashCmdWrite(0X555, 0xAA);
FlashCmdWrite(0X2AA, 0x55);
/* Write Chip Erase Command to Base Address */
FlashCmdWrite(0X555, 0x10);
}
Note: Any other operation should wait until erase finishes. The toggle bit can be used to check the
programming status. Please refer to Toggle Bit Polling on page 8.
3.1.4
Sector Erase
Sector Erase Command
Similar to chip erase, only the last cycle differs.
1
2
3
4
5
6
addr
data
addr
data
addr
data
addr
data
addr
data
addr
data
555
AA
2AA
55
555
80
555
AA
2AA
55
SA
30
– 1st cycle, write data 0xAA to address 0x555
– 2nd cycle, write data 0x55 to address 0x2AA
– 3rd cycle, write data 0x80 to address 0x555
– 4th cycle, write data 0xAA to address 0x555
– 5th cycle, write data 0x55 to address 0x2AA
– 6th cycle, write data 0x30 to sector address
Example code:
void lld_SecEraseCmd(void)
April 13, 2007
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
7
A pplication
Note
{
/* Issue Sector Erase Command Sequence */
FlashCmdWrite(0X555, 0xAA);
FlashCmdWrite(0X2AA, 0x55);
FlashCmdWrite(0X555, 0x80);
FlashCmdWrite(0X555, 0xAA);
FlashCmdWrite(0X2AA, 0x55);
/* Write Chip Erase Command to Base Address */
FlashCmdWrite(0X555, 0x30);
}
Note: Any other operation should wait until erase finishes. The toggle bit can be used to check the
programming status. Please refer to Toggle Bit Polling on page 8.
3.1.5
Toggle Bit Polling
Generally, there are three methods to determine the flash operation status.
1. Status bit polling (more commonly used)
2. Data checking and
3. Hardware RY/BY# method.
Polling the Status bits involves reading the DQ data bits DQ2, 3, 5, 6 and 7 to check the statue of a program
or erase operation. This is the preferred method and is described in more detail in the following paragraphs.
Data checking is simply reading a location over-and-over again which reads back the value you programmed
into the device. While this seems simple, this method can have problems in systems that use interrupts, have
long data line traces or if the flash encounters an error when programming. The Hardware RY/BY# method
requires supporting hardware and does not provide error information.
DQ Status Bits
DQ6 indicates whether an Embedded Program or Erase algorithm is in progress or complete, or whether the
device has entered the Erase Suspend mode.
DQ5 indicates whether the program or erase time has exceeded a specified internal pulse count limit. Under
these conditions DQ5 produces a 1 indicating that the program or erase cycle was not successfully
completed.
DQ2, when used with DQ6, indicates whether a particular sector is actively erasing (that is, the Embedded
Erase algorithm is in progress), or whether that sector is erase-suspended. See Figure 3.1.
Figure 3.1 DQ2 vs. DQ6
Enter
Embedded
Erasing
WE#
Erase
Suspend
Erase
Enter Erase
Suspend Program
Erase Suspend
Read
Erase
Suspend
Program
Erase
Resume
Erase Suspend
Read
Erase
Erase
Complete
DQ6
DQ2
Note
DQ2 toggles only when read at an address within an erase-suspended sector. The system may use OE# or CE# to toggle DQ2 and DQ6.
DQ1 indicates whether a Write-to-Buffer operation was aborted. Under these conditions DQ1 produces a 1.
The system must issue the Write-to-Buffer-Abort-Reset command sequence to return the device to reading
array data.
8
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
April 13, 2007
App l ic atio n
No t e
Figure 3.2 Toggle Bit Status Flowchart
Read data twice
N
DQ6 toggle?
Read data twice
Y
DQ2 toggle?
Read data twice
N
Y
Y
Write buffer
programming?
N
Erase/program
Suspend
N
DQ1 high?
Read data twice
DQ5 high?
N
Y
Y
Time Out
Write buffer abort
Busy
Not Busy
Figure 3.3 Toggle Bit Polling Flow Chart
Get toggle bit status
N
Status is BUSY?
Status = ABORT do
abort handle
Status = suspend do
suspend handle
Y
N
Polling counts = 0?
Y
BUSY
April 13, 2007
Status=NOT BUSY, do
next operation
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
9
A pplication
Note
Example code:
Please refer to LLD v5.13.
extern DEVSTATUS lld_StatusGet
(
FLASHDATA * base_addr,
/* device base address in system */
ADDRESS
/* address offset from base address */
offset
);
extern DEVSTATUS lld_Poll
(
FLASHDATA * base_addr,
/* device base address in system */
ADDRESS offset,
/* address offset from base address */
FLASHDATA *exp_data_ptr,
/* expect data */
FLASHDATA *act_data_ptr,
/* actual data */
POLLING_TYPE polling_type
/* type of polling to perform */
);
3.1.6
Write Buffer
Write Buffer Programming allows the system write to a maximum of 16 words/32 bytes in one programming
operation. This results in faster effective programming time than the standard programming algorithms.
Write Buffer Command
1
2
3
4
5
...
addr
data
addr
data
addr
data
addr
data
addr
data
addr
data
555
AA
2AA
55
PA
25
SA
word
count
PA
PD
PA
PD
Program Buffer to Flash Command
Program buffer
1
addr
data
SA
29
Write to Buffer Abort Reset Command
Write to
buffer
abort reset
10
1
2
3
addr
data
addr
data
addr
data
555
AA
2AA
55
555
F0
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
April 13, 2007
App l ic atio n
No t e
Figure 3.4 Write Buffer and Program Flow Chart
Write data to buffer command
(Address 0x555
<= 0xAA
Address 0x2AA <= 0x55
Program address
<= 0x25
Program address
<= word count)
Program address++
<=Program data
YES
Writing count< buffer
size (16 words)
NO
Program Buffer To Flash command
Status polling- before do any other
operation
Example code:
DEVSTATUS lld_WriteBufferProgramOp
(
FLASHDATA *
ADDRESS
base_addr,
offset,
/* device base address is system
/* address offset from base address
WORDCOUNT word_count, /* number of words to program
FLASHDATA *data_buf
*/
*/
*/
/* buffer containing data to program */
)
{
DEVSTATUS status;
FLASHDATA write_data = 0;
FLASHDATA read_data = 0;
ADDRESS
last_loaded_addr;
ADDRESS
current_offset;
ADDRESS
end_offset;
FLASHDATA wcount;
/* Initialize variables */
current_offset
= offset;
end_offset
= offset + word_count - 1;
last_loaded_addr = offset;
/* don't try with a count of zero */
if (!word_count) return(DEV_NOT_BUSY);
/* Issue Load Write Buffer Command Sequence */
lld_WriteToBufferCmd(base_addr, offset);
/* Write # of locations to program */
wcount = (FLASHDATA)word_count - 1;
April 13, 2007
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
11
A pplication
Note
wcount *= LLD_DEV_MULTIPLIER; /* only needed for interleaves of multiple devices to
make a wider data bus /*
FLASH_WR(base_addr, offset, wcount);
/* Load Data into Buffer */
while(current_offset <= end_offset)
{
/* Store last loaded address & data value (for polling) */
last_loaded_addr = current_offset;
write_data = *data_buf;
/* Write Data */
FLASH_WR(base_addr, current_offset++, *data_buf++);
}
/* Issue Program Buffer to Flash command */
lld_ProgramBufferToFlashCmd(base_addr, last_loaded_addr);
status = lld_Poll(base_addr, last_loaded_addr, &write_data,
&read_data, LLD_P_POLL_WRT_BUF_PGM);
return(status);
}
3.1.7
Unlock Bypass Mode
The unlock bypass feature allows the system to program words to the device faster than using the standard
program command sequence. The unlock bypass command sequence is initiated by first writing two unlock
cycles. Only two cycles are used for programming process, thus reducing the programming time.
Unlock
bypass
entry
Unlock
bypass
Program
Unlock
bypass
reset
12
1
2
3
addr
data
addr
data
addr
data
555
AA
2AA
55
555
20
1
2
addr
data
addr
data
XXX
A0
PA
PD
1
2
addr
data
addr
data
XXX
90
XXX
0
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
April 13, 2007
App l ic atio n
No t e
Figure 3.5 Unlock Bypass Programming Flow Chart
Unlock bypass entry (3 cycles)
Unlock bypass program (2 cycles)
YES
Continue programming?
NO
Unlock bypass reset
4. Notice to Reader
For MirrorBit™ Flash users, please find a summary of our advice from the software point of view below:
1. Please make sure the Device ID and manufactorer ID are different than the floating gate one.
2. MirrorBit flash devices require 4 µs from the time a programming command is issued before the
data polling bits can be read. Without the delay, it is likely that you will read invalid status from the
flash. The invalid status may lead the software to believe that programming finished early without
problems or that programming failed. If your system inherently has more than a 4 µs delay, you
don't need any additional delay.
3. There are two methods to speed up the programming process. One is with the unlock bypass
mode, the other is by write buffer then program to flash. Spansion recommends you use the write
buffer command to write data to flash. The advantages of the write buffer are:
a. faster programming compared to using unlock bypass
b. Fewer system resources needed to poll the programming of a stream of data.
April 13, 2007
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
13
A pplication
5.
Note
Revision History
Section
Description
Revision 01 (April 13, 2007)
Initial release
14
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
April 13, 2007
App l ic atio n
No t e
Colophon
The products described in this document are designed, developed and manufactured as contemplated for general use, including without
limitation, ordinary industrial use, general office use, personal use, and household use, but are not designed, developed and manufactured as
contemplated (1) for any use that includes fatal risks or dangers that, unless extremely high safety is secured, could have a serious effect to the
public, and could lead directly to death, personal injury, severe physical damage or other loss (i.e., nuclear reaction control in nuclear facility,
aircraft flight control, air traffic control, mass transport control, medical life support system, missile launch control in weapon system), or (2) for
any use where chance of failure is intolerable (i.e., submersible repeater and artificial satellite). Please note that Spansion will not be liable to
you and/or any third party for any claims or damages arising in connection with above-mentioned uses of the products. Any semiconductor
devices have an inherent chance of failure. You must protect against injury, damage or loss from such failures by incorporating safety design
measures into your facility and equipment such as redundancy, fire protection, and prevention of over-current levels and other abnormal
operating conditions. If any products described in this document represent goods or technologies subject to certain restrictions on export under
the Foreign Exchange and Foreign Trade Law of Japan, the US Export Administration Regulations or the applicable laws of any other country,
the prior authorization by the respective government entity will be required for export of those products.
Trademarks and Notice
The contents of this document are subject to change without notice. This document may contain information on a Spansion product under
development by Spansion. Spansion reserves the right to change or discontinue work on any product without notice. The information in this
document is provided as is without warranty or guarantee of any kind as to its accuracy, completeness, operability, fitness for particular purpose,
merchantability, non-infringement of third-party rights, or any other warranty, express, implied, or statutory. Spansion assumes no liability for any
damages of any kind arising out of the use of the information in this document.
Copyright © 2007 Spansion Inc. All rights reserved. Spansion®, the Spansion Logo, MirrorBit®, MirrorBit® Eclipse™, ORNAND™, HD-SIM™ and
combinations thereof, are trademarks of Spansion LLC in the US and other countries. Other names used are for informational purposes only
and may be trademarks of their respective owners.
April 13, 2007
How to Use Spansion™ LLD v5.13 to Implement a Flash Driver
15