I want to use FatFS library using STM32F303 internal flash memory. I created user_diskio.c file and described necessary functions USER_write
, USER_read
and USER_ioctl
for reading and writing data to/from internal flash
if (FATFS_LinkDriver(&USER_Driver, USER_Path) == 0)
{
result = f_mount(&FATFS_Obj,(TCHAR const*)USER_Path, 1);
...
}
f_mount gets FR_NO_FILESYSTEM error. Using function f_mkfs((TCHAR const*)USER_Path, 0, 512);
gets FR_NOT_ENABLED
error. I don't understand, how should I format disk sector to use FatFS library.
Best Answer
That's not going to work very well. I would recommend that you reconsider.
FatFS expects to be working with a block device where it's possible to write any 512-byte sector of the disk at any time. This is not how flash memory works on STM32 devices -- on the STM32F3 series, flash memory is organized as a set of 2 KB sectors (not the 512-byte sectors assumed by FAT!), each of which can only be written to as part of a program/erase cycle.
Writing to a single 512-byte subsector of the 2 KB flash sector will require an expensive, slow operation where you erase the entire flash sector, then re-write it with one sector modified. This will wear the flash memory very quickly, resulting in premature failure of the device.
That all being said, based on the FatFS code I looked at,
FR_NOT_ENABLED
does not appear to be a valid return value fromf_mkfs()
. Either you've read the error code wrong, or you're running into a bug in the version of FatFS you're using.