近期使用STM32F429和NAND Flash做了个板子,NAND是新的(镁光的...4G08ABADA)。根据正点原子开发板F429的FatFS例程移植后,调试中出现如下的情况:
1、FTL层初始化正常,建立FTL表正常,初始化NAND正常、全片擦写寻找坏块功能也正常
2、PageRead、PageWrite正常,数据正确
3、FTL_WriteSector、FTL_ReadSector正常,数据正确
总之以上都正常
但是,在挂FatFs系统时,f_mount不成功,返回的值是13(没有文件系统)
我尝试使用f_mkfs建立文件系统,返回值是12(没有工作区)
请问大家,这种情况是如何造成的?怎样才能成功加载FatFs呢?
代码如下所示:其中FTL的函数完全是按照原子哥的例程做的
/* Private function prototypes -----------------------------------------------*/
DSTATUS NAND_initialize (void);
DSTATUS NAND_status (void);
DRESULT NAND_read (BYTE*, DWORD, BYTE);
#if _USE_WRITE == 1
DRESULT NAND_write (const BYTE*, DWORD, BYTE);
#endif /* _USE_WRITE == 1 */
#if _USE_IOCTL == 1
DRESULT NAND_ioctl (BYTE, void*);
#endif /* _USE_IOCTL == 1 */
Diskio_drvTypeDef NAND_Driver =
{
NAND_initialize,
NAND_status,
NAND_read,
#if _USE_WRITE == 1
NAND_write,
#endif /* _USE_WRITE == 1 */
#if _USE_IOCTL == 1
NAND_ioctl,
#endif /* _USE_IOCTL == 1 */
};
DSTATUS NAND_initialize(void)
{
if(FTL_Init()) {return RES_ERROR;}
else {return RES_OK;}
}
DSTATUS NAND_status(void)
{
DRESULT res = RES_ERROR;
if(NAND_ReadStatus() == NAND_READY)
{
res = RES_OK;
}
else
{
res = RES_ERROR;
}
return res;
}
DRESULT NAND_read(BYTE *buff, DWORD sector, BYTE count)
{
DRESULT res = RES_ERROR;
res = FTL_ReadSectors(buff,sector,512,count); //读取数据
if(res == 0x00) {return RES_OK;}
else {return RES_ERROR;}
}
#if _USE_WRITE == 1
DRESULT NAND_write(const BYTE *buff, DWORD sector, BYTE count)
{
DRESULT res = RES_ERROR;
res=FTL_WriteSectors((u8*)buff,sector,512,count);//写入数据
if(res == 0x00) {return RES_OK;}
else {return RES_ERROR;}
}
#endif /* _USE_WRITE == 1 */
#if _USE_IOCTL == 1
DRESULT NAND_ioctl(BYTE cmd, void *buff)
{
DRESULT res = RES_ERROR;
switch(cmd)
{
case CTRL_SYNC:
res = RES_OK;
break;
case GET_SECTOR_SIZE:
*(WORD*)buff = 512; //NAND FLASH扇区强制为512字节大小
res = RES_OK;
break;
case GET_BLOCK_SIZE:
*(WORD*)buff = nand_dev.page_mainsize/512;//block大小,定义成一个page的大小
res = RES_OK;
break;
case GET_SECTOR_COUNT:
*(DWORD*)buff = nand_dev.valid_blocknum*nand_dev.block_pagenum*nand_dev.page_mainsize/512;//NAND FLASH的总扇区大小
res = RES_OK;
break;
default:
res = RES_PARERR;
break;
}
}
#endif /* _USE_IOCTL == 1 */
一周热门 更多>