2
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Format of your f_mount call does not seem to correspond to documentation elm-chan.org/fsw/ff/00index_e.html \$\endgroup\$
    – Anonymous
    Commented Jun 6, 2017 at 8:06
  • \$\begingroup\$ I would recommend stepping in the code to find the actual function calls that the FatFS lib is making towards your implementation file. Either your parameters to the f_mount function call are not correct or the functions in your diskio.c file is not correctly implemented. \$\endgroup\$
    – MathiasE
    Commented Jun 6, 2017 at 9:03

2 Answers 2

1
\$\begingroup\$

I want to use FatFS library using STM32F303 internal flash memory.

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 from f_mkfs(). Either you've read the error code wrong, or you're running into a bug in the version of FatFS you're using.

\$\endgroup\$
0
\$\begingroup\$

You should format your flash as FAT32 or exFAT. Since your flash is internal to the MCU, you'll have to get that f_mkfs call right (otherwise you could have formatted it externally).

Right now it seems to have the wrong argument count (refer to this example) and FR_NOT_ENABLED is not a valid return code for this function anyway, so you're probably not even calling it in your code.

\$\endgroup\$
2
  • \$\begingroup\$ Currently i'm using older version of fatfs and that func has only 3 arguments \$\endgroup\$ Commented Jun 6, 2017 at 12:15
  • \$\begingroup\$ @Igor1488 First, good luck getting help with the library version you didn't even bother to specify. Second, when you're struggling getting a lib working, the first thing to try is to upgrade to the current stable release: this will solve a whole bunch of bugs and dramatically increase the relevance of whatever guidance you may get. \$\endgroup\$ Commented Jun 6, 2017 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.