EmbeddedRelated.com
Forums

About flash memory

Started by VG December 21, 2010
One of the boards I am working on has a 16-bit STMicro NOR flash.
According to the datasheet, four cycles are required to program the
flash through software.

1) 0x555 = 0xAA
2) 0x2AA = 0x55
3) 0x555 = 0xA0
4) actual address = actual data

My questions are:

a) In 1), 2) and 3) above, does the flash's internal mechanism
actually write the given data bytes at the given locations, for
example, 0xAA at the location 0x555 which happens to be in the first
sector? If the board loses its power before 4) is done, then will 0xAA/
0x55/0xA0 be there in the flash if I read its contents using a
hardware tool?

b) What would happen, if, say, immediately after 1) or 2) or 3) above,
the RTOS task that wanted to (raw) write to a sector is preempted (due
to some bad coding) by another task that invokes some file I/O
routines to access the flash file system layered on top of other
sectors?

Any link that explains the flash internal workings would really be
helpful. Thanks.
>One of the boards I am working on has a 16-bit STMicro NOR flash. >According to the datasheet, four cycles are required to program the >flash through software. > >1) 0x555 = 0xAA >2) 0x2AA = 0x55 >3) 0x555 = 0xA0 >4) actual address = actual data > >My questions are: > >a) In 1), 2) and 3) above, does the flash's internal mechanism >actually write the given data bytes at the given locations, for >example, 0xAA at the location 0x555 which happens to be in the first >sector? If the board loses its power before 4) is done, then will 0xAA/ >0x55/0xA0 be there in the flash if I read its contents using a >hardware tool?
The first 3 writes are to the Command Registers in the On-Chip Controller, and tell it that the 4th write is the actual write address/data pair.
> >b) What would happen, if, say, immediately after 1) or 2) or 3) above, >the RTOS task that wanted to (raw) write to a sector is preempted (due >to some bad coding) by another task that invokes some file I/O >routines to access the flash file system layered on top of other >sectors?
You must ensure that the 4-write sequence is "atomic", and cannot be pre-empted.
> >Any link that explains the flash internal workings would really be >helpful. Thanks. >
Read The Fine Data Sheet. HTH! --------------------------------------- Posted through http://www.EmbeddedRelated.com
On Tue, 21 Dec 2010 02:20:28 -0800, VG wrote:

> One of the boards I am working on has a 16-bit STMicro NOR flash. > According to the datasheet, four cycles are required to program the > flash through software. > > 1) 0x555 = 0xAA > 2) 0x2AA = 0x55 > 3) 0x555 = 0xA0 > 4) actual address = actual data > > My questions are: > > a) In 1), 2) and 3) above, does the flash's internal mechanism actually > write the given data bytes at the given locations, for example, 0xAA at > the location 0x555 which happens to be in the first sector? If the board > loses its power before 4) is done, then will 0xAA/ 0x55/0xA0 be there in > the flash if I read its contents using a hardware tool?
No, the AA/55/A0 will never be programmed. If you lose power just after you write at 4), the data itself may be partially written.
> b) What would happen, if, say, immediately after 1) or 2) or 3) above, > the RTOS task that wanted to (raw) write to a sector is preempted (due > to some bad coding) by another task that invokes some file I/O routines > to access the flash file system layered on top of other sectors?
Make sure that doesn't happen. Also, don't run code from that flash (some devices excepted in certain circumstances)
On Tue, 21 Dec 2010 02:20:28 -0800, VG scribbled:

> One of the boards I am working on has a 16-bit STMicro NOR flash. > According to the datasheet, four cycles are required to program the > flash through software. > > 1) 0x555 = 0xAA > 2) 0x2AA = 0x55 > 3) 0x555 = 0xA0 > 4) actual address = actual data > > My questions are: > > a) In 1), 2) and 3) above, does the flash's internal mechanism actually > write the given data bytes at the given locations, for example, 0xAA at > the location 0x555 which happens to be in the first sector? If the board > loses its power before 4) is done, then will 0xAA/ 0x55/0xA0 be there in > the flash if I read its contents using a hardware tool? > > b) What would happen, if, say, immediately after 1) or 2) or 3) above, > the RTOS task that wanted to (raw) write to a sector is preempted (due > to some bad coding) by another task that invokes some file I/O routines > to access the flash file system layered on top of other sectors? > > Any link that explains the flash internal workings would really be > helpful. Thanks.
(a) has already been answered, for (b) ... flash is like a coke machine, do EXACTLY what it says and you'll get a coke. Deviate in the slightest and ... nothing. That is to say, if you have a stray write, or read, to flash before steps 1 - 3 complete then the fourth write will fail. If 1 - 3 complete then the fourth write is a write whether from the desired or interrupting task; and if 1 - 3 complete and there's a read then the fourth (now fifth access) will silently fail. flash is dumb, really dumb. --
>@<
Bill Dennen ieee1014@hotmail.com Of all the things I miss, I miss my mind the most ...