📄 nor.c
字号:
/* most of the info are from datasheet of Intel.Strata.Flash.28f640j3
* however, it`s incomplete and its language is obscure for beginners
* so reading the fucking code is the best way to master it
*/
#include "hardware.h"
#include "hardware_reg.h"
#include "HA_typedef.h"
#include <stdio.h>
void NorFlash(void)
{
U32 temp;
U32 i,j;
temp = NorFlash_unlock(0x20000000 );
temp=NorFlash_bolckerase(0x20000000);
#if 1
for(i=0;i<0x10000;i++)
{
temp = 0xAAAA0000 | i;
temp = NorFlash_write( (0x20000000+(i*4)), temp );
}
printf("first block done!\n");
#endif
/////////////////////////////////////////////////////////////////
#if 1
for(i = 0; i<63; i++)
{
temp = NorFlash_bolckerase(0x20040000 + i*0x40000 );
}
printf("erase block done!\n");
for(i=0;i<0x10000;i++)
{
temp = 0xAAAA0000 | i;
temp = NorFlash_write( (0x20800000+(i*4)), temp );
}
printf("middle block done!\n");
for(i=0;i<0x10000;i++)
{
temp = 0xAAAA0000 | i;
temp = NorFlash_write( (0x20fc0000+(i*4)), temp );
}
printf("end block done!\n");
#endif
temp = NorFlash_Normal(0x20000000 );
printf("done!\n");
}
void TestofNorFlash(U32 dest,U32 size)
{
U32 i;
for(i=0;i<size/4;i++)
if(*(RP)(dest+i*4) != (0xAAAA0000 | i))
printf("%x\n",(dest+i*4));
printf("block %x test OK\n",(dest));
}
//////////////////////////////////////////////////
ER NorFlash_clearSR(void)
{
*(RP)0x0000000 = 0x500050;
return 1;
}
ER NorFlash_idlejud(U32 address)
{
U32 temp;
*(RP)address = 0x700070;
temp = *(RP)address;
while( temp != 0x800080 )
{
temp = *(RP)address ;
}
return 1;
}
ER NorFlash_Normal(U32 address)
{
U32 temp;
*(RP)address = 0xff00ff;
//temp = NorFlash_idlejud(address);
return 1;
}
ER NorFlash_unlock( U32 address)
{
U32 temp;
*(RP)address = 0x600060;
*(RP)address = 0xd000d0;
temp = NorFlash_idlejud(address);
return 1;
}
ER NorFlash_bolckerase(U32 blockadd)
{
U32 temp;
*(RP)blockadd = 0x200020;
*(RP)blockadd = 0xd000d0;
temp = NorFlash_idlejud(blockadd);
temp = NorFlash_clearSR( ); //Clear SR
return 1;
}
ER NorFlash_read( U32 address)
{
U32 temp;
//*(RP16)address = 0xff;
//*(RP)address = 0x200020;
//*(RP)address = 0xd000d0;
temp = NorFlash_idlejud(address);
return 1;
}
ER NorFlash_write( U32 Pageadd, U32 data )
{
U32 temp;
*(RP)Pageadd = 0x400040;
*(RP)Pageadd = data;
temp = NorFlash_idlejud(Pageadd);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -