使用了华邦的SPI FLASH W25Q64 ,由于要经常性的更新Flash中的数据,初步估计平均每天更新100次左右,按照手册上的最高可大100,000次,也顶多只能用个3年。因此写了个测试程序来测试下。结果令人大跌眼镜~已经到了300,000+ 了,还没挂...有这么强大吗?这样就能用十年了...
本来计划写个简单的算法,每个扇区擦写个五万次后就写入个故障标志再换个扇区继续...
附上测试程序union {
unsigned int wfcount;
unsigned char wfbuf[4];
}RD_FLASH;
unsigned char rdbuf[4096],wbuf[4096];
#define TEST_FLASH_ADDR 0x6A6000
/********************************************main function**************************************
**************************************************************************************
********************************************************************************************/
int main()
{
unsigned int i;
unsigned char rbuf[2]=" ";
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x4000);
BSP_Init();
STM_EVAL_LEDOff(LED3);
printf("\r\n Test flash start... \r\n" );
SPI_FLASH_BufferRead(rdbuf,TEST_FLASH_ADDR, 4096);
if((rdbuf[0] == 0xff)&&(rdbuf[1] == 0xff)
&&(rdbuf[2] == 0xff)&&(rdbuf[3] == 0xff)){
RD_FLASH.wfcount = 0;
memcpy(wbuf, RD_FLASH.wfbuf, 4);
SPI_FLASH_SectorErase(TEST_FLASH_ADDR);
SPI_FLASH_BufferWrite(wbuf, TEST_FLASH_ADDR, 4096);
SPI_FLASH_BufferRead(rdbuf, TEST_FLASH_ADDR, 4096);
if(memcmp(wbuf,rdbuf,4096)==0){
RD_FLASH.wfcount ++;
printf("\r\n%d", RD_FLASH.wfcount );
}else
printf("\r\n write flash error! " );
}else{
memcpy(RD_FLASH.wfbuf, rdbuf, 4);
while(1){
RD_FLASH.wfcount ++;
memcpy(wbuf, RD_FLASH.wfbuf, 4);
SPI_FLASH_SectorErase(TEST_FLASH_ADDR);
SPI_FLASH_BufferWrite(wbuf, TEST_FLASH_ADDR, 4096);
SPI_FLASH_BufferRead(rdbuf,TEST_FLASH_ADDR, 4096);
if(memcmp(wbuf,rdbuf,4096)==0){
printf("\r\n%d", RD_FLASH.wfcount );
}else{
printf("\r\n write flash error! " );
break;
}
if(STM_EVAL_KeyGetState(Key1) == 0){ //有按键按下就退出测试
printf("\r\n write flash break! " );
break;
}
}
}
printf("\r\n Test flash flish... \r\n" );
STM_EVAL_LEDOn(LED3);
while(1)
{
}
}
|