AnsweredAssumed Answered

Multiple nandflash access

Question asked by arnogir on Aug 22, 2018
Latest reply on Aug 29, 2018 by arnogir



I'm using MQX 4.1 on K70 with an external Nandflash linked to the NFC.

I installed the MFS then the nandflash is seen like a disk on letter "a:"


Then I read/write some files on this until:


MyFileHandler = fopen("a:\\", r+), read(), write, fclose(MyFileHandler ).


I have some questions about this, because sometime during the life of the product, some files are corrupted with bad value. So I try to found possible source of this problem.


1- My code is protected against multiple access on the same file. If a task access to a file, before open file, I call:


Then after close file I call _lswem_post(MyFileSemaphore).


But I'm not protected against other file access.

Is a task can access to a file (read/write), be interrupted by higher priority task in which an access to an other file is done?

I don't know how the MFS manage this, but in exemple, on other project, I managed an external SPI flash. This is some simple access to a read/write instructions. To write, I send the command write, then the address and then all the bytes to be written from the given address. If I interrupted during transmission of the Data bytes, an other task can access to the flash, start a new dial by give another address and write data byte. So when I back into the original task, the write continue but not on the desired address! Then I protect against multiple access. Is similar with the Nandflash on the NFC with MQX and MFS?




2-  For a big file, I must call fflush on the system nandflash after fclose(MyFileHandler ). But I think I must also (or only?) call a flush on the file before close it : fflush(MyFileHandler ). What is your opinion?


3 - Is there need some delay after Open / Read / Write /(Flush) / Close operation? and/or Flush Nandflash ?


4- What happen if Power become off during a open/ Read/Write / flush/close? Is file could be corrupted or the integrity is keeped?


5- By looking for in this forum, I find the following method. This could be fine in my case? This could say the call to fflush is not necessary?

ioctl ( fat_handle, IO_IOCTL_DEFAULT_FORMAT, NULL );
_io_ioctl ( fat_handle, IO_IOCTL_SET_FAT_CACHE_MODE, &cache_mode );
_io_ioctl ( fat_handle, IO_IOCTL_SET_WRITE_CACHE_MODE, &cache_mode );
_io_ioctl ( fat_handle, IO_IOCTL_FAT_CACHE_OFF, NULL );


Thank for your back, this is very critical for our project.