Nor-flash driver Documentation (SST39VF1601)

Source: Internet
Author: User
Tags documentation

sst39vf160 Chinese datasheet.pdf sst39vf1601.pdf sst39vf160x Driver.txt

Nor-flash is the first flash Memory to emerge, and is still the technology architecture supported by most vendors. Nor-flash is widely used in applications where erasure and programming operations are less straightforward, especially for pure code storage, but because Nor-flash only supports block Erasure, its erasure and programming speed is slow, and block size is large, resulting in a long time to erase and program operations, So in the application of pure data storage and file storage, it seems to be inadequate.


Nor-flash is characterized by:

1. The program and data can be stored on the same chip, the Flash chip has a separate data bus and address bus, can be quickly random read, and allows the system directly from Flash to read code execution, without first downloading the code into RAM and then execute;

2. Can be single-byte or word read, but not a single-byte erase, must be in part or block or the whole piece to perform the erase operation, before performing a write operation, you must first wipe the part, block or whole piece, before writing the data.


Take the SST series Nor-flash chip as an example to introduce the use method and drive of Flash.

First, in the driver's header file, according to the specific situation of the chip and the requirements of the project are defined as follows:

1. Define the units of the operation, such as

typedef unsigned char BYTE; BYTE is 8-bit in length

typedef unsigned short int WORD; WORD is 16-bit in length

typedef unsigned long int Uint32; Uint32 is 32-bit in length

Here the address is more than 32 bits, the minimum data unit for the chip write operation is word, which is defined as 16 bits, and the minimum data unit of the chip read operation is byte, which is defined as 8 bits.

2. Because the chip is divided into 16-bit and 32-bit, the command operation on the chip is also divided into 16-bit operation and 32-bit operation (the command operation will be described in detail during the introduction of the specific reading and writing process).

#ifdef GE01

/* Macro Norflash_32bit, if defined as 32-bit norflash, otherwise 16-bit norflash*/

#define Norflash_32bit

#endif

3. Depending on the chip, define the part (segment) and the size of the block.

#define SECTOR_SIZE 2048//Must be 2048 words for 39vf160x

#define BLOCK_SIZE 32768//Must be 32K words for 39vf160x

/* Where words is based on the above definition, refers to 16-bit data */

The remaining parameters can be used without modification.

Here's a look at the specific operation.

1. Read operation

The Nor-flash can read data at random, fast, and can read at any address in Flash and the smallest unit of read data is controlled at 8 bits.

The following is the read operation in the driver, the function of which is to read a length of data from the offset address in flash to the DST address at the source address Srcword address (the unit of length is bytes):

void Norflash_read (U8 *srcword, Uint32 Dst, int length)

{

Uint32 destbuf = Dst;

U8 *sourcebuf = Srcword;

int Index;

for (Index = 0; Index < length; index++)

{

Readoneword (Sourcebuf, destbuf); A function that reads a single byte

sourcebuf++;

destbuf++;

}

}

void Readoneword (U8 *srcword, Uint32 Dst)

{

Uint32 destbuf = Dst;

U8 *sourcebuf = (U8 *) Srcword;

*SOURCEBUF = * (volatile u8*) (system_base|  DESTBUF); System_base is the base address of Flash,

Can be defined in the driver, in addition

Read operations do not need to send commands, directly

Reading can

}

Usage: If you need to read a 10-byte data from the address of Flash to the address of the SDRAM 0x30001000, the code should be written as: Norflash_read ((U8 *) 0x30001000, 0x1000, 10); The base of Flash is 0x20000000, so the offset address can only be written 0x1000.


2. Erase action

Erase operation is divided into 3 kinds, one is partial erase, namely erase a sector size space, two is block erase, three is the whole piece erase.

Part of the Erase function, in addition to the read operation, the rest of the flash operation must send the corresponding command to flash. and specific to send what kind of command, by the Flash chip model decision, TIME please consult sst39vf1601 chip instruction manual

int Eraseonesector (Uint32 Dst)

{

Uint32 destbuf = Dst;

int ReturnStatus;

39VF160X series Flash command, control the following table to write commands

*sysaddress (0x5555) = 0X00AA; Write data 0x00aa to device addr 0x5555

*sysaddress (0X2AAA) = 0x0055; Write data 0x0055 to device addr 0x2aaa

*sysaddress (0x5555) = 0x0080; Write data 0x0080 to device addr 0x5555

*sysaddress (0x5555) = 0X00AA; Write data 0x00aa to device addr 0x5555

*sysaddress (0X2AAA) = 0x0055; Write data 0x0055 to device addr 0x2aaa

*sysaddress (DESTBUF) = 0x0030; Write data 0x0030 to device sector addr

ReturnStatus = Checktoggleready (DESTBUF); Check that the offset in Flash is a write-or-erase operation at the DSTBUF address. Return 1: The destination address is not in the write and erase operation; 0: A write or erase operation at the destination address

return returnstatus;

}

The corresponding Chinese

The drive code to erase a block and erase the entire piece is similar to the above, but the commands are different and can be modified according to the commands in the table block-erase and Chip-erase. The application of the erase operation can be seen in the write operation.


3. Write operations

Write operations are slow and do not use frequently

int Norflash_write (WORD *src, U32 Dst, int length)//will write a length of data at the source address SRC address to flash in the offset address at the Dst address, length in bytes

{

WORD *sourcebuf;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.