2
\$\begingroup\$

I have ported FATFS for Free RTOS on STM32F103 SPI Flash of 32 Mbit. In a demo Application I have successfully created a file, written a file, and read back from the file. My requirement is like I have to store multiple files (images) in SPI flash and read it back when required.

I have the following conditions/queries.

  1. I have set the Sector Size to 512 bytes, and block erase size for SPI flash is 4K. As in the SPI Flash, block needs to be erased before written. Do I need to keep track on whether a particular block is erased or not or its the file System who is managing this?

  2. How can I verify that the sector, which I am writing in erased or not? What I am currently doing is, Erase the Complete Block for the sector, which I am going to write?

  3. How can I make sure, The Block for SPI flash I am going to erase will not affect any Sector containing useful data?

\$\endgroup\$
1
  • \$\begingroup\$ If you can use an SD card instead, there's suitable code to do everything you want on the FreeRTOS interactive site. I appreciate this might not be possible. \$\endgroup\$
    – DiBosco
    Jan 19, 2018 at 14:31

1 Answer 1

2
\$\begingroup\$

FATFS is a bad choice to use directly on a flash chip without any intermediate translation layer, as writing the FAT will overwrite the same sector again and again, causing these cells to wear out quickly.

  1. You cannot reliably determine whether a certain block has been erased. If it reads back as only ones, the chance is fairly high that this is an empty, usable block, but it could also be a block that was in the process of being erased when the power went out, so some of the bits might be unstable. A flash file system should be aware of this, and explicitly mark blocks it has successfully erased with a specific marker.

  2. The only way to be sure is to either perform an erase immediately before, or to have a note somewhere that a certain block has been erased.

  3. You will erase the entire block, which contains 8 sectors. If any of these sectors already contains data, it will be erased as well, which you want to avoid.

As said, FAT is not suitable for use in this way.

\$\endgroup\$
3
  • \$\begingroup\$ It might not be terrible if writes were expected to be rare, and the ability to expose it as USB mass storage (that MCU has USB) may be worth something in some cases. But yes, it is a complicated fit. \$\endgroup\$ Aug 5, 2014 at 15:27
  • \$\begingroup\$ Thanks Simon, Can you suggest any other OpenSource File system for Flash. \$\endgroup\$
    – CAK
    Aug 6, 2014 at 7:22
  • \$\begingroup\$ Wikipedia has a good article on flash file systems. \$\endgroup\$ Aug 6, 2014 at 7:30

Your Answer

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

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