mini2440的nandflash裸机代码
根据韦东山的代码改的程序,,不知道哪里有问题,led不亮,只改了nand.c程序,其他的和韦东山的一样,请各位帮忙看看。*************************************nand.c***************************************************
#define NFCONF (*(volatile unsigned long *)0x4e000000)
#define NFCONT (*(volatile unsigned long *)0x4e000004)
#define NFCMD (*(volatile unsigned long *)0x4e000008)
#define NFADDR (*(volatile unsigned long *)0x4e00000C)
#define NFDATA (*(volatile unsigned long *)0x4e000010)
#define NFSTAT (*(volatile unsigned long *)0x4e000020)
#define NFCONF (*(volatile unsigned long *)0x4e000000)
#define NAND_SECTOR_SIZE_LP 2048
#define NAND_BLOCK_MASK_LP (NAND_SECTOR_SIZE_LP-1)
#define TACLS 0
#define TWRPH0 3
#define TWRPH1 0
#define send_cmd(cmd) {NFCMD=(cmd);}
#define send_addr(addr) {NFADDR=(addr);}
#define send_data(date) {NFDATA=(date);}
#define read_byte() NFDATA
#define enable() {NFCONT&=~(1<<1);}
#define disable() {NFCONT|=(1<<1);}
#define enable_rb() {NFSTAT|=(1<<2);}
#define check_busy() {while(!(NFSTAT&(1<<2)));}
#define waitrb() {while(!(NFSTAT&(1<<2)));}
void nand_read(unsigned char *buf,unsigned long start_addr,int size);
static void nand_reset()
{
enable();
enable_rb();
send_cmd(0xff);
check_busy();
disable();
}
void nand_init()
{
NFCONF=(TACLS<<12)|(TWRPH0<<8)|(TWRPH1<<4)/*|(3<<2)|(1<<1)*/;
NFCONT=(1<<4)|(1<<1)|(1<<0);
NFSTAT=0;
nand_reset();
}
static void write_addr(unsigned int addr)
{
int i;
int col,page;
col=addr&NAND_BLOCK_MASK_LP;
page=addr/NAND_SECTOR_SIZE_LP;
send_addr(col&0xff);
for(i=0;i<10;i++);
send_addr((col>>8)&0x0f);
for(i=0;i<10;i++);
send_addr(page&0xff);
for(i=0;i<10;i++);
send_addr((page>>8)&0xff);
for(i=0;i<10;i++);
send_addr((page>>16)&0x03);
for(i=0;i<10;i++);
}
void nand_read(unsigned char *buf,unsigned long start_addr,int size)
{
int i,j;
enable();
for(i=start_addr;i<(start_addr+size);)
{
send_cmd(0x00);
write_addr(i);
send_cmd(0x30);
check_busy();
for(j=0;j<NAND_SECTOR_SIZE_LP;i++,j++)
{
*buf=read_byte();
buf++;
}
}
disable();
}
页:
[1]