折腾了两三天终于搞定了s3c2440对nandflash的读写操作,s3c2410对nandflash的读写操作资料比较多而s3c2440的资料比较少,两款芯片在nandflash寄存器上有较大的变化,不能通用,需对照datasheet修改。
下面讲一下实验过程:
试验目的:使nandflash开始4k代码完成将4k以后代码copy到sdram内运行的功能。
试验内容:采用朗成AT2440EVB-I型开发板,nandflash启动跳线1,3,4在on位置,将head.s和init.c(主要完成初始化,nandflash读写,从nandflash到sdram的代码copy)写入nandflash起始地址(启动地址0x0000),将main.c(完成点亮LED的功能)存放到nandflash的4096地址,但使其在0x30000000(就是sdram的首地址)运行,这就需要nandflash启动后4k的代码将4096起始的代码copy到0x30000000运行。
过程:本来是有源代码的,但那是用在s3c2410上的,将其直接用到AT2440EVB-I型开发板上,失败。将2410和2440datasheet对照一看才知道寄存器有了很大变化,直接用是肯定不行的。查资料才知道2440的nandflash操作资料很少(好像2440的资料都很少,2410比较多),最后查到两个,一个是u-boot在2440上的移植,其中有从nandflash启动的读写函数(copy自vivi),另一个就是AT2440EVB-I型开发板自带的ATBOOT中nand_read.c,对照看了一下差不多,根据这两个资料改写init.c之后还是失败。只好又找资料将“nandflash读写操作”的原理搞清楚了(之前一直没搞清楚代码,只是拿过来用)。再看2410上的代码,发现2440上的少了nandflash的初始化函数,对照datasheet改写寄存器后,led终于亮了。^_^
s3c2410对nandflash读写操作寄存器配置的流程:
1.初始化
NFCONF=(1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0);或NFCONF = 0xf830;
(1)enable NAND flash controller(15位)
(2)initialize ECC(12位)
(3)chip disable(11位),使用时再chip enable
(4)设置TACLS=0、TWRPH0=3、TWRPH1=0 //2440采用默认值即可
2.复位
(1)NFCONF &= ~0x800;//chip enable
(2)NFCMD = 0xff; //reset command
(3)while(!(NFSTAT & BUSY))等待NAND flash memory ready to operate
3.读写函数
(1)NFCONF &= ~0x800;/* chip Enable */
(2)NFCMD = 0;//read0
(3)NFADDR = i & 0xff; NFADDR = (i >> 9) & 0xff; NFADDR = (i >> 17) & 0xff; NFADDR = (i >> 25) & 0xff;/* Write Address */
(4)while(!(NFSTAT & BUSY))等待NAND flash memory ready to operate
(5)*buf = (NFDATA & 0xff);//读数据线
(6)NFCONF |= 0x800; /* chip disable */
s3c2440对nandflash读写操作寄存器配置的流程:
1.初始化
(1)NFCONT = (1<<0) //enable NAND flash controller
(2)NFCONT |= (1<<1)/* chip disable */
2.复位
(1)NFCONT &= ~(1<<1) /* chip enable */
(2)NFCMD = 0xff; //reset command
(3)while(!(NFSTAT & BUSY))等待NAND flash memory ready to operate
3.读写函数
(1)NFCONT &= ~(1<<1) /* chip enable */
(2)NFSTAT |= (1<<2) //NAND_CLEAR_RB ,RnB transition is detected
(3)NFCMD = 0; //READ0,读上半叶
(4) /* Write Address */ NFADDR = i & 0xff; NFADDR = (i >> 9) & 0xff; NFADDR = (i >> 17) & 0xff; NFADDR = (i >> 25) & 0xff;
(5)while(! (NFSTAT&(1<<0)) ); /*NAND_DETECT_RB,等待NAND flash memory ready to operate*/
(6)*buf = (NFDATA & 0xff); //读数据线
(7)NFCONT |= (1<<1)/* chip disable */
s3c2440对nandflash读写操作部分源码(仅供学习使用):
代码: /* NAND Flash registers 2440*/#define NFCONF (*(volatile unsigned int *)0x4e000000)#define NFCONT (*(volatile unsigned int *)0x4e000004)#define NFCMD (*(volatile unsigned char *)0x4e000008)#define NFADDR (*(volatile unsigned char *)0x4e00000c)#define NFDATA (*(volatile unsigned char *)0x4e000010)#define NFSTAT (*(volatile unsigned char *)0x4e000020)#define NAND_CHIP_ENABLE (NFCONT &= ~(1<<1))#define NAND_CHIP_DISABLE (NFCONT |= (1<<1))#define NAND_CLEAR_RB (NFSTAT |= (1<<2))#define NAND_DETECT_RB { while(! (NFSTAT&(1<<0)) );}/* 在第一次实用NAND Flash前,复位一下NAND Flash */void reset_nand(){ int i=0;// NFCONF &= ~0x800;// for(; i<10; i++); NAND_CHIP_ENABLE; NFCMD = 0xff; //reset command wait_idle();}/* 初始化NAND Flash */void init_nand(){// NFCONF = 0xf830; NFCONT = (1<<0); NAND_CHIP_DISABLE;
|