cancel
Showing results for 
Search instead for 
Did you mean: 

No possibility to choose MMC in File System mode and configuration ?.

RMarz.1
Associate II

In CubeMX, when you configure SDMMC in MMC mode, then you add FATFS in Middleware, you can choose SD card but you there is no option for MMC. Why is that ? I am unable to mount a fs on my eMMC. Should I use User-defined ?

6 REPLIES 6
Ghofrane GSOURI
ST Employee

Hello @RMarz.1​ 

First let me thank you for posting .

In order to mount a file system on your eMMC, you can try using the "User-defined" option in CubeMX. This will allow you to manually specify the parameters required for the FATFS middleware to work with your eMMC.

To do this, you will need to consult the documentation for your eMMC device to determine the correct parameters to use. You may need to specify details such as the sector size for your eMMC device. Once you have entered these parameters into the User-defined section of CubeMX, you should be able to mount a file system on your eMMC.

Thx

Ghofrane

RMarz.1
Associate II

Thank you so much for replying, I have been trying to get this to work since last week.

I acutally have tried the "User-defined" option in CubeMX, the problem afterwards is when I use the MX_FATFS_Init() function it calls the FATFS_LinkDriver() function which requires a Driver (in the case of an SD card it is called SD_Driver and it is predefined), what should be done in order to have an equivalent of this Driver for the MMC case ?

Thank you.

Ghofrane GSOURI
ST Employee

Hello @RMarz.1​ 

In order to create a driver for your eMMC device, you will need to write your own low-level hardware interface functions to communicate with the device. These functions will typically include things like sending commands to the device, reading and writing data blocks, and managing the device's hardware interface (e.g. configuring the clock speed and I/O pins).

Once you have written these hardware interface functions, you can create a driver structure that contains function pointers to these low-level functions. This driver structure can then be passed to the FATFS middleware using the FATFS_LinkDriver() function.

Here's an example of what the driver structure might look like:

#include "ffconf.h"
#include "diskio.h"
 
/* eMMC hardware interface functions */
DSTATUS eMMC_disk_initialize(BYTE pdrv);
DSTATUS eMMC_disk_status(BYTE pdrv);
DRESULT eMMC_disk_read(BYTE pdrv, BYTE *buff, LBA_t sector, UINT count);
DRESULT eMMC_disk_write(BYTE pdrv, const BYTE *buff, LBA_t sector, UINT count);
DRESULT eMMC_disk_ioctl(BYTE pdrv, BYTE cmd, void *buff);
 
/* eMMC driver structure */
const Diskio_drvTypeDef eMMC_Driver = {
  eMMC_disk_initialize,
  eMMC_disk_status,
  eMMC_disk_read,
  eMMC_disk_write,
  eMMC_disk_ioctl
};

In this example, the eMMC_disk_initialize(), eMMC_disk_status(), eMMC_disk_read(), eMMC_disk_write(), and eMMC_disk_ioctl() functions are the low-level hardware interface functions for the eMMC device. These functions should be implemented to communicate with your specific eMMC device.

The eMMC_Driver structure contains function pointers to these low-level functions, and is defined using the Diskio_drvTypeDef structure provided by the FatFs middleware.

Once you have defined this driver structure, you can pass it to the FATFS_LinkDriver() function as follows:

FATFS fs;
if (FATFS_LinkDriver(&eMMC_Driver, "0") == 0) {
  if (f_mount(&fs, "0:", 1) == FR_OK) {
    // File system is mounted on the eMMC device
  }
}

In this example, the eMMC_Driver structure is passed to the FATFS_LinkDriver() function, along with a drive number ("0" in this case). If the function returns 0, the driver is successfully linked with the FATFS middleware.

After linking the driver, you can use the f_mount() function to mount the file system on the eMMC device, as shown in the example above.

Ghofrane GSOURI
ST Employee

Hello @RMarz.1​ 

Please check this UM1721 , it could be useful for you

RMarz.1
Associate II

@Ghofrane GSOURI​ Thank you again for your clear answer. I am a bit concerned however because writing my own low-level hw interface seems a bit complicated, especially that the datasheet of the eMMC that I am using does not detail all the commands. I thought the commands were standardized for all SD/MMC components.

RMarz.1
Associate II

@Ghofrane GSOURI​ Thank you for the provided document. I have a question if I may : Would it be possible to use the SD_Driver for the eMMC ? Because I have worked with an SD card before and now I'm trying to do the same with an eMMC and they both use the same SDIO pins and have similar functionalities. I'm wondering if it would be possible