FATFS
首先是cubemx里面的基本配置, 注意flash的最小写单位是sector=4096Bytes, 然后实现flash的基本读写接口,需要单独测试通过之后才能布置到user_diskio.c里面去
void MX_FATFS_Init(void)
{
/*## FatFS: Link the USER driver ###########################*/
retUSER = FATFS_LinkDriver(&USER_Driver, USERPath);
/* USER CODE BEGIN Init */
/* additional user code for init */
/* additional user code for init */
#if 1
fs_log("--------------------FATFS SYSTEM---------------------\r\n");
if (retUSER != RES_OK) {
fs_log("fatfs: Link the USER driver failed.\r\n");
}
fs_log("try f_mount...\r\n");
retUSER = f_mount(&USERFatFS, USERPath, 1);
if (retUSER != RES_OK) {
fs_log("Failed to mount the disk during system startup.(%d)\r\n", retUSER);
if (retUSER == FR_NO_FILESYSTEM) {
fs_log("A new disk is detected, ready to format to FAT file system.\r\n");
fs_log("try f_mkfs...\r\n");
retUSER = f_mkfs((const TCHAR *)USERPath, FM_FAT, 0, USERFatFS.win, sizeof(USERFatFS.win));
if (retUSER != FR_OK) {
fs_log("----->failed.(%d)\r\n", retUSER);
} else {
fs_log("----->succeddfully.(%d)\r\n", retUSER);
fs_log("f_mount...\r\n");
retUSER = f_mount(NULL, USERPath, 1);
retUSER = f_mount(&USERFatFS, USERPath, 1);
if (retUSER == FR_OK) {
fs_log("----->succeddfully.(%d)\r\n", retUSER);
} else {
fs_log("----->failed.(%d)\r\n", retUSER);
}
}
}
} else {
uint32_t tot_sect, fre_sect;
exf_getfree((uint8_t *)USERPath, &tot_sect, &fre_sect);
fs_log("total %4d KB (%d Bytes) -> %04d KB (%d Bytes) available.\r\n", \