cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with FATFS and copy between Ramdisk(FMC) and SD(SPI) on STM32F4

Digimorf
Associate III
Posted on September 28, 2017 at 00:36

Hello,

I am trying to solve this problem. I am using FATFS13 on my custom STM32F469 board and I am using the Standard Peripheral library.

I have connected 1MB of SRAM over the FMC bus, and an SD card over the SPI bus. I can mount on both hardware a FAT file system, FAT12 on the RAM and FAT32 on the SD. I tested SD cards up to 32GB so I can say that everything is working. It's possible to manage files on each volume. I named them RAMDISK and SDCARD in the ffconf.h

Basically, I want two drives so that the user can copy graphics files in the SRAM for a faster access during the execution of programs.

The problem is that when I try to copy a file from one drive to the other, it's copied only the first chunk of data. A single cycle: - read from

- read from source

- copy to dest - read from

- read from source -> Error 9 on the source ((9) The file/directory object is invalid).

I tried to dig into the code, and with the debugger, I noticed that after the write to the destination file when it's time to read the second chunk of data, the 'obj->fs->fs_type' of the source file is set to 0. So the validation fails.

I can't figure out why. Did you have a similar experience?

In order to avoid this error I need to have only one file opened a time, so I temporary solved the problem with this sequence: - open source - read

- open source - read

- read chunck of data at offset - close source -

- close source -

- open destination for append - save a chunk of data - close destination.

- save a chunk of data - close destination.

- close destination.

In your experience is there a particular way to perform a correct copy on different volumes?

Thank you.

#spi #fatfs #fmc #ram #stm32f469
5 REPLIES 5
Posted on September 28, 2017 at 02:21

I just built a cache and implemented at the diskio.c level....

You'd need to make sure you have two instances of the FATFS structure, and _VOLUMES (FF_VOLUMES R.013) set to two

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Digimorf
Associate III
Posted on September 28, 2017 at 10:06

Hi Clive,  thanks for your answer.  Currently I have an array that stores the two FATFS structures. And I have set the number of volumes to 2. There isn't any over writing. 

What about the cache?  How do you use it? 

Thanks 

Digimorf
Associate III
Posted on September 28, 2017 at 11:22

Uhm, that is correct, 8.3 names were allowed only. And now I am thinking if there is a conflict between the two file systems. The USE_LFN definition should be global but I am not sure if the library switches if one file system doesn't support it. What I noticed is that files are correctly created in the Ramdisk with a long name, even if the FAT12 isn't supposed to do that. The name should be modified somehow to the 8.3 format...

I will do some tests... thank you for the memory

🙂

Posted on September 28, 2017 at 10:15

If memory serves me, Fat12 allowed 8.3 file/directory names only.

I was fortunate to not have a 'compatible' PC when this FS was en vogue.

Digimorf
Associate III
Posted on September 28, 2017 at 23:30

Probably I understood the problem...

Originally I put the two file systems FATFS into an array. Since I have two drives I declared:

FATFS FileSystems[FF_VOLUMES];

Instead, I tried to declare two different structures like:

FATFS FileSystemSD;

FATFS FileSystemRAM;

Everything worked perfectly. The copy between the two volumes is OK now.

So If I use those structures inside an array, somehow, somewhere, data are messed up if we access to files on different volumes at once.

I checked the indexes in the code but I didn't notice anything wrong.

So for now I can't figure out what is going on, I will do more tests but this solved the problem.