DSP学习第六篇——Flash 的使用
(2011-11-17 15:08:37)Flash芯片
Flash擦除
Attention:flash编程使用的是字地址
写flash
Flash_CS()与Flash_DisCS()
操作(读/写)flash前都要进行cpld片选flash的握手操作,即调用CS函数,操作完毕要释放dsp对flash的片选,调用disCS函数
CE1和CE2 接至
HX-5509 开发板通过功能选择寄存器组,利用 CE2、CE3 存储空间对各
寄存器组进行访问操作,操作流程如下:
1)读操作
①写功能选择寄存器组(写
存器组,对于读
②读目标寄存器组(读
③读操作完成后,再写功能选择寄存器组,禁用所有寄存器组。
2)写操作
①写功能选择寄存器组(写
存器组;
②写目标寄存器组(写
③写操作完成后,再写功能选择寄存器组,禁用所有寄存器组。
void Flash_CS()
{
}
附录:
void Flash_CS()
{
deminaddr = (int *)CESECT2;
*deminaddr = 0x00fd;
*deminaddr = 0x0040;
deminaddr = (int *)CESECT2;
*deminaddr = 0x00ff;
}
void Flash_disCS()
{
deminaddr = (int *)CESECT2;
*deminaddr = 0x00fd;
*deminaddr = 0x00c0;
deminaddr = (int *)CESECT2;
*deminaddr = 0x00ff;
}
void Flash_Reset()
{
deminaddr = (int *)CESECT2;
*deminaddr = 0x00fd;
*deminaddr = 0x0000;
delay(1000);
*deminaddr = 0x0040;
*deminaddr = 0x00c0;
deminaddr = (int *)CESECT2;
*deminaddr = 0x00ff;
}
Uint16 Flash_Erase_all()
{
deminaddr = (int *)CESECT1;
addbias = 0x0555;
*(deminaddr+addbias) = 0x00aa;
addbias = 0x02aa;
*(deminaddr+addbias) = 0x0055;
addbias = 0x0555;
*(deminaddr+addbias) = 0x0080;
addbias = 0x0555;
*(deminaddr+addbias) = 0x00aa;
addbias = 0x02aa;
*(deminaddr+addbias) = 0x0055;
addbias = 0x0555;
*(deminaddr+addbias) = 0x0010;
delay(100);
fstatus = *(deminaddr+addbias);
fstatus &= 0x0040;
fstatus2 = *(deminaddr+addbias);
if((fstatus&fstatus2)!=0)
{
Flash_disCS();
return 0;
}
else
{
while(fstatus!=0x00ff)
ddelay(500);
fstatus = *(deminaddr+addbias);
fstatus &= 0x00ff;
Flash_disCS();
return 1;
}
}
Uint16 Flash_Erase_sector()
{
return 1;
}
void Flash_Write_init()
{
Flash_CS();
deminaddr = (int *)CESECT1;
addbias = 0x0555;
*(deminaddr+addbias) = 0x00aa;
addbias = 0x02aa;
*(deminaddr+addbias) = 0x0055;
addbias = 0x0555;
*(deminaddr+addbias) = 0x0020;
}
Uint16 Flash_Write(Uint16 waddr, Uint16 wdata) //AM29LV800烧写
{
*(fwaddr+waddr) = wdata;
delay(10000);
fstatus = *(fwaddr+waddr);
{
delay(10000);
fstatus = *(fwaddr+waddr);
}
return 1;
}
void Flash_Write_end()
{
deminaddr = (int *)CESECT1;
*deminaddr = 0x0090;
*deminaddr = 0x0000;
Flash_disCS();
}
Uint16 Flash_Read(Uint16 raddr)
{
Uint16 frtemp;
frtemp = *(fraddr+raddr);
return frtemp;
}
main()
{
Flash_Reset();
success = Flash_Erase_all();
//以下程序为烧写AM29LV800
Flash_Write_init();
fwaddr = (int *)CESECT1;
fwaddr += 0x10000;
for(datacount=0;datacount<1000;datacount++)
{
success = Flash_Write(datacount, datacount);
}
Flash_Write_end();
//以下程序为读AM29LV800
for(datacount=0;datacount<1000;datacount++)
{
databuffer[datacount]=0;
}
Flash_CS();
fraddr = fwaddr;
for(datacount=0;datacount<1000;datacount++)
{
databuffer[datacount] = Flash_Read(datacount);
}
Flash_disCS();
//运行到此处,在view--memory里查看databuffer开始地址的数据,看是否所写即所读
}