TQ2440 Study Notes—— 20. NAND Flash Controller

Publisher:莫愁前路Latest update time:2022-04-19 Source: eefocusKeywords:TQ2440  NAND  Flash  Controller Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. NAND Flash Controller


1. Address space


The address bus of SRAM, DM9000 is connected to the address bus of S3C2440; while NAND Flash has no address bus, its addressing method is different from the former.


Therefore, the address must be clearly distinguished.


2. NAND addressing


3. NAND commands


4. Use S3C2440's NAND Flash controller to access NAND Flash


From the hardware:


1. Issue the command CLE DATA BUS


2、Addr ALE DATA BUS


3. Transmitting data


S3C2440:


1. Command register NFCMMD

2. Address register NFADDR

3. Data register NFDATA


4. Status register NFSTAT


2. Source Code Analysis


#define LARGER_NAND_PAGE

 

#define GSTATUS1        (*(volatile unsigned int *)0x560000B0)

#define BUSY            1

 

#define NAND_SECTOR_SIZE    512

#define NAND_BLOCK_MASK     (NAND_SECTOR_SIZE - 1)

 

#define NAND_SECTOR_SIZE_LP    2048

#define NAND_BLOCK_MASK_LP     (NAND_SECTOR_SIZE_LP - 1)

 

typedef unsigned int S3C24X0_REG32;

 

 

/* NAND FLASH (see S3C2410 manual chapter 6) */

typedef struct {

    S3C24X0_REG32   NFCONF;

    S3C24X0_REG32   NFCMD;

    S3C24X0_REG32   NFADDR;

    S3C24X0_REG32   NFDATA;

    S3C24X0_REG32   NFSTAT;

    S3C24X0_REG32   NFECC;

} S3C2410_NAND;

 

/* NAND FLASH (see S3C2440 manual chapter 6, www.100ask.net) */

typedef struct {

    S3C24X0_REG32   NFCONF;

    S3C24X0_REG32   NFCONT;

    S3C24X0_REG32   NFCMD;

    S3C24X0_REG32   NFADDR;

    S3C24X0_REG32   NFDATA;

    S3C24X0_REG32   NFMECCD0;

    S3C24X0_REG32   NFMECCD1;

    S3C24X0_REG32   NFSECCD;

    S3C24X0_REG32   NFSTAT;

    S3C24X0_REG32   NFESTAT0;

    S3C24X0_REG32   NFESTAT1;

    S3C24X0_REG32   NFMECC0;

    S3C24X0_REG32   NFMECC1;

    S3C24X0_REG32   NFSECC;

    S3C24X0_REG32   NFSBLK;

    S3C24X0_REG32   NFEBLK;

} S3C2440_NAND;

 

 

typedef struct {

    void (*nand_reset)(void);

    void (*wait_idle)(void);

    void (*nand_select_chip)(void);

    void (*nand_deselect_chip)(void);

    void (*write_cmd)(int cmd);

    void (*write_addr)(unsigned int addr);

    unsigned char (*read_data)(void);

}t_nand_chip;

 

static S3C2410_NAND * s3c2410nand = (S3C2410_NAND *)0x4e000000;

static S3C2440_NAND * s3c2440nand = (S3C2440_NAND *)0x4e000000;

 

static t_nand_chip nand_chip;

 

/* Function for external calls*/

void nand_init(void);

void nand_read(unsigned char *buf, unsigned long start_addr, int size);

 

/* The total entry for NAND Flash operations, which will call the corresponding functions of S3C2410 or S3C2440*/

static void nand_reset(void);

static void wait_idle(void);

static void nand_select_chip(void);

static void nand_deselect_chip(void);

static void write_cmd(int cmd);

static void write_addr(unsigned int addr);

static unsigned char read_data(void);

 

/* S3C2410 NAND Flash processing function*/

static void s3c2410_nand_reset(void);

static void s3c2410_wait_idle(void);

static void s3c2410_nand_select_chip(void);

static void s3c2410_nand_deselect_chip(void);

