This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/PROCESSOR-SDK-AM57X: EMMC fatfs formatting after device startup

Part Number: PROCESSOR-SDK-AM57X

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.

  • Hi,

    Please use the latest Processor SDK RTOS 5.2 release for EMMC related testing and development work. We have made improvement over 5.1 release.

    There is a USB_DevMsc_mmcsd_evmAM572x_armExampleProject (under ti\drv\usb), it has -DUSB_DEVICE_EMMC in the compiler option, so this project is used to access the EMMC from the USB port. This is how we access a formatted or un-formatted EMMC drive using a host PC, over USB port.

    We don't have any development work using MMCSD/FATFS driver to format the EMMC. Instead, we used the host PC to format it.

    I tested it on AM572x GP EVM, my Windows PC detected a unknown USB driver. You can format it. If this is the first time you access the EMMC, it is not partitioned so formatting will fail. You can use the Windows PC, administrative tools====>computer management=====>Storage====>disk management to partition it. After that, I was able to write/read files from EMMC.

    Hope this info help and you may consider using host to format EMMC, it is one-time work.

    Regards, Eric