HOME


DSP         Embedded Systems         GNU Tutorials         SW Development        


Introduction

Parallel Processing

Processor Architecture

Memory

Peripherals

Booting

System Design

System Development

System Debugging

Memory Devices

Real World Examples

Previous Page                                 Index                                 Next Page


MORE ON MEMORY DEVICES


Writing NOR Flash Driver

In this section I have discussed about the NOR Flash Commands and the operations supported by a “Generic NOR Flash Driver”. I have also provide a “Flash Driver example code in C” for “AT29LV040A Flash Memory”. This code can be used for any other Flash Memory, with minimum changes.

Intended Audience: I have assumed that readers of this tutorial are familiar with the basic operation of a Static RAM. Familiarity with “C Programming Language” is also assumed. This tutorial and the accompanying example code could be of use to the beginners, who are just learning to interact with the NOR flash devices.

Flash Device Selection
Flash Manufacturer offer a wide range of Flash Devices with differing characteristics:
* Memory Size: Refers to the total Storage capacity (generally measured in terms of Mbits) of the memory device.
* Data Bus-width: This should be compatible with the data bus-width of processor, with which you are going to interface the Memory Device. Common bus widths are 8-bit and 16-bit.
* Programming speed: Time required to write a block of data in to Flash Memory
* Sector Size: Sector is the minimum unit of memory, which needs to be updated for any write operation. Flash memory is arranged as sectors of of fixed size (of the order of 100s of Bytes). Any write or erase operation on the memory device is performed on sector basis. If a write has to be performed on any single (or multiple) byte of a sector, then the contents of entire sector will have to be re-written.

The final selection of the device for your system will depend on the system requirements (e.g how much memory is needed, what sector size is best, what programming time is acceptable) and device compatibility (e.g. bus-width) with the other devices in system.

Flash Hardware Interface
A Flash Interface consists of signals quite similar to the Static SRAM
Dx..D0: Form the data-bus. These pins are connected to the Data Bus of the processor.
Ay..A0: Form the address-bus. These pins are connected to the Address Bus of the Processor.
!OE: Is the “active-low” “Output-enable” signal. This signal must be asserted (Along with !CE) during the read operations. This signal is connected to the “!Read” signal of the processor.
!WE: Is the “active-low” “Write-Enable” signal. This signal is should be asserted during any command operation (more on this later). This signal is connected to the “!Write” signal of the processor.
!CE: Is the “active-low” “Chip-enable” signal. This signal must be asserted while performing any operating on the memory device. This signal is connected to the “!Chip Select” signal of the processor.

Flash Commands
Flash Memory consists of memory cells which can be read in a way similar to a Static RAM. However modifying the state of these cells requires special programming voltages. The Flash devices have an in-built circuitry which can generate these special programming voltages. This circuitry has a state machine, which can receive inputs via external interface (external pins of the Memory Device). In order to modify the contents of the Flash, user needs to send some specific commands (via Address Bus, Data Bus, !OE, !WE and !CE signals) to the state machine of Flash Device.

Waiting for the Command Completion
After a command has been issued to the Flash Device, the internal state machine takes some time to execute this command (command completion time). This time is fixed for a given device (and is generally of the order of few m-seconds). After issuing any command, the flash programming software must wait for command completion (before starting any other operation). There are various ways to implement this wait logic in the flash driver software:
* Wait for a fixed number of processor cycles: Time taken by a processor to issue an instruction is fixed (for fixed processor clock). Generally most processors supports an “NOP” (no operation) instruction. This instruction does nothing, but wait for a processor cycle. Thus inserting a few “NOP” instructions the driver code will tantamount to a wait loop. For example if the processor core is running at a clock speed of 100 MHz (10ns cycle time) and the command completion time is “20 ms”, then inserting 2000, NOP instructions should help. Generally such NOP instructions can be inserted by implementing an empty FOR Loop (while writing code in C or any similar programming language). The problem with this approach is that flash driver needs to be aware of the processor “clock cycle time” and Flash “command completion time”.
* Data Polling: Flash devices support a special feature, where reading a word from the memory (during the command execution phase of flash) will return “invert” of the “last written value” on a specific bit. The wait loop, can keep polling this particular data bit to ensure the completion of flash command.
* Toggle Bit: Flash devices support another feature, where the value of a particular bit will toggle for each consecutive read operation, during the command execution phase. This is the most easy way for implementing the “command completion wait loop” as the driver software need not be aware of the last written value to the flash.

More on Sector-Size:
Flash Technology requires content of entire sector to be changed, even if a single byte in given sector needs to be modified. Too big a sector size can thus result in programming efficiency. However reducing the sector-size adds to the memory cost. Hence a trade-off is needed between efficiency and cost. Sector sizes of a few KBytes (128 Byte and 256 Bytes are most common sizes) , are suitable for most applications.

Typical Flash Commands
Sector Unlock: To provide extra-protection to the Flash Memory against falsely triggered writes (unitentional operations like electrical transients and unintentional instructions), Flash memory devices offer a Sector Lock. Before performing any operation on the sector (erase or write), the sector must be unlocked.
Sector Erase: A sector needs to be erased before writing in to the Flash. Generally flash memory cells can be thought of as an array of electronic switches. The value stored (0 or 1) in a memory cell, depends on the ability of this switch to conduct (or not conduct). When a memory has been erased, all the switches will be in no-conduction state (reads “1″). Any memory cell can be then programmed (by the internal state machine) to conduct (this is done by using special programming voltages). Hence, writing to any flash sector, must be preceeded by a sector erase operation.
Sector Program: To write specific data to the memory cells.
Device Identification: (Most) Memory devices have a unique Manufacturer-ID and a unique Product-ID associate with them. A system can thus support multiple Flash Devices. Ater power-on, system software (this can be a part of POST) can read these IDs to identify the flash chip and then use a programming software (out of various available softwares) for corresponding device.

Writing in to Flash: In order to modify the contents of a Flash Devices, one needs to issue a series of commands operations on the device.
* Sector-Unlock
* Sector-Erase
* Sector-Program
* Wait for programming cycle completion

FLASH_WRITE_EXAMPLE

Fig. Flash Program Command for a 128-KByte memory with Sector Size of 128 Bytes



Previous Page                                 Index                                 Next Page








HOME

Copyright : Kunal Singh

Content of this site shall not be reused without my written permission

This page is XHTML Certified