FATFS 主函数
int main(void)
{
uint8_t showData[5] = {0, 0, 0, 0, 0}, ledState;
FATFS fs0, fs1;
uint32_t free, total, i = 0;
TFT_Init();
FLASH_Init();
GUI_DisplayInit();
USART1_Config(9600);
LED_Config();
while(SD_Init())
{
GUI_Show12Char(0, 126, "SD 卡初始化错误", RED, BLACK);
}
f_mount(0,&fs0); //挂载 SD 卡
f_mount(1,&fs1); //挂载 FLASH 卡
/* 读取 SD 卡 FAT 的容量和空余 */
if(FATFS_GetFree("0:", &total, &free))
{
printf(" SD 卡 FAT 错误!");
GUI_Show12Char(0, 147, "SD 卡 FAT 错误!", RED, BLACK);
}
else
{
/* 显示 FAT 容量 */
total >>= 10; //从 KB 转成 MB
free >>= 10;
printf(" sd card total memory:%d MB\n", total);
printf(" sd card free memory:%d MB\n", free);
showData[0] = (total % 10000 /1000) + '0';
showData[1] = (total % 1000 /100) + '0';
showData[2] = (total % 100 /10) + '0';
showData[3] = (total % 10) + '0';
GUI_Show12Char(0, 126, "sd card total memory is: MB", RED,
BLACK);
GUI_Show12Char(192, 126, showData, RED, BLACK);
showData[0] = (total % 10000 /1000) + '0';
showData[1] = (total % 1000 /100) + '0';
showData[2] = (total % 100 /10) + '0';
showData[3] = (total % 10) + '0';
GUI_Show12Char(0, 147, "sd card free memory is: MB", RED,
BLACK);
GUI_Show12Char(184, 147, showData, RED, BLACK);
}
/* 读取 FLASH 卡 FAT 的容量和空余 */
while(FATFS_GetFree("1:", &total, &free))
{
f_mkfs(1, 1, 4096); //如果读取失败,格式化 FLASH
i++;
if(i > 10)
{
break;
}
}
/* 显示 FAT 容量 */
if(i > 10)
{
printf(" FLASH FAT 错误!");
GUI_Show12Char(0, 84, "FLASH FAT error!", RED, BLACK);
}
else
{
printf(" FLASH total memory:%d KB\n", total);
printf(" FLASH free memory:%d KB\n", free);
showData[0] = (total % 10000 /1000) + '0';
showData[1] = (total % 1000 /100) + '0';
showData[2] = (total % 100 /10) + '0';
showData[3] = (total % 10) + '0';
GUI_Show12Char(0, 84, "FLASH total memory is: KB", RED,
BLACK);
GUI_Show12Char(176, 84, showData, RED, BLACK);
showData[0] = (total % 10000 /1000) + '0';
showData[1] = (total % 1000 /100) + '0';
showData[2] = (total % 100 /10) + '0';
showData[3] = (total % 10) + '0';
GUI_Show12Char(0, 105, "FLASH free memory is: KB", RED,
BLACK);
GUI_Show12Char(168, 105, showData, RED, BLACK);
}
while(1)
{
/* LED 灯闪烁 */
i++;
if(i>0xFFFFF)
{
i = 0;
if(ledState == 0xFE)
{
ledState = 0xFF;
}
else
{
ledState = 0xFE;
}
LED_SetState(ledState);
}
}
} |