Can flash be written during run-time on Atmega328?

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My understanding is that flash can only be written during compilation time and not run time. But I would like to try my luck and ask the experts here if this can be done anyway on Atmega328.

Thank you for your help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is a badly posed question I think.
You cannot write flash during compilation time as both operations are performed on different hardware.
Of course you can write flash during run-time, that is why SPM was invented.

No RSTDISBL, no fun!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brutte wrote:
That is a badly posed question I think.
You cannot write flash during compilation time as both operations are performed on different hardware.
Of course you can write flash during run-time, that is why SPM was invented.

You are right. The question is badly posed. What I mean is whether the built-in flash inside Atmega328 can be used as a form of storage during run-time.

Based on the link below, it does not seem possible. Is this correct?
http://playground.arduino.cc/Lea...

Extracted from link:
Note: Flash (PROGMEM) memory can only be populated at program burn time. You can’t change the values in the flash after the program has started running.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Of course you can write flash during run-time, that is why SPM was invented.

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
The question is badly posed. What I mean is whether the built-in flash inside Atmega328 can be used as a form of storage during run-time.
Can it be? Yes. Should it be? No. Flash is intended for storing the program and constant data. While it is possible to write to flash from within a program, it is not something you want to be doing to store active data at run time. If it is a small amount of data space you need, use the eeprom on the chip. If you need more than than, then hook up an external memory card.
Quote:
Based on the link below, it does not seem possible. Is this correct?
Don't believe everything you read on the internet.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Flash CAN be written while code is running! Should it be? Generally, no, but that is exactly how a bootloader works.

There are some things you need to pay attention to, to do it. One is that the spm instruction will run ONLY if executed from bootloader section of flash. Thus, you would need to construct a function of some sort that is designed so that the toolchain will place it in the bootloader section. One thing that the function ought to do is allow writing only to a predetermined "safe" region of flash so that it does not accidentally over-write code.

You also need to know that writing to flash is relatively slow and is subject to wear-out. For the Mega328, that is 10,000 write cycles as opposed to 100,000 writes for EEPROM.

What you read is totally wrong, as written. You COULD have verified whether or not it is correct by referring to the specification sheet.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How much data? How often are the writes?

(SD/MMC is a very common choice for runtime data storage, it's very easy to use).