We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am finding conflicting information regarding the use of Flash memory. Some information indicates that all Flash memory is for code only, while other information implys that Flash can be used for code and data both. I get the impression that data storage in Flash is something that can be done on some parts and not others, but can't find any information on manufacturers websites that clarifies the issue. Is there any good information out there that will tell me what is what? I am looking at 8051 based parts - Atmel & Philips mostly. Thanks, Scott Kelley
There's no general answer. Flash stores bits; all else being equal, those could be "data" bits or "program" bits. It's just a question of whether or not that particular memory is wired to respond to the 8051 core's instruction fetch cycle, or data read/write cycles. Either (or both) can work. So, the answer for any specific part has to lie in the manufacturer's data sheet. The Atmel T89C51IC2, for example, says it has 32k flash "program / data memory". They describe some built-in API calls for programming the flash from software. So there's no reason you couldn't use some of that memory for "data" instead of "code"; at worst, you'd have to access it with MOVC instructions instead of MOVX. The Atmel AT89C51, on the other hand, sports 4k of "in system reprogrammable flash memory" -- but if you read further you'll notice that they refer to "every code byte in the flash array", and notice that the programming waveforms all involve the *PSEN (program store enable) signal. So, it looks like to me that this part is only intended to use flash as program store; it says nothing about making the flash visible in the data store address space. I agree that the data sheets can be unclear. (There's always tech support from the maker; serves 'em right if they can't write clear documentation...) Did you have any specific parts in mind?
On the part I'm using (8051F120) there is 256 bytes of scratchpad memory above the CODE memory. This scratchpad is also FLASH memory that I use to read/write configuration data. Since there is a limited number of writes, I don't use it often. I mostly write to it with factory configuration data (ie. serial number of board, date of manufacter, etc.) Don't think there's a limit to the number of times you can read it.
The main reasons Flash is not commonly offered as data is 1) flash can not be simply written, it must be erased before write, 2) flash can not be written at the speed SRAM can, and 3) Flash can only be written a limited number of times before it fails, Some information indicates that all Flash memory is for code only, while other information implys that Flash can be used for code and data both. Data can be stored in any kind of memory, what you are referring to is a) the most common use of flash is for code and b) the fact that chips with internal flash are built to accommodate that. I get the impression that data storage in Flash is something that can be done on some parts and not others, but can't find any information on manufacturers websites that clarifies the issue. As a general rule the only data that can be stored in internal flash by simple means is code and the data you include with your code such as fixed tables. In one of my applications I have 2Mbyte of external flash used for rarely written, often read data. Is there any good information out there that will tell me what is what? I am looking at 8051 based parts - Atmel & Philips mostly. Most chips with internal flash allow you to store rarely written, mostly read data in code flash, you need to use a whole page of flash and use the routines provided for program update. The thing to look for is the chips ability to run code in one page while writing to another page. The way to do this is described in the datasheet as "user defined ISP". Erik
I mostly write to it with factory configuration data (ie. serial number of board, date of manufacter, etc.) Don't think there's a limit to the number of times you can read it. That sounds like a pretty typical use to me. Code updates, configuration parameter storage. As erik noted, flash doesn't have the lifespan to be used as main memory for a running application. But for data that changes less often, it can be useful. Just to expand on some of erik's points: 1) flash can not be simply written, it must be erased before write See the data sheet for your part for details. There's typically a state machine inside the flash looking for a particular sequence of bus cycles to appear before it accepts a value to be programmed. There are two main algorithms, which I think of as "Intel" and "AMD", but there are little variations and extensions from every manufacturer. This is one reason some parts give you routines built into their boot ROM to do the programming for you. It's essentially some BIOS routines to deal with the flash. 2) flash can not be written at the speed SRAM can Quite a bit of understatement here. Even the read access time for typical flash is slower than SRAM (say 80-120ns instead of 10-20ns). But the time to write a value is much longer, say on the order of 10-100 us. And before you can write a value, you generally need to erase the sector containing it, which takes even longer (perhaps hundreds of ms per sector for a large flash device). Check your data sheets. 3) Flash can only be written a limited number of times before it fails It's a bit more accurate to say it can only be "erased" a limited number of times, but that's tantamount to the same thing if you're talking about storing arbitary values. The limits in question are fairly large for the uses I think of as typical. To give an idea of the range, most parts are generally around 100,000 erase cycles. Good parts often guarantee a million erase cycles. Cheap ones are sometimes only 10,000. So if you're talking about code upgrades or configuration updates, there's no worry in practice. If you're talking about a non-volatile file system updated by the code, you have to be a little more careful. And there's no way flash could support general variables in your code, like loop counters or your serial data ring buffer or whatever. Even if the write performance weren't a limitation, the flash would wear out far too quickly. Just for the sake of completeness, note that all these comments apply to "NOR" flash. There's another kind of flash technology, "NAND" flash, which usually has a longer lifespan, erases more quickly, is higher density (for the same price). NAND flash has a number of other limitations, though -- it's accessed sequentially instead of randomly, with a programmed I/O interface instead of appearing as a normal memory device, and NAND parts ship with bad blocks and blocks can fail during use, which means your software has to do some sort of bad block detection and list management to deal with it. NAND flash is usually used for file system type applications, where you've got a layer of file system software to deal with the bad blocks, and the increased capacity and lifespan are important. For direct execution of code, you need the random access properties of NOR flash.
One more important point for flash as data memory. The same block of flash memory CANNOT be written/read/erased while the code stored in the same block is executing. For this reason, most flash memory based 8051 can use the flash as code memory only. One exception is the SST89x5x4 from Silicon Storage Technology. There are two flash memory blocks in the microcontroller. You can use one as code memory and the other for data. So when your code is being executed in one block, it can write data to the other block.
The same block of flash memory CANNOT be written/read/erased while the code stored in the same block is executing. For this reason, most flash memory based 8051 can use the flash as code memory only. HUH? I know of no '51 with internal flash where the flash is one page only. Erik
Atmels 89c51RB2 + 89c51RC2 will have Thomas
Atmels 89c51RB2 + 89c51RC2 will have ! Thomas
I know of no '51 with internal flash where the flash is one page only. The flash block is different from page. A block can be as big as 64KB or as small as 4KB depends on the '51 chip design. The blocks are independent from each other. To write data to the same block, you'll need In System Programming (ISP), and you'll have to make sure that no code is executing in that block during that time. (ATMEL 89c51RB2) To write data to the other block, you'll need In Application Programming (IAP), and the application in this block doesn't have to be halt waiting for the end of the write data operation in the other block. (SST89x5x4)
Oliva stated erroneously: The same block of flash memory CANNOT be written/read/erased while the code stored in the same block is executing. For this reason, most flash memory based 8051 can use the flash as code memory only. My reply may have been wrong in the choice of words, so I will rephrase: I know of no '51 with internal flash where all the flash has to be erased at once. Thus one section can be ersased and written to while the program is running in another section. This makes it possible to use a section as data storage. E. g. the Philips P89C51RD2 has the flash separated in 5 blocks 8k, 8k and 3*16k. Erik
Eric, What I am saying is that The same block of flash memory CANNOT be written/read/erased while the code stored in the same block is executing at the same time. These two actions CANNOT be taken simultaneously. What you said is right that code in one sector and data in another. But if there is only one block (block is not a page or a sector, but contains multiple sectors), the execution of the code has to be halt until the erase and write operation finished, which takes rather long, compare to normal data saving. What's more, the interrupts cannot be responsed during this time. These are the limitations for writing data to the same block. P89C51RD2 you mentioned also has both IAP and ISP. Thanks for the information. As far as I know now, Philips and SST provide '51s that can treat flash as data memory without restriction.
What I am saying is that The same block of flash memory CANNOT be written/read/erased while the code stored in the same block is executing at the same time. I agree, what you said was: For this reason, most flash memory based 8051 can use the flash as code memory only. I strongly disagree, I know of none (except the supersmall) that can not use some of the flash as "data" memory (in " becuse of movc reads). Erik
I think this discussion very interesting. Can anyone tell me if is it possible to save 32bits data the internal flash (Philips P89C51RD+).Since the P89C51RD is 8 bit data microcontroller, how can I save a 32 bit data? is it possible? I am using the assembly routines of IAP system programming.But with that it is only possible to save 8 bit data.I am now triyng to make code in assembly in order to save 32bits data, but its not working. Can someone help me?
"Since the P89C51RD is 8 bit data microcontroller, how can I save a 32 bit data?" The same way you do anything with 32-bit (or 16-bit) data on an 8051: you have to handle it as 4 (or 2) separate bytes. This has nothing whatsoever to do with the data being in Flash!