I have a question, When I upload a sketch from the Arduino IDE does it erase the flash memory ( except the bootloader part ) then it writes or it just erases the space it needs.
lets assume that my application starts at 0x0000 to 0x0F6E and the bootloader starts at 0x7000 to end
when uploading a new sketch, does the whole flash memory starting from 0x0000 to 0x6FFF gets erased or
only 0X0000 to 0x0F6E is erased ?
I'm suspecting it erases the whole thing, if that is true is there away to make it not to erase everything in the flash memory, and only erases the required space for application (0x0000 to 0x0F6E) ?
Which chip or board specifically?
ATmega328P has EESAVE bit in high fuse byte (same 2560). The EEPROM is preserved during chip erase if EESAVE is programmed.
bemin:
I have a question, When I upload a sketch from the Arduino IDE does it erase the flash memory ( except the bootloader part ) then it writes or it just erases the space it needs.
You mention "bootloader" so the assumption is that you are using a bootloader.
I cannot find any mention of the board (which bootloader). That matters.
If you are using Optiboot then...
• Each page is erased then written.
• Trailing "blank" pages are correctly erased then written. The full image from the HEX file is written.
• No other part of Flash is touched.
• The bootloader does not support writing to EEPROM. Whatever was in it before will be in it after.