Tool/software: TI-RTOS
Hello,
I'm using AM572x IDK board with TI-RTOS SDK 05.01.00.11.
I want to implement that logic:
- Detect EMMC memory fatfs formatting status (formatted/not formatted)
- Format emmc, if required
- Work with formatted emmc: read/write files
I implement it with that code:
FATFS_Error err = FATFS_OK;
char open_path[] = "1:path.txt";
int emmc_fat_index = 1;
FRESULT fat_err;
FIL f;
EmmcsReset();
FATFS_init();
err = FATFS_open(emmc_fat_index, NULL, &FatfsInit_emmcHandle);
if (err != FATFS_OK) {
Log_error1("ERROR: Cannot init emmc card. Error code %d\n", err);
return;
}
// try to open file
fat_err = f_open(&f, open_path, FA_READ);
if (fat_err == FR_NO_FILESYSTEM) {
Log_warning0("Cannot found emmc file system");
/* Create FAT volume */
res = f_mkfs(open_path, 0, 0);
if (res != FR_OK){
Log_error1("Cannot create emmc file system. Error code %d", res);
} else {
Log_info0("Emmc formatting completed");
}
}
if (fat_err == FR_OK)
{
// file not need
f_close(&f);
}
if (fat_err == FR_OK || fat_err == FR_NO_FILE || fat_err == FR_NO_PATH)
{
Log_info0("Filesystem on emmc was found");
}
But that code doesn't work as I want: f_mkfs() call returns error code 3. I debugged the library, and that error generates when fatfs driver call MMCSD_init() function again (first call was in f_open()).
I tried to close file system with FATFS_close(&FatfsInit_emmcHandle) function before f_mkfs() function call, but my code crashes (because ((FATFS_Config *) handle)->object has NULL value).
How should I implement the required logic?
With regards,
Alex
P.S. I rebuilt PDK fatfs driver with #define _USE_MKFS 1 option and rebuild project after that.
P.P.S. eMMC memory works, because eMMC PDK example test works fine.