|

楼主 |
发表于 2016-11-7 09:53:58
|
显示全部楼层
测试时连续读写了16个块,验证了每页2048个数据没有错。64B spare area各位含义如下图:
以下初始化、读写函数:
static U32 Init (NAND_DRV_CFG *cfg) {
/* Define spare area layout */
cfg-> gLay-> os_LSN = 4;
cfg-> gLay-> os_COR = 2;
cfg-> gLay-> os_BBM = 0;
cfg-> gLay-> os_ECC = 8;
/* Define page organization */
cfg-> gLay->SectInc = 512;
cfg-> gLay->SpareOfs = 2048;
cfg->PgLay->SpareInc = 16;
NAND_Init();
return RTV_NOERR;
}
/*-----------------------------------------------------------------------------
* Read page
* row = Page address
* *buf = Pointer to data buffer
* *cfg = Pointer to configuration structure
*
* Return: RTV_NOERR - Page read successful
* ERR_NAND_HW_TOUT - Hardware transfer timeout
* ERR_ECC_COR - ECC corrected the data within page
* ERR_ECC_UNCOR - ECC was not able to correct the data
*----------------------------------------------------------------------------*/
static U32 PageRead (U32 row, U8 *buf, NAND_DRV_CFG *cfg) {
U8 Status;
Status = NAND_ReadPage(buf, row, 0, NAND_PAGE_TOTAL_SIZE);
return Status;
}
static U32 PageWrite (U32 row, U8 *buf, NAND_DRV_CFG *cfg) {
U8 Status;
Status = NAND_WritePage(buf, row, 0, NAND_PAGE_TOTAL_SIZE);
return Status;
}
底层检读取态寄存器返回ECC校验结果等
uint8_t FSMC_NAND_ReadPage(uint8_t *_pBuffer, uint32_t _ulPageNo, uint16_t _usAddrInPage, uint16_t _usByteCount)
{
unsigned int au32SourceData;
unsigned int au32DestinationData;
unsigned int counter;
unsigned char eccresult;
//2Îêy′íÎó
if(_usByteCount > (2112-_usAddrInPage))
return ERR_NAND_HW_TOUT;
// /CS: active
SPI_SET_SS_LOW(SPI2);
// configure transaction length as 8 bits
SPI_SET_DATA_WIDTH(SPI2, 8);
// send Command: 0x03, Read data
au32SourceData = 0x13;
SPI_WRITE_TX(SPI2, au32SourceData);
while(SPI_IS_BUSY(SPI2));
au32SourceData = 0;
SPI_WRITE_TX(SPI2, au32SourceData);
while(SPI_IS_BUSY(SPI2));
SPI_SET_DATA_WIDTH(SPI2, 16);
// send 16-bit start address
au32SourceData = _ulPageNo&0xffff;
SPI_WRITE_TX(SPI2, au32SourceData);
while(SPI_IS_BUSY(SPI2));
SPI_SET_SS_HIGH(SPI2);
//μè′yÖ¸¶¨ò3êy¾Yìî3ädata bufferíê3é
for(counter = 6; counter >0; counter--)
{
if(NAND_IsReady() == 0)
break;
SysTickDelay(10);
}
if(counter == 0)
return ERR_NAND_HW_TOUT;
SPI_SET_SS_LOW(SPI2);
// configure transaction length as 8 bits
SPI_SET_DATA_WIDTH(SPI2, 8);
au32SourceData = 0x03;
SPI_WRITE_TX(SPI2, au32SourceData);
while(SPI_IS_BUSY(SPI2));
SPI_SET_DATA_WIDTH(SPI2, 24);
// send 24-bit start address
au32SourceData = _usAddrInPage;
au32SourceData <<= 8;
SPI_WRITE_TX(SPI2, au32SourceData);
while(SPI_IS_BUSY(SPI2));
SPI_SET_DATA_WIDTH(SPI2, 8);
I2S_CLR_RX_FIFO(SPI2);
for(counter = 0; counter < _usByteCount; counter++)
{
// receive
au32SourceData = 0x0;
SPI_WRITE_TX(SPI2, au32SourceData);
while(SPI_IS_BUSY(SPI2));
// dump Rx register
au32DestinationData = SPI_READ_RX(SPI2);
_pBuffer[counter] = (unsigned char) au32DestinationData;
}
// /CS: de-active
SPI_SET_SS_HIGH(SPI2);
eccresult = (NAND_ReadStatusReg(0xc0)&0x30)>>4;
if(eccresult == 0)
return RTV_NOERR;
else if(eccresult == 1)
return ERR_ECC_COR;
else
return ERR_ECC_UNCOR;
}
不知道还有哪里有问题???或者除了验证2048字节数据读写正确,还需要测什么? |
|