Is loading arduino sketch erases all the flash memory?

HI guys,

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) ?

What are you aiming to achieve ?

I need a space other than the Bootloader space to be write protected

I suspect it only erases the pages it writes - quicker that way. One way to check of course, test it

bemin:
I need a space other than the Bootloader space to be write protected

The EEPROM is.

Deva_Rishi:
The EEPROM is.

No the EEPROM is not protected when you upload a new sketch!

bemin:
No the EEPROM is not protected when you upload a new sketch!

Are you saying that it is possible to upload data to EEPROM using the IDE upload process, or something else ?

bemin:
No the EEPROM is not protected when you upload a new sketch!

I write to the EEPROM with a Calibration sketch for my TFT-touch and then access the stored values after uploading another sketch

No the EEPROM is not protected when you upload a new sketch!

When I upload a sketch from the Arduino IDE

If you are uploading a sketch with ISP, there are fuse settings which can preserve or erase the eeprom.

Those fuse settings do not apply when using a USB upload with the ide and bootloader. The eeprom settings are preserved.

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:
No the EEPROM is not protected when you upload a new sketch!

Ordinarily it is.

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.