2

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.

Bence Kaulics
  • 6,353
  • 12
  • 33
  • 60
user2809652
  • 71
  • 2
  • 8
  • Format of your f_mount call does not seem to correspond to documentation http://www.elm-chan.org/fsw/ff/00index_e.html – Anonymous Jun 06 '17 at 08:06
  • 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. – MathiasE Jun 06 '17 at 09:03

2 Answers2

1

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.

0

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.

Dmitry Grigoryev
  • 25,576
  • 5
  • 45
  • 106
  • Currently i'm using older version of fatfs and that func has only 3 arguments – user2809652 Jun 06 '17 at 12:15
  • @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. – Dmitry Grigoryev Jun 06 '17 at 13:58