大师,我移植了FATFS到flash,发现格式化未成功(未移植操作系统时多扇区(512B)读写没问题,已经测试过),如何配置格式化函数呀:
#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */
/* Maximum sector size to be handled.
/ Always set 512 for memory card and hard disk but a larger value may be
/ required for floppy disk (512/1024) and optical disk (512/2048).
/ When _MAX_SS is larger than 512, GET_SECTOR_SIZE command must be implememted
/ to the disk_ioctl function. */
#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */
/* Maximum sector size to be handled.
/ Always set 512 for memory card and hard disk but a larger value may be
/ required for floppy disk (512/1024) and optical disk (512/2048).
/ When _MAX_SS is larger than 512, GET_SECTOR_SIZE command must be implememted
/ to the disk_ioctl function. */
RE:fatfs文件系统格式化代码SPI flash
RE:fatfs文件系统格式化代码SPI flash
回复:fatfs文件系统格式化代码SPI flash
回复:fatfs文件系统格式化代码SPI flash
#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */
/* Maximum sector size to be handled.
/ Always set 512 for memory card and hard disk but a larger value may be
/ required for floppy disk (512/1024) and optical disk (512/2048).
/ When _MAX_SS is larger than 512, GET_SECTOR_SIZE command must be implememted
/ to the disk_ioctl function. */
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
DRESULT disk_ioctl(
BYTE drv, /* Physical drive nmuber (0..) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res = RES_OK;
//DWORD result;
if (drv)
{
return RES_ERROR;
}
switch (ctrl)
{
case CTRL_SYNC:
break;
case GET_SECTOR_COUNT:
*(DWORD*)buff = (DWORD) 4096;
break; //2M byte
case GET_SECTOR_SIZE:
//*(DWORD*)buff = (DWORD) 2048; //>512时从这里获得扇区大小
break;
//单扇区字节数
case GET_BLOCK_SIZE:
*(DWORD*)buff = (DWORD) 4096;
break; //族大小
case CTRL_POWER :
break;
case CTRL_LOCK :
break;
case CTRL_EJECT :
break;
default:
res = RES_ERROR;
break;
}
return res;
}
int main(void)
{
UARTInit (); /* UARTInit */
PINSEL0 = PINSEL0 & (~0x0F); /* UART0,设置I/O连接到UART*/
PINSEL0 = PINSEL0 | 0x05; /* P0.0 = TXD0,P0.1 = RXD0*/
UART0SendStr("\x0c\0");
UART0SendStr("\x0c\0"); //超级终端清屏
UART0SendStr("\033[1;40;32m"); //设置超级终端背景为黑色,字符为绿色
UART0SendStr("\r\n*******************************************************************************");
UART0SendStr("\r\n*********************** Copyright 2012-10-10, liujiehan ***********************");
UART0SendStr("\r\n************************** http://www.upcomputer.com **************************");
UART0SendStr("\r\n***************************** All Rights Reserved *****************************");
UART0SendStr("\r\n*******************************************************************************");
UART0SendStr("\r\n");
/*初始化文件系统,检查芯片是否插入以及是否型号正确*/
res = disk_initialize(NORFLASH);
if(res == RES_OK)
{
UART0SendStr("initialize filesystem successed!\n\r\n\r");
}
else
{
UART0SendStr("initialize filesystem failed!\n\r\n\r");
}
/*挂载文件系统*/
res = f_mount(NORFLASH,&fs);
if(res == RES_OK)
{
UART0SendStr("mount filesystem successed!\n\r\n\r");
}
else
{
UART0SendStr("mount filesystem failed!\n\r\n\r");
}
/*格式化磁盘*/
UART0SendStr("正在格式化磁盘,请稍候...\n\r\n\r");
//res = f_mkfs(NORFLASH,1,4096);//4096:每簇占用字节数
res = f_mkfs(NORFLASH,0,4096);//4096:每簇占用字节数
if(res == RES_OK)
{
UART0SendStr("format filesystem successed!\n\r");
}
else
{
UART0SendStr("format filesystem failed!\n\r");
}
res = f_mount(NORFLASH,NULL);
/////////////////////////////////////////////////////////////////////////////////////////////////
res = f_mount(NORFLASH,&fs);
/*写文件测试*/
UART0SendStr("write file test......\n\r");
res = f_open(&FileObject, "test.txt", FA_CREATE_ALWAYS | FA_WRITE);
。。。
}
回复:fatfs文件系统格式化代码SPI flash
#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */
/* Maximum sector size to be handled.
/ Always set 512 for memory card and hard disk but a larger value may be
/ required for floppy disk (512/1024) and optical disk (512/2048).
/ When _MAX_SS is larger than 512, GET_SECTOR_SIZE command must be implememted
/ to the disk_ioctl function. */
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
DRESULT disk_ioctl(
BYTE drv, /* Physical drive nmuber (0..) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res = RES_OK;
//DWORD result;
if (drv)
{
return RES_ERROR;
}
switch (ctrl)
{
case CTRL_SYNC:
break;
case GET_SECTOR_COUNT:
*(DWORD*)buff = (DWORD) 4096;
break; //2M byte
case GET_SECTOR_SIZE:
//*(DWORD*)buff = (DWORD) 2048; //>512时从这里获得扇区大小
break;
//单扇区字节数
case GET_BLOCK_SIZE:
*(DWORD*)buff = (DWORD) 4096;
break; //族大小
case CTRL_POWER :
break;
case CTRL_LOCK :
break;
case CTRL_EJECT :
break;
default:
res = RES_ERROR;
break;
}
return res;
}
int main(void)
{
UARTInit (); /* UARTInit */
PINSEL0 = PINSEL0 & (~0x0F); /* UART0,设置I/O连接到UART*/
PINSEL0 = PINSEL0 | 0x05; /* P0.0 = TXD0,P0.1 = RXD0*/
UART0SendStr("\x0c\0");
UART0SendStr("\x0c\0"); //超级终端清屏
UART0SendStr("\033[1;40;32m"); //设置超级终端背景为黑色,字符为绿色
UART0SendStr("\r\n*******************************************************************************");
UART0SendStr("\r\n*********************** Copyright 2012-10-10, liujiehan ***********************");
UART0SendStr("\r\n************************** http://www.upcomputer.com **************************");
UART0SendStr("\r\n***************************** All Rights Reserved *****************************");
UART0SendStr("\r\n*******************************************************************************");
UART0SendStr("\r\n");
/*初始化文件系统,检查芯片是否插入以及是否型号正确*/
res = disk_initialize(NORFLASH);
if(res == RES_OK)
{
UART0SendStr("initialize filesystem successed!\n\r\n\r");
}
else
{
UART0SendStr("initialize filesystem failed!\n\r\n\r");
}
/*挂载文件系统*/
res = f_mount(NORFLASH,&fs);
if(res == RES_OK)
{
UART0SendStr("mount filesystem successed!\n\r\n\r");
}
else
{
UART0SendStr("mount filesystem failed!\n\r\n\r");
}
/*格式化磁盘*/
UART0SendStr("正在格式化磁盘,请稍候...\n\r\n\r");
//res = f_mkfs(NORFLASH,1,4096);//4096:每簇占用字节数
res = f_mkfs(NORFLASH,0,4096);//4096:每簇占用字节数
if(res == RES_OK)
{
UART0SendStr("format filesystem successed!\n\r");
}
else
{
UART0SendStr("format filesystem failed!\n\r");
}
res = f_mount(NORFLASH,NULL);
/////////////////////////////////////////////////////////////////////////////////////////////////
res = f_mount(NORFLASH,&fs);
/*写文件测试*/
UART0SendStr("write file test......\n\r");
res = f_open(&FileObject, "test.txt", FA_CREATE_ALWAYS | FA_WRITE);
。。。
}