I have written the following code to perform a copy procedure between RAM and FLASH Memory: unsigned char i; i = 0x00; do{ i --; *(&FLASHADDRESS + j + i) = DataBuffer[i]; }while(i != 0x00); Is there any better way to generate efficient(like DJNZ in assembler) code? :) THS.
Interesting. The interface for this part is a little unusual. Atmel generally sells flash with what I think of as "AMD-style" commands. It's not a standard, unfortunately, but a lot of manufacturers use something similar. The 55/AA/A0 sequence is usually the command to program a single word. For this part, they require you to program an entire 256-byte sector. It's a little more common to see an different sequence for a burst programming mode. See the 55/AA/80 55/AA/A0 command sequence for the Atmel AT49SV322, for example. I've found the single-word program command to be consistent on different parts from different manufacturers. The more advanced features, including burst-mode programming, tend to vary a bit more. Most flash devices have sector sizes larger than 256 bytes, as well. Those that do support small sector sizes seem more likely to have an internal RAM buffer to support this sort of burst mode programming. Using the advanced features often means getting trapped using a particular device, or a lot more software work to make a smart driver than can cope with many slightly different interfaces. At any rate, the burst mode methods do usually have a timeout between successive writes, so that they know when the processor is done with the sequence. This is the 150 us timeout after each write. That series of writes would be followed by the 10 ms delay (Twc) to allow the write actually to complete. The toggle bit or data polling algorithm lets you know when the flash is actually done updating. (You could just wait the worst-case 10 ms time instead.) The write isn't really complete until that algorithm is finished.