static void s3c2410_write_cmd(int cmd);

static void s3c2410_write_addr(unsigned int addr);

static unsigned char s3c2410_read_data();

 

/* S3C2440 NAND Flash processing function*/

static void s3c2440_nand_reset(void);

static void s3c2440_wait_idle(void);

static void s3c2440_nand_select_chip(void);

static void s3c2440_nand_deselect_chip(void);

static void s3c2440_write_cmd(int cmd);

static void s3c2440_write_addr(unsigned int addr);

static unsigned char s3c2440_read_data(void);

 

/* S3C2410 NAND Flash operation function*/

 

/* Reset */

static void s3c2410_nand_reset(void)

{

    s3c2410_nand_select_chip();

    s3c2410_write_cmd(0xff); // reset command

    s3c2410_wait_idle();

    s3c2410_nand_deselect_chip();

}

 

/* Wait for NAND Flash to be ready */

static void s3c2410_wait_idle(void)

{

    int i;

    volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFSTAT;

    while(!(*p & BUSY))

        for(i=0; i<10; i++);

}

 

/* Send chip select signal */

static void s3c2410_nand_select_chip(void)

{

    int i;

    s3c2410nand->NFCONF &= ~(1<<11);

    for(i=0; i<10; i++);    

}

 

/* Cancel chip select signal*/

static void s3c2410_nand_deselect_chip(void)

{

    s3c2410nand->NFCONF |= (1<<11);

}

 

/* Issue a command */

static void s3c2410_write_cmd(int cmd)

{

    volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFCMD;

    *p = cmd;

}

 

/* Sending address */

static void s3c2410_write_addr(unsigned int addr)

{

    int i;

    volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFADDR;

    

    *p = addr & 0xff;

    for(i=0; i<10; i++);

    *p = (addr >> 9) & 0xff;

    for(i=0; i<10; i++);

    *p = (addr >> 17) & 0xff;

    for(i=0; i<10; i++);

    *p = (addr >> 25) & 0xff;

    for(i=0; i<10; i++);

}

 

/* Read data */

static unsigned char s3c2410_read_data(void)

{

    volatile unsigned char *p = (volatile unsigned char *)&s3c2410nand->NFDATA;

    return *p;

}

 

/* S3C2440 NAND Flash operation function*/

 

/* Reset */

static void s3c2440_nand_reset(void)

{

    s3c2440_nand_select_chip();

    s3c2440_write_cmd(0xff); // reset command

    s3c2440_wait_idle();

    s3c2440_nand_deselect_chip();

}

 

/* Wait for NAND Flash to be ready */

static void s3c2440_wait_idle(void)

{

    int i;

    volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFSTAT;

    while(!(*p & BUSY))

        for(i=0; i<10; i++);

}

 

/* Send chip select signal */

static void s3c2440_nand_select_chip(void)

{

    int i;

    s3c2440nand->NFCONT &= ~(1<<1);

    for(i=0; i<10; i++);    

}

 

/* Cancel chip select signal*/

static void s3c2440_nand_deselect_chip(void)

{

    s3c2440nand->NFCONT |= (1<<1);

}

 

/* Issue a command */

static void s3c2440_write_cmd(int cmd)

{

    volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFCMD;

    *p = cmd;

}

 

/* Sending address */

static void s3c2440_write_addr(unsigned int addr)

{

    int i;

    volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFADDR;

    

    *p = addr & 0xff;

    for(i=0; i<10; i++);

    *p = (addr >> 9) & 0xff;

    for(i=0; i<10; i++);

    *p = (addr >> 17) & 0xff;

    for(i=0; i<10; i++);

    *p = (addr >> 25) & 0xff;

    for(i=0; i<10; i++);

}

 

 

static void s3c2440_write_addr_lp(unsigned int addr)

