About MFS on K21 Flashx memory

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

About MFS on K21 Flashx memory

Jump to solution
755 Views
rahulhirve
Contributor II

Hi All,

 

I am trying to implement MFS on flashx memory, attached is my code.

I am able to write file and if I search for files in MFS it return me the file details.

 

But when I read the file it returns me 0 bytes in file and I am not able to read file.

 

Can anyone please suggest me the corrections I need to do.

 

Thanks and Regards,

Rahul

Original Attachment has been moved to: mfs_demo.c.zip

0 Kudos
1 Solution
487 Views
RadekS
NXP Employee
NXP Employee

Hi Rahul,

I tested your code at my TWR-K21F120M board.

  1. I never meet branch with disk format. Therefore I just simply copy this code prior write into the file.
  2. FLASH_IOCTL_WRITE_PROTECT is FlashX ioctl command, therefore I suppose, that you should use flashHandle instead of filesysHandle for such command. However I suppose, that you don't need it in this case at all.
  3. The most important point is that seek function doesn’t return size of file (just OK or error). Please use this fix in your code:

fseek(filePtr, 0, IO_SEEK_END);

i = ftell(filePtr);

fseek(filePtr, 0, IO_SEEK_SET);

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
3 Replies
487 Views
RadekS
NXP Employee
NXP Employee

BTW: The MFS is not intended to be used on a flash memory without a wear leveling layer (as FAT table is frequently updated, the internal flash could wear out due to too many Program/Erase cycles).

If you use MFS mainly for read and your application writes to MFS only seldom, you can forget on wear leveling. But if your application updates MFS frequently you will need wear leveling layer in software. You will need to develop a software, which sits between MFS and flashx driver and which spreads the program/erase load of the internal flash sectors equally. (By the way, common use case of MFS on SD card employs wear leveling algorithms inside the SD card itself)...

0 Kudos
487 Views
rahulhirve
Contributor II

Hi Radek,

Thanks for your reply, yes this is correct I could able to do that with little debugging and was about to post my comment  :-). I am aware of wear leveling issue, but as my system needs one time write and then read only so I guess this should be fine.

Thanks,

Rahul

0 Kudos
488 Views
RadekS
NXP Employee
NXP Employee

Hi Rahul,

I tested your code at my TWR-K21F120M board.

  1. I never meet branch with disk format. Therefore I just simply copy this code prior write into the file.
  2. FLASH_IOCTL_WRITE_PROTECT is FlashX ioctl command, therefore I suppose, that you should use flashHandle instead of filesysHandle for such command. However I suppose, that you don't need it in this case at all.
  3. The most important point is that seek function doesn’t return size of file (just OK or error). Please use this fix in your code:

fseek(filePtr, 0, IO_SEEK_END);

i = ftell(filePtr);

fseek(filePtr, 0, IO_SEEK_SET);

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos