自己编写的flash烧写程序工程
源代码在线查看: flashwrite.c
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\def.h"
#include "..\inc\flash.h"
void waitfor_endprog(void)//等待系统工作结束
{ volatile U16 flashstatus,old;
old=*((volatile U16 *)0x0);//用察看bit5的方法来检查
while(1)
{
flashstatus=*((volatile U16 *)0x0);
if((old&0x40)==(flashstatus&0x40))
break;
else
old=flashstatus;
}
}
U32 secaddr(U16 sec_index)//返回相应段的首地址
{
switch(sec_index)
{
case 0:return 0;
case 1:return 0x2000;
case 2:return 0x3000;
case 3:return 0x4000;
default:return(sec_index-3) }
}
void flash_sectorerase(U16 sector_index)//进行相应段的删除
{
U32 address;
address=secaddr(sector_index);
writeflash(0x555,0xAA);
writeflash(0x2AA,0x55);
writeflash(0x555,0x80);
writeflash(0x555,0xAA);
writeflash(0x2AA,0x55);
Uart_Printf("Erasing sector %d.\n",sector_index);
writeflash(address,0x30);
waitfor_endprog();
}
void flash_erase(U32 start,U32 end)//进行从首地址到末地址的段擦除
{
U16 start_i,end_i,i;
for(start_i=0;secaddr(start_i) for(end_i=start_i;secaddr(end_i) Uart_Printf("erase range:sector %d to sector %d\n",start_i-1,end_i-1);
for(i=start_i-1;i { flash_sectorerase(i);}
}
void chip_erase(void)//整片擦除
{
writeflash(0x555,0xAA);
writeflash(0x2AA,0x55);
writeflash(0x555,0x80);
writeflash(0x555,0xAA);
writeflash(0x2AA,0x55);
writeflash(0x555,0x10);
waitfor_endprog();
}
void flash_wordprog(U32 addr,U16 dat)
{
writeflash(0x555,0xAA);
writeflash(0x2AA,0x55);
writeflash(0x555,0xA0);
writeflash(addr,dat);
waitfor_endprog();
}