{

int i;

volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFADDR;

int col, page;

 

col = addr & NAND_BLOCK_MASK_LP;

page = addr / NAND_SECTOR_SIZE_LP;

*p = col & 0xff; /* Column Address A0~A7        0 */

for(i=0; i<10; i++);

*p = (col >> 8) & 0x0f; /* Column Address A8~A11   0 */

for(i=0; i<10; i++);

*p = page & 0xff; /* Row Address A12~A19         2 */

for(i=0; i<10; i++);

*p = (page >> 8) & 0xff; /* Row Address A20~A27     0 */

for(i=0; i<10; i++);

*p = (page >> 16) & 0x03; /* Row Address A28~A29     0 */

for(i=0; i<10; i++);

}

 

 

/* Read data */

static unsigned char s3c2440_read_data(void)

{

    volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFDATA;

    return *p;

}

 

 

/* Reset NAND Flash before using it for the first time */

static void nand_reset(void)

{

    nand_chip.nand_reset();

}

 

static void wait_idle(void)

{

    nand_chip.wait_idle();

}

 

static void nand_select_chip(void)

{

    int i;

    nand_chip.nand_select_chip();

    for(i=0; i<10; i++);

}

 

static void nand_deselect_chip(void)

{

    nand_chip.nand_deselect_chip();

}

 

static void write_cmd(int cmd)

{

    nand_chip.write_cmd(cmd);

}

static void write_addr(unsigned int addr)

{

    nand_chip.write_addr(addr);

}

 

static unsigned char read_data(void)

{

    return nand_chip.read_data();

}

 

 

/* Initialize NAND Flash */

void nand_init(void)

{

#define TACLS   0

#define TWRPH0  3

#define TWRPH1  0

 

    /* Determine whether it is S3C2410 or S3C2440 */

    if ((GSTATUS1 == 0x32410000) || (GSTATUS1 == 0x32410002))

    {

        nand_chip.nand_reset         = s3c2410_nand_reset;

        nand_chip.wait_idle          = s3c2410_wait_idle;

        nand_chip.nand_select_chip   = s3c2410_nand_select_chip;

        nand_chip.nand_deselect_chip = s3c2410_nand_deselect_chip;

        nand_chip.write_cmd          = s3c2410_write_cmd;

        nand_chip.write_addr         = s3c2410_write_addr;

        nand_chip.read_data          = s3c2410_read_data;

 

/* Enable NAND Flash controller, initialize ECC, disable chip select, set timing*/

        s3c2410nand->NFCONF = (1<<15)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0);

    }

    else

    {

        nand_chip.nand_reset         = s3c2440_nand_reset;

        nand_chip.wait_idle          = s3c2440_wait_idle;

        nand_chip.nand_select_chip   = s3c2440_nand_select_chip;

        nand_chip.nand_deselect_chip = s3c2440_nand_deselect_chip;

        nand_chip.write_cmd          = s3c2440_write_cmd;

#ifdef LARGER_NAND_PAGE

        nand_chip.write_addr         = s3c2440_write_addr_lp;

#else

nand_chip.write_addr = s3c2440_write_addr;

#endif

        nand_chip.read_data          = s3c2440_read_data;

 

/* Set timing */

        s3c2440nand->NFCONF = (TACLS<<12)|(TWRPH0<<8)|(TWRPH1<<4);

        /* Enable NAND Flash controller, initialize ECC, disable chip select*/

        s3c2440nand->NFCONT = (1<<4)|(1<<1)|(1<<0);

    }

    

    /* Reset NAND Flash */

    nand_reset();

}

 

 

/* Read function */

void nand_read(unsigned char *buf, unsigned long start_addr, int size)

