下面是合众达自带的flash调试和烧写程序中的函数flash_erase函数,有几句代码想请教一哈各位大神;
Uint32 flash_erase(Uint32 addr,unsigned short type)
{
Uint32 i,j;
*FLASH_5555 = FLASH_UL1; //first
*FLASH_2AAA = FLASH_UL2; //second
*FLASH_5555 = FLASH_UL3; //third
*FLASH_5555 = FLASH_UL4;
*FLASH_2AAA = FLASH_UL5;
switch(type)
{
case 0x50: //block erase
……
case 0x30: //sector erase
……
case 0x10: //chip erase
*FLASH_5555 = type;
while((*FLASH_5555 & 0x80) != 0x80); // (1) type的值为0x10,while会不会永远在这个空循环中?*FLASH_5555的值如何改变?
for(i = 0; i < CHIP_SIZE; i++)
{
if(*(unsigned short *)(addr + i) != 0xffff) // (2) 如果flash中有数值,这个if语句就不成立啦?
{
j = 0; break;
}
}
j = 1; break;
default:
break;
}
return (j); // (3) 返回的函数值 j 对程序的运行有何影响?
}
(4) 程序如何将flash内存擦除为0xFFFF?
下面是main程序
void main()
{
CSL_init();
EMIFB_config(&MyEmifbConfig);
IRQ_setVecs(vectors);
IRQ_nmiEnable();
IRQ_globalEnable();
flash_erase(0,0×10);
flash_writes(0x64001000,0x1234);
for(k = 0; k < 0x1000; k++)
{
data[k] = 0x1234+k;
}
flash_writem(0x64000000,&data[0],0x1000);
flash_readm(0x64000000,&data[0],0x1000);
for(;;);
}
我是个菜鸟,希望大家踊跃发表自己的想法,谢谢各位;
Tony Tang:
代码中特定的值是根据flash手册来的,看一下flash手册就好了。flash的写,擦除等操作都是有命令及步骤的。