NAND Flash driver design

Publisher:龙腾少年Latest update time:2013-03-18 Source: dzscKeywords:NAND  Flash  K9F2808UOB  S3C2410 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  introduction

  In the current development and design of various embedded systems, storage module design is an indispensable and important aspect. NOR and NAND are the two main non-volatile flash memory technologies on the market. NOR Flash memory has a small capacity and a slow write speed, but because of its fast random read speed, it is often used to store program codes in embedded systems. Compared with NOR, the advantage of NAND flash memory is its large capacity, but its speed is slower, because it has only 8 or 16 I/O ports, and these signals must be transmitted in turn to complete the transmission of addresses and data. NAND Flash has an extremely high cell density, can have a relatively large capacity, and is relatively cheap.

  This article takes Samsung's K9F2808UOB chip as an example to introduce the design method of NAND Flash interface circuit and driver. This article introduces the basic principles of developing NAND Flash driver, aiming to simplify the embedded system development process.

  1 NAND Flash Working Principle

  The NAND Flash support of the S3C2410 board consists of two parts: the NAND Flash controller integrated on the S3C2410 CPU

  And NAND Flash storage chip. To access the data in NAND Flash, you must send commands through the NAND Flash controller. Therefore, NAND Flash is equivalent to a peripheral of S3C2410 and is not located in its memory address area.

  1.1 Chip internal storage layout and storage operation characteristics

  A NAND Flash is a device, and its data storage is hierarchical: 1 device = 4 096 blocks; 1 block = 32 pages; 1 page = 528 bytes = data block size (512 bytes) + OOB block size (16 bytes). In each page, the last 16 bytes (also known as OOB, Out?of?Band) are used to set the status after the NAND Flash command is executed, and the remaining 512 bytes are divided into the first half and the second half. The first half, the second half, and the OOB can be located respectively through the NAND Flash command 00h/01h/50h, and the pointer built into the NAND Flash points to their respective first addresses.

  The characteristics of storage operation are as follows: The minimum unit of erase operation is block; each bit of NAND Flash chip can only change from 1 to 0, but not from 0 to 1, so the corresponding block must be erased before writing to it (erasing means changing all bits of the corresponding block to 1); the 6th byte (ie 517 bytes) of the OOB part marks whether it is a bad block. If the value is FF, it is not a bad block, otherwise it is a bad block. In addition to the 6th byte of OOB, usually at least the first 3 bytes of OOB are used to store the NAND Flash hardware ECC code.

  1.2 NAND Flash Interface Circuit

  First, the hardware design of the development board is introduced. Figure 1 shows the NAND Flash interface circuit. When switches 1 and 2 are connected, R/B indicates ready/busy. When switches 2 and 3 are connected, nWAIT can be used to add additional waiting cycles for read/write access. The NAND Flash controller has been integrated in the S3C2410 processor. Figure 2 shows how the microcontroller connects to the NAND Flash.

  1.3 Controller Working Principle

  The NAND Flash controller maps its own special function registers in its dedicated register area (SFR) address space, which is to write the built-in commands of the NAND Flash chip into its special function registers to realize the reading, verification and programming control of the NAND Flash chip. The special function registers are: NFCONF, NFCMD, NFADDR, NFDATA, NFSTAT, NFECC.

  2 Flash programming program principle and structure

  Basic principle: Write the data in a storage area in SDRAM to the NAND Flash storage space. The burning program is completed in three layers vertically. The first layer: the main burning function, writes the data in a storage area in SDRAM to the NAND Flash storage space. The second layer: This layer provides page read, write and block erase functions for NAND Flash operations. The third layer: provides the core functions for the second layer to operate the special function registers in the specific NAND Flash controller. This layer is also the function that actually transfers data between SDRAM and NAND Flash. The second layer is the key to the design of the driver. The following is a detailed introduction to the read, write (also known as programming) and erase function coding of this layer. [page]

  2.1 NAND Flash Read

  Function: The data read operation is in pages. When reading data, first write the read data command 00H, then enter the address of the page to be read, then read the data from the data register, and finally perform ECC check.

  Parameter description: block, block number; page, page number; buffer, points to the starting position to be read into the memory; return value 1: read successful, return value 0: read failed.

  static int NF_ReadPage(unsigned int block, unsigned int page, unsigned char *buffer){

  NF_RSTECC(); /* Initialize ECC */

  NF_nFCE_L(); /* Chip select NAND Flash chip*/

  NF_CMD(0x00); /* Start reading from area A*//* A0~A7 (column address) */

  NF_ADDR(0); /* A9A16(page address) */

  NF_ADDR(blockPage&0xff); /* A17A24,(page address) */

  NF_ADDR((blockPage>>8)&0xff);/* A25, (page address) */

  NF_ADDR((blockPage>>16)&0xff);/* Wait for NAND Flash to be ready again*/

  ReadPage();/* Read the entire page, 512 bytes*/

  ReadECC();/* Read ECC code*/

  ReadOOB();/* Read the OOB block of this page*//* Uncheck NAND Flash*/

  NF_nFCE_H();/* Check ECC code and return*/

  Return (checkEcc())}

  2.2 NAND Flash Program

  Function: Program the page, used for write operation.

  Command code: First write 00h (A zone)/01h (B zone)/05h (C zone), indicating which zone to write to; then write 80h to start programming mode (write mode), then write address and data; finally write 10h to end programming. Figure 3 is the program flow chart.

  Parameter description: block, block number; page, page number; buffer, points to the starting position of the data to be written to the NAND Flash in the memory; return value 0, write error, return value 1, write success.

  static int NF_WritePage(unsigned int block, unsigned int page, unsigned char *buffer){

  NF_RSTECC(); /* Initialize ECC */

  NF_nFCE_L(); /* Chip select NAND Flash chip*/

  NF_CMD(0x0); /* Start writing from area A*/

  NF_CMD(0x80); /* Write the first command *//* A0~A7 (column address) */

  NF_ADDR(0);/* A9A16(page address) */

  NF_ADDR(blockPage&0xff);/* A17A24(page address) */

  NF_ADDR((blockPage>>8)&0xff); /* A25(page address) */

  NF_ADDR((blockPage>>16)&0xff);/* Write page 512B to NAND Flash chip*/

  WRDATA(); /*OOB has 16 bytes in total. What is stored in each byte is defined by the programmer. ECC check code is stored in Byte0 and Byte2, and bad block flag is stored in Byte6*/

  WRDATA(); /* Write the OOB data block of this page*/

  CMD(0x10); /* End write command*/

  WAITRB();/* Wait for NAND Flash to be in the ready state*//* Send a read status command to NAND Flash*/

  CMD(0x70);

  if (RDDATA()&0x1) { /*If there is a write error, mark it as a bad block and cancel NAND Flash selection*/

  MarkBadBlock(block);

  return 0;

  } else { /* Exit normally, cancel NAND Flash selection*/

  return 1;}[page]

  2.3 NAND Flash Erase

  Function: Block erase command.

  Command code: First write 60h to enter the erase mode, then enter the block address, and then write D0h to indicate the end of the erase.

  Parameter description: block, block number; return value 0, erasure error (if it is a bad block, it will return 0 directly; if an error occurs during erasure, it will be marked as a bad block and then return 0); return value 1, successful erasure.

  static int NF_EraseBlock(unsigned int block){/* If the block is a bad block, return*/

  if(NF_IsBadBlock(block)) return 0;

  NF_nFCE_L(); /* Chip select NAND Flash chip*/

  NF_CMD(0x60); /* Set the erase mode*//* A9A16(Page Address), is based on block erase*/

  NF_ADDR(blockPage&0xff);

  NF_ADDR((blockPage>>8)&0xff); /* A25(Page Address) */

  NF_ADDR((blockPage>>16)&0xff); NF_CMD(0xd0); WAITRB();CMD(0x70);

  if(RDDATA()&0x1){/*If there is an error, mark it as a bad block and cancel the Flash selection*/

  MarkBadBlock(block);

  return 0;

  } else { /* Exit, cancel Flash selection*/

  return 1;}

  3 ECC Check Principle and Implementation

  Since the NAND Flash process cannot guarantee that the NAND Memory Array maintains reliable performance during its life cycle, bad blocks will be generated during the production and use of NAND. In order to detect the reliability of data, a certain bad block management strategy is generally adopted in the system using NAND Flash, and the premise of managing bad blocks is to be able to detect bad blocks relatively reliably. If there are no problems with the operation timing and circuit stability, when NAND Flash fails, it will generally not cause the entire block or page to be unable to read or all errors, but only one or several bits in the entire page (for example, 512 bytes) will be wrong. Commonly used data checks include parity check and CRC check, and in NAND Flash processing, a special check is generally used - ECC. ECC can correct single-bit errors and detect double-bit errors, and the calculation speed is very fast, but it cannot correct errors of more than 1 bit, and it is not guaranteed to detect errors of more than 2 bits. ECC generally generates 3 bytes of ECC check data for every 256 bytes of original data. These 3 bytes, a total of 24 bits, are divided into two parts: 6 bits of column check and 16 bits of row check, and the redundant 2 bits are set to 1, as listed in Table 1.

  First, we will introduce the ECC column checksum. The ECC column checksum generation rule is shown in Figure 4. "^" represents the "bitwise XOR" operation. Due to space constraints, the row checksum is not introduced. Interested readers can refer to the chip datasheet, which can be downloaded for free on the Samsung website.

  The mathematical expression is:

  When writing data to a NAND Flash page, an ECC checksum is generated for every 256 bytes, called the original ECC checksum, and saved in the OOB data area of ​​the page. When reading data from NAND Flash, an ECC checksum is generated for every 256 bytes, called the new ECC checksum. When checking, it is not difficult to infer based on the above ECC generation principle: the original ECC checksum read from the OOB area is XORed with the new ECC checksum bit by bit. If the result is 0, it means there is no error (or an error that cannot be detected by ECC); if 11 bits in the 3-byte XOR result are 1, it means there is a bit error and it can be corrected; if only 1 bit in the 3-byte XOR result is 1, it means an error in the OOB area; other cases indicate an error that cannot be corrected.

  4 Functional verification under UBOOT

  The main way to implement UBOOT's support for NAND Flash is to implement NAND Flash operations under the command line. The commands implemented for NAND Flash are: nand info, nand device, nand read, nand write, nand erase, nand bad. The main data structures used are: struct nand_flash_dev and struct nand_chip. The former includes information such as the main chip model, storage capacity, device ID, I/O bus width, etc., and the latter is the information used for specific operations on NAND Flash. Since the method of porting the driver to UBoot is not the focus of this article, it will not be introduced in detail.

  Verification method: Download data to SDRAM via TFTP, and use the nand read, nand write, and nand erase commands to read, program, and erase the NAND Flash. The test results are listed in Table 2. Compared with the data in the datasheet, it can be concluded that the driver runs well in the system.

  Conclusion

  Nowadays, embedded systems are increasingly widely used, and storage devices are an indispensable part of embedded systems. NAND Flash has obvious advantages over other storage devices when the capacity does not exceed 4 GB. The driver designed in this paper is not based on any operating system and can be easily ported to multiple operating systems and Boot Loaders, which has certain practical significance for simplifying the development of embedded systems.

Keywords:NAND  Flash  K9F2808UOB  S3C2410 Reference address:NAND Flash driver design

Previous article:Implementing the debugging of embedded software in VIM
Next article:Using Allegro to route the BGA package of s3c2410

Recommended ReadingLatest update time:2024-11-17 00:34

Design of Embedded Audio System Based on S3C2410 and UDAl341
  1 Introduction   In recent years, embedded digital audio products have been favored by more and more consumers. In consumer electronic products such as MP3 and mobile phones, people's requirements for these personal terminals are no longer limited to simple calls and simple text processing. High-quality sound effect
[Microcontroller]
Design of Embedded Audio System Based on S3C2410 and UDAl341
The difference between FLASH and EEPROM
The biggest difference between FLASH and EEPROM is that FLASH operates by sector, while EEPROM operates by byte. The two have different addressing methods and different storage unit structures. FLASH has a simpler circuit structure, and the same capacity occupies a smaller chip area, so the cost is naturally lower tha
[Microcontroller]
SK Hynix develops 238-layer NAND flash memory chip for mass production in the first half of next year
Beijing time, August 3, SK Hynix of South Korea has developed a 238-layer NAND flash memory chip, which can be used in PC storage devices, smartphones and servers. Last week, Micron also began shipping 232-layer NAND flash memory chips.    SK Hynix claims that the new 238-layer chip is the smallest NAND flash memory c
[Semiconductor design/manufacturing]
Transplantation of cs8900 network card driver based on s3c2410 2.6.25 kernel
Because the driver uses virtual addresses, the physical address of the network card must first be mapped to the virtual address *************************************************** ************ 1. Add in include/asm-arm/plat-s3c24xx/common-smdk.h file The macro __phys_to_pfn must be used to shift the physical address r
[Microcontroller]
TrendForce: NAND Flash prices may drop by 10%-15% in the first quarter of 2021
The latest report from the Semiconductor Research Department of market research firm TrendForce stated that since the number of NAND Flash suppliers is much higher than that of DRAM, and the growth rate of supply bits remains high, NAND Flash prices are expected to continue to fall quarter by quarter in 2021. Image
[Mobile phone portable]
TrendForce: NAND Flash prices may drop by 10%-15% in the first quarter of 2021
Methods to Improve the Flash Erasing Life of MSP430G MCU
In embedded design, many application designs need to use EEPROM to store non-volatile data. Due to cost reasons, some microcontrollers do not have EEPROM integrated inside the chip. The MSP430G series processors are low-cost 16-bit processors launched by TI. There is no EEPROM in the MSP430G series microcontrollers. I
[Microcontroller]
Methods to Improve the Flash Erasing Life of MSP430G MCU
Intel Accelerates Data-Centric Technologies with Memory and Storage Innovations
At the Global Influencers Conference, Intel formally introduced a series of new technology milestones and emphasized its continued investment and firm commitment to driving advances in memory and storage technology in the data-centric computing era, including providing customers with unique Intel® Optane™ technology a
[Embedded]
Intel Accelerates Data-Centric Technologies with Memory and Storage Innovations
GigaDevice Launches 1.2mm×1.2mm USON6 GD25WDxxK6 SPI NOR Flash Product Series
GigaDevice launches 1.2mm×1.2mm USON6 GD25WDxxK6 SPI NOR Flash product series, and continues to lead the market with “ultra-small size, ultra-thin, and wide voltage” Beijing, China (July 20, 2022) — GigaDevice, an industry-leading semiconductor device supplier, announced the launch of the GD25WDxx
[Embedded]
GigaDevice Launches 1.2mm×1.2mm USON6 GD25WDxxK6 SPI NOR Flash Product Series
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号