cancel
Showing results for 
Search instead for 
Did you mean: 

The confusion of the using of the FatFs link driver in STM32Cube_FW

jacksong
Associate II
Posted on May 18, 2018 at 09:30

Hi all! I'm developing the SD application on the STM32H7 board with FatFs.  For my application, I need multiple partitions. According to the UM1721 manual, I know how to start this work. Now I have some confusions about the using of the FatFs link driver.

As the manual present, we  can use the uint8_t FATFS_LinkDriver(Diskio_drvTypeDef *drv, char *path) to link the I/O driver, which is shown as follows:

 /**

* @brief Links a compatible diskio driver and increments the number of active

* linked drivers.

* @note The number of linked drivers (volumes) is up to 10 due to FatFs limits

* @param drv: pointer to the disk IO Driver structure

* @param path: pointer to the logical drive path

* @retval Returns 0 in case of success, otherwise 1.

*/

uint8_t FATFS_LinkDriver(Diskio_drvTypeDef *drv, char *path)

{

uint8_t ret = 1;

uint8_t DiskNum = 0;

if(disk.nbr <_VOLUMES)

{

disk.is_initialized[disk.nbr] = 0;

disk.drv[disk.nbr] = drv;

DiskNum = disk.nbr++;

path[0] = DiskNum + '0';

path[1] = ':';

path[2] = '/';

path[3] = 0;

ret = 0;

}

return ret;

}

Q1:

if I need multiple partitions, whether I have to link each volumes with the diskio driver, e.g., coding as follows:

#define _VOLUMES 4 for(int vol=0; vol < _VOLUMES; vol++)  {  FATFS_LinkDriver(&SD_Driver, &SDPath[vol*4]);  }

char 

SDPath[4];

FATFS_LinkDriver(&SD_Driver, SDPath);

char SDPath[16];

PARTITION VolToPart[] = {

{0, 1},

{0, 2},

{0, 3},

{0, 4}

}; /* Volume - Partition resolution table */#define _VOLUMES 4 for(int vol=0; vol < _VOLUMES; vol++)  {  FATFS_LinkDriver(&SD_Driver, &SDPath[vol*4]);  }

char 

SDPath[4];

FATFS_LinkDriver(&SD_Driver, SDPath);

Actually, looking into the uint8_t FATFS_LinkDriver(Diskio_drvTypeDef *drv, char *path) function, I think that the codes shown above is incorrect, because the variable disk.nbr is used to record the active diskio driver number instead of the active logic drive(volume) number, is it?

Q2:

So, if we don't link the driver as shown above, so we just need to link the used disko driver one time as follows:

#define _VOLUMES 4 for(int vol=0; vol < _VOLUMES; vol++)  {  FATFS_LinkDriver(&SD_Driver, &SDPath[vol*4]);  }

char 

SDPath[4];

FATFS_LinkDriver(&SD_Driver, SDPath);#define _VOLUMES 4 for(int vol=0; vol < _VOLUMES; vol++)  {  FATFS_LinkDriver(&SD_Driver, &SDPath[vol*4]);  }

char 

SDPath[4];

FATFS_LinkDriver(&SD_Driver, SDPath);

Now I want to know how the SDPath make sense there in the case of the multiple partition, the SDPath there make me think that the logic drive number has the same value with the diskIO driver number.

That's all my confusions, don't make me wrong. I just feel that this function seems make me misunderstanding the mappings of the logic drive and the diskIO driver in the multiple partition case. In this case, the

the mappings of the logic drive and the diskIO driver is decided by the volume management table.

Obviously, By default, that is, just one partition case, this function show  me the clear mappings of the diskIO driver and logic drive, which is also keep the same with the mapping definition in the FatFs document.(pls refer to 

http://elm-chan.org/fsw/ff/doc/filename.html

 Volume Management section).
0 REPLIES 0