{

    int i, j;

 

#ifdef LARGER_NAND_PAGE

    if ((start_addr & NAND_BLOCK_MASK_LP) || (size & NAND_BLOCK_MASK_LP)) {

        return ; /* Address or length is not aligned */

    }

#else

    if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {

        return ; /* Address or length is not aligned */

    }

#endif

 

    /* Select chip */

    nand_select_chip();

 

    for(i=start_addr; i < (start_addr + size);) {

      /* Issue READ0 command */

      write_cmd(0);

 

      /* Write Address */

      write_addr(i);

#ifdef LARGER_NAND_PAGE

      write_cmd(0x30);

#endif

      wait_idle();

 

#ifdef LARGER_NAND_PAGE

      for(j=0; j < NAND_SECTOR_SIZE_LP; j++, i++) {

#else

  for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {

#endif

          *buf = read_data();

          buf++;

[1] [2]
Keywords:TQ2440  NAND  Flash  Controller Reference address:TQ2440 Study Notes—— 20. NAND Flash Controller

Previous article:TQ2440 Study Notes—— 30. Porting U-Boot [Source code analysis of the first stage of U-Boot startup process]
Next article:TQ2440 Study Notes —— 23. Universal Asynchronous Receiver/Transmitter UART

Recommended ReadingLatest update time:2024-11-16 16:39

s3c2440 migration u-boot-2016.03 Part 3 supports Nor flash recognition
When selected, NOR flash is enabled, and NOR FLASH can be accessed. /common/board_r.c 364 line: initr_flash() flash_size = flash_init(); /drivers/mtd/cfi_flash.c If you want to enable debugging, define this #define DEBUG flash_init() debug("JEDEC PROBE: ID %x %x %xn", info- manufacturer_id, info- device_id, info- devi
[Microcontroller]
s3c2440 migration u-boot-2016.03 Part 3 supports Nor flash recognition
【Record】NAND FLASH controller
The structure of the bin file consists of two parts. The main program is placed at address 4096 in the NAND flash. The first 4k of program is responsible for copying the main program directly into SDRAM. The first 4k of the program is executed in the on-chip SRAM, and the main program is executed on SDRAM.
[Microcontroller]
【Record】NAND FLASH controller
RAM, SRAM, SDRAM, ROM, EPROM, EEPROM, Flash memory concepts
Common memory concepts: RAM, SRAM, SDRAM, ROM, EPROM, EEPROM, Flash memory can be divided into many categories. According to whether the data is lost when power is off, it can be divided into RAM (random access memory) and ROM (read-only memory). RAM has a faster access speed, but the data will be lost after power o
[Microcontroller]
Strong earthquake hits Japan's west coast, Toshiba NAND flash memory factory temporarily suspends production
On the first day of the new year, a strong earthquake hit the west coast of Japan, causing heavy casualties and possibly affecting the supply of computer accessories. Toshiba announced that it will temporarily suspend production at its NAND flash memory factory in Nomi City, Ishikawa Prefecture due to the need for a s
[Semiconductor design/manufacturing]
Two boot modes of ARM (NAND FLASH. NOR FLASH)
Why are there two startup methods? This is determined by the different characteristics of the two types of FLASH. NAND FLASH has a large capacity and the cost of storing unit bit data is much lower, but NAND FLASH must be read and written according to a specific timing, so the CPU cannot directly address the data i
[Microcontroller]
S5PV210 Nand flash driver writing
Hello everyone, it's time for Tianqian's again. Compared with the previous , which mainly shared the technology of TQ335X development board, this issue decided to share the technology of TQ210 development board, which is also in the cortex-a8 series. This issue is about the Nand flash driver writing of TQ210 developme
[Microcontroller]
Why does STM32 remap boot from Flash address 0x08000000
When I first wrote an STM32 program, I encountered a confusion. The STM32 Flash was set to start at address 0x0800 0000 in MDK, but the CM3 manual stipulates that the interrupt vector should be taken from address 0x0000 0000 when the chip is reset. So how does the STM32 execute the code? Address remapping? Or is there
[Microcontroller]
Design of FLASH boot loader system for single chip microcomputer
Preface The boot loading of DSP system refers to the process that DSP transfers a code stored in external non-volatile memory to internal high-speed memory unit and executes it when the system is powered on. FLASH is a high-density, non-volatile electrically erasable memory, and the price per storag
[Microcontroller]
Design of FLASH boot loader system for single chip microcomputer
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号