微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > s3c2440对norflash的操作

s3c2440对norflash的操作

时间:11-11 来源:互联网 点击:

unsigned short *)(flash_base+ (0x100<1)))<16;

temp |= *(volatile unsigned short *)(flash_base + (1<1));

return temp;

}

下面的程序实现了对一块区域进行擦除,写入,并读出的操作,判断写入的数据是否与读出的数据相同:

…… ……

U16 buffer[1024];

char cmd;

…… ……

void test_en29lv160ab(void)

{

U32 temp;

U8 sta;

int i;

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

buffer[i]=2*i+1;

//读ID

temp = get_en29lv160ab_id();

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)((temp&0xff000000)>>24);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)((temp&0x00ff0000)>>16);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)((temp&0x0000ff00)>>8);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)((temp&0x000000ff));

reset_en29lv160ab(); //这里一定要复位

delay(100);

//擦除块33

sta=en29lv160ab_sector_erase(0xf0000);

if(sta == 0)

{

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=0xaf; //擦除出错

}

else

{

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

{

sta = en29lv160ab_program(0xf0000+(i<1),buffer[i]); //写

if(sta == 0) //写出错

{

while(!(rUTRSTAT0 & 0x2));

rUTXH0=0xbf;

break;

}

delay(200);

}

if(sta == 1)

{

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

{

if(read_en29lv160ab(0xf0000+(i<1))!=buffer[i]) //读出错

{

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=0xcf;

sta = 3;

break;

}

}

if(sta !=3) //全部操作都正确

{

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=0x66;

}

}

}

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=0x88; //结束

}

//简单测试CFI

void test_en29lv160ab_CFI(void)

{

U16 temp;

*((volatile U16 *)(0x55<1+flash_base))=0x98; //CFI命令

temp = (*(volatile unsigned short *)(flash_base+ (0x10<1)));

//while(!(rUTRSTAT0 & 0x2)) ;

//rUTXH0=(U8)((temp&0xff00)>>8);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)(temp&0x00ff);

temp = (*(volatile unsigned short *)(flash_base+ (0x11<1)));

//while(!(rUTRSTAT0 & 0x2)) ;

//rUTXH0=(U8)((temp&0xff00)>>8);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)(temp&0x00ff);

temp = (*(volatile unsigned short *)(flash_base+ (0x12<1)));

//while(!(rUTRSTAT0 & 0x2)) ;

//rUTXH0=(U8)((temp&0xff00)>>8);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)(temp&0x00ff);

temp = (*(volatile unsigned short *)(flash_base+ (0x13<1)));

//while(!(rUTRSTAT0 & 0x2)) ;

//rUTXH0=(U8)((temp&0xff00)>>8);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)(temp&0x00ff);

temp = (*(volatile unsigned short *)(flash_base+ (0x14<1)));

//while(!(rUTRSTAT0 & 0x2)) ;

//rUTXH0=(U8)((temp&0xff00)>>8);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)(temp&0x00ff);

temp = (*(volatile unsigned short *)(flash_base+ (0x15<1)));

//while(!(rUTRSTAT0 & 0x2)) ;

//rUTXH0=(U8)((temp&0xff00)>>8);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)(temp&0x00ff);

temp = (*(volatile unsigned short *)(flash_base+ (0x16<1)));

//while(!(rUTRSTAT0 & 0x2)) ;

//rUTXH0=(U8)((temp&0xff00)>>8);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)(temp&0x00ff);

temp = (*(volatile unsigned short *)(flash_base+ (0x17<1)));

//while(!(rUTRSTAT0 & 0x2)) ;

//rUTXH0=(U8)((temp&0xff00)>>8);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)(temp&0x00ff);

temp = (*(volatile unsigned short *)(flash_base+ (0x18<1)));

//while(!(rUTRSTAT0 & 0x2)) ;

//rUTXH0=(U8)((temp&0xff00)>>8);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)(temp&0x00ff);

temp = (*(volatile unsigned short *)(flash_base+ (0x19<1)));

//while(!(rUTRSTAT0 & 0x2)) ;

//rUTXH0=(U8)((temp&0xff00)>>8);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)(temp&0x00ff);

temp = (*(volatile unsigned short *)(flash_base+ (0x1a<1)));

//while(!(rUTRSTAT0 & 0x2)) ;

//rUTXH0=(U8)((temp&0xff00)>>8);

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=(U8)(temp&0x00ff);

}

void __irq uartISR(void)

{

char ch;

rSUBSRCPND |= 0x1;

rSRCPND |= 0x1<28;

rINTPND |= 0x1<28;

ch=rURXH0;

switch(ch)

{

case 0x11: //get ID

cmd = 1;

break;

case 0x66: //test CFI

cmd = 6;

break;

case 0x77: //test norflash

cmd = 7;

break;

}

while(!(rUTRSTAT0 & 0x2)) ;

rUTXH0=ch;

}

void Main(void)

{

U32 temp;

int i;

//uart0 port

rGPHCON = 0x00faaa;

rGPHUP = 0x7ff;

//init uart0

rULCON0 = 0x3;

rUCON0 = 0x5;

rUFCON0 = 0;

rUMCON0 = 0;

rUB

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top