Electronic – Some general NAND flash questions

non-volatile-memorystm32

I have some questions about nand memories.

  1. Do we need to erase whole block to rewrite only one page?
  2. If true, what is the algorithm? Cache whole block > edit one page > erase whole block > write whole block?
  3. How random data input works? Do we need erase block to input few bytes in random mode???

p.s. I am writing MSD application with STM32F207ZG mcu + K9F1G08U0B nand

EDIT For newbies like me

How NAND flash works:

We can perform read and write on page basis or use random input or random output in any page. Nothing special about reading, but i hear that reading, like writing, may wear pages.

After erase all bits in erased area is set to 1, and when we write, we only set some bits to 0. Once bit is set to 0, it cannt be set to 1 again, setting bit to 1 is possible only by erasing region containing that bit. As consequence, if we need to fill some region with 0x00, we do not need to erase this region.

And note: Erase can be performed only on block (not page) basis. I found, that when you specify page address to erase, block containing that page will be erased. So we need to specify not a block number to erase, but for example number of first page in block.

Hope this information is correct and will be helpful for someone. Sorry for my broken english 😉

Thanks to supercat for explanation.

Best Answer

If interoperability with other systems is not required, your choice of algorithms will depend upon the resources you have available (most notably RAM) and your usage patterns. If you can get by with block-level granularity, and if no block will have to be rewritten too many times, the simplest approach is to simply map logical pages directly onto fixed physical blocks. Some applications are amenable to such an approach, but others are not. Generally, what is done is to have logical page addresses and keep a table of where each page is presently stored on the chip. When a page should be changed, a new blank location is selected for it, the data is written there, the location table is updated, and the old page is invalidated. If after such operation a block contains many invalid pages and no valid ones, erase it. If the number of blank pages gets low, the system should identify a block which contains many invalid pages and, move the still-valid pages to new locations in other blocks, and invalidate the copies in the old locations; once that is done, the block won't contain any valid pages anymore and may thus be erased.

There are many variations to this approach based upon things like the amount of RAM available for page tables, the amount of time one is willing to spend searching for pages, etc. If the number of pages is too large to keep a full table in memory, it may be necessary to store some of the table in flash. If this is done, it may be helpful to have a virtual mapping between logical block numbers and physical blocks, and have the "cleanup" operation find a new blank block, copy all of the valid pages from the old block to the corresponding pages in the new one, and assign the new block the same logical block number that the old one had. If one does this, one can avoid updating the tables that hold the locations of pages within the block.