1.NandFlash分类

根据物理结构上的区别,NandFlash主要分为如下两类:
•SLC (Single Level Cell): 单层式存储
•MLC (Multi Level Cell): 多层式存储
SLC在存储格上只存一位数据,而MLC则存放两位数据。

2.MLC与SLC对比

价格:由于MLC采用了更高密度的存储方式,因此同容量的MLC价格上远低于SLC.
访问速度:SLC的访问速度一般要比MLC快3倍以上.
使用寿命:SLC能进行10万次的擦写,MLC能进行1万次
功耗:MLC功耗比SLC高15%左右

3.NandFlash初始化

3.1 设置时间参数TACLS 、TWRPH0、TWRPH1

NandFlash读写-LMLPHP

3.2 使能NandFlash

NandFlash读写-LMLPHP

3.3 NandFlash复位

3.3.1 选中芯片

NandFlash读写-LMLPHP

3.3.2 清除RnB

NandFlash读写-LMLPHP

NandFlash读写-LMLPHP

3.3.3 发出复位信号(0xff)

NandFlash读写-LMLPHP

3.3.4 等待就绪

NandFlash读写-LMLPHP

NandFlash读写-LMLPHP

3.3.5 取消选中

4.按页读取NandFlash的值

NandFlash读写-LMLPHP

NandFlash读写-LMLPHP

步骤:

1.选中芯片;2.清除RnB;3.发出命令0x00;4.发送列地址;5.发送行地址;6.发出命令0x30;7.等待就绪;8.读数据 ;9.取消片选

5.向NandFlash写入数据

5.1 擦除(写之前要进行擦除)

NandFlash读写-LMLPHP

步骤:

1.选中芯片;2.清除RnB;3.发出命令0x60;4.发送行地址(3个周期);5.发送命令D0;6.等待RnB;7.发送命令70;8.读取擦除结果;9.取消片选

5.2 写入数据

NandFlash读写-LMLPHP

步骤:

1.选中芯片;2.清除RnB;3.发出命令0x80;4.发送列地址(2个周期);5.发送行地址(3个周期);6.写入数据;7.发送命令0x10;8.等待RnB;9.发送命令70;10.读取写入结果;10.取消片选

6.代码

nand.c

 /*
tiny6410用的nandflash为 一页2K
*/ #define NFCONF (*((volatile unsigned long*)0x70200000))
#define NFCONT (*((volatile unsigned long*)0x70200004))
#define NFCMMD (*((volatile unsigned char*)0x70200008))
#define NFSTAT (*((volatile unsigned char*)0x70200028))
#define NFADDR (*((volatile unsigned char*)0x7020000c))
#define NFDATA (*((volatile unsigned char*)0x70200010)) void select_ship(void)
{
NFCONT &= ~(<<);
} void delselect_ship(void)
{
NFCONT |= (<<);
} void clean_RnB()
{
NFSTAT |= (<<);
}
void nand_cmd(unsigned char cmd)
{
NFCMMD = cmd;
} void wait_RnB(void)
{
while(!(NFSTAT & 0x1));
} void nand_addr(unsigned char addr)
{
NFADDR = addr;
} void nand_reset(void)
{
/* 选中 */
select_ship(); /* 清除RnB */
clean_RnB(); /* 发出复位信号 */
nand_cmd(0xff); /* 等待就绪 */
wait_RnB(); /* 取消选中 */
delselect_ship();
} void nand_init(void)
{ /* 设置时间参数 */
#define TACLS 7
#define TWRPH0 7
#define TWRPH1 7 NFCONF &= ~((<<)|(<<)|(<<));
NFCONF |= (TACLS<<)|(TWRPH0<<)|(TWRPH1<<); /* 使能 nandflash controller*/
NFCONT = | (<<); /* 复位 */
nand_reset();
} void NF_PageRead(unsigned long addr,unsigned char* buff)
{
int i; /* 选中芯片 */
select_ship(); /* 清除RnB */
clean_RnB(); /* 发出命令0x00 */
nand_cmd(0x00); /* 发出列地址 */
nand_addr(0x00);
nand_addr(0x00); /* 发出行地址 */
nand_addr(addr&0xff);
nand_addr((addr >> ) & (0xff));
nand_addr((addr >> ) & (0xff)); /* 发出命令0x30 */
nand_cmd(0x30); /* 等待就绪 */
wait_RnB(); /* 读数据 */
for(i = ; i<*; i++)
{
*buff++ = NFDATA;
} /* 取消片选 */ delselect_ship(); } int NF_Erase(unsigned long addr)
{
int ret; //选中flash芯片
select_ship(); //清除RnB
clean_RnB(); //发送命令60
nand_cmd(0x60); //发送行地址(3个周期)
nand_addr(addr&0xff);
nand_addr((addr >> ) & (0xff));
nand_addr((addr >> ) & (0xff)); //发送命令D0
nand_cmd(0xD0); //等待RnB
wait_RnB(); //发送命令70
nand_cmd(0x70); //读取擦除结果
ret = NFDATA; //取消选中flash芯片
delselect_ship(); return ret;
} int NF_WritePage(unsigned long addr,unsigned char* buff)
{
int ret,i; //选中flash芯片
select_ship(); //清除RnB
clean_RnB(); //发送命令80
nand_cmd(0x80); //发送列地址(2个周期)
nand_addr(0x00);
nand_addr(0x00); //发送行地址(3个周期)
nand_addr(addr&0xff);
nand_addr((addr >> ) & (0xff));
nand_addr((addr >> ) & (0xff)); //写入数据
for(i=;i<*;i++)
{
NFDATA = buff[i];
} //发送命令10
nand_cmd(0x10); //等待RnB
wait_RnB(); //发送命令70
nand_cmd(0x70); //读取写入结果
ret = NFDATA; //取消选中flash芯片
delselect_ship(); return ret;
}

nand.c

nand_to_ram

汇编和C语言的参数传递,不超过4个的时候,直接用r0--r3传递,且顺序和从函数的形参一致

 copy_to_ram:
mov r0,#
ldr r1,=_start
ldr r2,=bss_end sub r2,r2,r1
mov ip,lr
bl nand_to_ram mov lr,ip mov pc,lr

start.S

 void nand_to_ram(unsigned long start_addr,unsigned char* sdram_addr,int size)
{
int i; for( i=(start_addr >>); size>;)
{
NF_PageRead(i,sdram_addr);
size -= ;
sdram_addr += ;
i++;
} }

nand_to_ram

05-01 02:21