记录下自己的调试过程:
注意:必须先定义flash对应的bank中tacc的值大于最长指令周期,这里是14个系统时钟
完成的功能:
检测flash ID DEVICE
该flash为16M 共有128个sector 因此每个sector大小为0x20000
擦除前必须先unlocked
检测ID指令:给0x1000000(芯片起始地址) 写0x90 ,在0x1000000 读出ID
检测DEVICE指令:给0x1000000(芯片起始地址) 写0x90 ,在0x1000002 读出DEVICE
检测是否锁指令:给0x1000000(芯片起始地址) 写0x90 ,在0x1000004 读出
解锁指令:第一个时序周期:给0x1000000(芯片起始地址) 写0x60
第二个时序周期:给0x1000000(芯片起始地址) 写0xd0
检测0x1000004第一位是否为1,是 说明解锁完成
结束,给0x1000000 写0xff
擦除sector指令:
第一个时序周期:给0x1000000(芯片起始地址) 写0x20
第二个时序周期:给0x1000000(芯片起始地址) 写0xd0
第三个时序周期:给0x1000000(芯片起始地址) 写0x70
检测0x1000000第一位是否为1,是则开始擦除一个sector 0x1000000~0x1020000
每次只能擦除0x10000,所以擦除两次
flash共有128个sector!
代码:
//==========================================================================================
int Strata_CheckID(int targetAddr)
{
//Add by HHTech
_WR(targetAddr, 0x0090);
return _RD(targetAddr); }
//==========================================================================================
int Strata_CheckDevice(int targetAddr)
{
_WR(targetAddr, 0x0090);
return _RD(targetAddr+0x2);
}
//==========================================================================================
void Strata_ClearBlockLock(int targetAddr)
{
U16 status;
//_RESET();
_WR(targetAddr, 0x0060);
_WR(targetAddr, 0x00d0);
while(1)
{
status=_RD(targetAddr+0x4);
if(status&(1<<7))break;
}
_RESET();
}
//==========================================================================================
void Strata_EraseSector(int targetAddress)
{
unsigned long ReadStatus;
unsigned long bSR5;
unsigned long bSR7;
_WR(targetAddress, 0x0020);
_WR(targetAddress, 0x0070);
ReadStatus=_RD(targetAddress);
bSR7=ReadStatus & (1<<7);
//bSR7_2=ReadStatus & (1<<(7+16));// higher 16-bit 8MB Strata
while(!bSR7 )
{
_WR(targetAddress, 0x0070);
ReadStatus=_RD(targetAddress);
bSR7=ReadStatus & (1<<7);
}
_WR(targetAddress, 0x0070);
ReadStatus=_RD(targetAddress);
bSR5=ReadStatus & (1<<5);
// bSR5_2=ReadStatus & (1<<(5+16)); // higher 16-bit 8MB Strata
if (bSR5==0 )
{
}
else
{
_WR(targetAddress, 0x0050); // Clear Status Register
error_erase=1; // But not major, is it casual ?
}
_RESET();
}
//==========================================================================================
/*int Strata_BlankCheck(int targetAddr,int targetSize)
{
int i;
U16 j;
for (i=0; i<targetSize; i+=2)
{
j=*((volatile U16 *)(i+targetAddr));
if (j!=0xffff) // In erasure it changes all block dta to 0xff
{
//Uart_Printf("E : %x = %x\n", (i+targetAddr), j);
return 0;
}
}
return 1;
}*/
void Program28F128J3A(void)
{
int i;
rINTMSK = BIT_ALLMSK;
targetAddress="TARGET"_ADDR_28F128;
targetOffset= 0x0;
targetSize = 0x20000*128;
//--------------------------------------------------------------------------------------------
if ( (Strata_CheckID(targetAddress) & 0xffff) != 0x0089 ) // ID number = 0x0089
{
//Uart_Printf("Identification check error !!\n");
return ;
}
//---------------------------------------------------------------------------------------------
if ( (Strata_CheckDevice(targetAddress) & 0xffff) != 0x0018 ) // Device number="0x0018"
{
//Uart_Printf("Device check error !!\n");
return ;
}
for(i=0;i<targetSize;i+=0x10000)
{
Strata_ClearBlockLock(targetAddress+targetOffset+i); //解除保护
Strata_EraseSector(targetAddress+targetOffset+i); //擦除
}
}
用户208031 2013-4-3 11:48