Per page flash erase not possible on ATMega?

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

I want avrdude to only erase flash pages that it is about to write to the flash. I found info that supposedly atmega chips only support full flash erase. Is this correct?

 

The reason is that I have a fairly large bit of flash data that I want to burn once and then only flash code section during subsequent testing. It would make it much faster for me to flash only the code section.

LibK - device driver support for flash based microcontrollers: GitHub project

http://oskit.se - join me on my quest to become a better programmer

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

Avrdude defaults to 'erase-first'.

Use -D to disable.    And -e when you want it.

 

Other programming software defaults to 'not-erase'.

 

David.

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

mkschreder wrote:
The reason is that I have a fairly large bit of flash data that I want to burn once and then only flash code section during subsequent testing. It would make it much faster for me to flash only the code section.
No can do.  At least with ISP.  Bootloaders can do a page at a time.

Iluvatar is the better part of Valar.

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

ISP can program one page at a time.     The problem is that you can't erase one page at a time via SPI.

 

So you can write multiple programs in consecutive memory.    But you need to 'skip' over the 'obsolete' pages.

With some CPUs,   0x0000 is a NOP (or otherwise harmless opcode).

 

So you can write 0x0000 all over your obsolete page(s).

A subsequent RESET will slowly execute all the 'NOP's until it gets to your current pages.

 

Quite honestly,    you either install each new program via a bootloader or just remove the bootloader during the Debugging phase.

 

You can make the JTAG debugger 'run' an existing program that you loaded via the bootloader.

However most Atmel tools expect you to erase everything and load a new program via the JTAG/debugWIRE/PDI.

 

It is easier to go with the flow.

 

David.

Last Edited: Wed. Oct 29, 2014 - 08:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

Avrdude defaults to 'erase-first'.

Use -D to disable.    And -e when you want it.

 

Other programming software defaults to 'not-erase'.

 

David.

 

Only problem is it erases all flash. Not erasing does not work because flash has to be set to 0xff before it is written.

 

I will try a bootloader when I have time for it later.

LibK - device driver support for flash based microcontrollers: GitHub project

http://oskit.se - join me on my quest to become a better programmer

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

Quite honestly,    you either install each new program via a bootloader or just remove the bootloader during the Debugging phase.

Well, there are apps and there are apps.  If this is indeed fixed info, then build it into the app?

 

Anyway, if that important then make a utility to read flash, extract the magic portion, combine with the new build into a combined .hex, then do normal ISP with the combined version.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

theusch wrote:

Quite honestly,    you either install each new program via a bootloader or just remove the bootloader during the Debugging phase.

Well, there are apps and there are apps.  If this is indeed fixed info, then build it into the app?

 

Anyway, if that important then make a utility to read flash, extract the magic portion, combine with the new build into a combined .hex, then do normal ISP with the combined version.

 

Well it's not really a problem. I just have bitmap data that does not really change that much, but it adds a lot to the final program size compared to size of the actual code. So I was thinking, that it is quite a waste to flash the bitmap data every time I upload new changes to the code during development (and possibly tears on the flash as well). So I thought it would be neat to just pack the bitmap into a separate section in my program that starts at 0x4000 and flash it once. Then to flash only code section to lower portion of the flash. It works to pack the bitmap into a separate section like that, it's just that if I then only write code afterwards and disable flash erase then code fails to run. And if I supply flash erase flag then the bitmap data disappears. So that's pretty much an explanation for what I was trying to do. It would be neat to just flash code during subsequent uploads and leave bitmap data in tact.

LibK - device driver support for flash based microcontrollers: GitHub project

http://oskit.se - join me on my quest to become a better programmer

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

Well,   install a bootloader.   Use it.   Tell your debugger not to re-program before a debug session.

 

I bet you will find this harder work!     i.e. fighting the IDE tools.

 

David.