Flash Memory in Embedded Systems
A trivial mistake that lots of beginners in embedded systems do when they get introduced to Flash and EEPROM is they grab their all mighty pointer and starts trying to write data directly to the Flash and then suddenly discovers that there is nothing happening at all! the data is not written and after a few research they will find out a couple of interesting information about Flash memory technology which are as follows :
Flash must be erased before they are written, Flash must be erased in Blocks or multiple of Blocks ,Flash must be written in pages or multiple of pages.
So of course what will come to your mind so why the hell this thing is not working like RAM and why there is all this limitations? In the following lines I will answer the above questions so you could know what is going on under the hood when you are working with your flash memory.
1-How Flash memory stores and erases data?
Flash memory consists of memory cells where each cell can store one Bit and an array of those cells Represents the data in our memory. Those cells are made of MOSFET transistors which consists of three terminals Gate, Drain ,Source where in our case the MOSFET has an additional gate called the floating gate this gate is the one responsible for storing the data in the cell as follows, When a Positive voltage is applied between the Gate and the Drain (Word line and bit-line) electrons will from source to drain in high intensity and during that process many electrons will jump and stuck in the floating gate causing it to store electrons ! in what is knows as hot-electron injection. The electrons stuck in the floating gate will stay there for very long time until an external force remove them and so you have now stored your data!! .To Erase the memory cell a negative voltage is applied to the word line leading to the repulsion between the negative charges in the gate and the stored electrons in the floating gate so the electron is removed in what is known as Quantum tunneling now you have erased your data!!.the presence of the electrons is sensed and interpreted as a logical zero (Binary 0) and the absence of them is interpreted as logical one( Binary 1).
So now you see we have to erase the memory cells first to remove the electrons in order to be able to re-program them again. for example to store 0xF0 we will need eight memory cells as follows (11110000) to store number 0x0F the cells will have to be as follows (00001111) for this to happen cells have to be erased first so all is free of electrons and seen as (11111111)(0xFF) and then the cells we want to program is applied to the certain voltage that will allow electrons to pass and so the cells will change to (00001111)(0x0F).If erase didn't happen the result will be as follows (00000000)(0x00)which is a mix of the two words and so the data is corrupted!!.
领英推荐
2-Why flash must be erased in sectors and written in pages?
Flash memory uses in-circuit wiring to apply the electric field either to the entire chip or to predetermined sections known as sectors. This erases the targeted area of the chip, which can then be rewritten and since erasing is a long process erasing a number of sectors at a time is faster than erasing byte by byte so for the need of speed flash is erased sector by sector and not byte by byte and so the writing operation after the erasing can be done faster.
Embedded Software Engineer Diagnostics, Bootloader, UDS-ISO-14229. Automotive field
3 年After reading I can sum up writing to the flash only changes bits to 0s, erasing changing bits to 1s so to write we have to erase the bits to change every bit to 1 then make the 0s by writing ??