Mega 2560 - compiler reported flash usage

Hi,

Hopefully a simple question.
When compiling on the Arduino IDE, and the compiler ends its messages with the estimated Flash and RAM used by the program. Does this take into account a bootloader at all, or is this assuming a blank processor?

Using an Arduino Mega, I had it reporting 96% full, 245832 bytes. Compiled fine, but would not download the hex fine and resulted in a verification error.
Commented out some code, compiled at 245004 bytes, still 96%, and that hex loaded in fine.

The only thing I can assume is the bootloader is not taken into consideration - which is fine.

Is that what this could be?

Thanks

Yes, this accounts for the bootloader. If you look closely at the message:

Sketch uses 656 bytes (0%) of program storage space. Maximum is 253952 bytes.

253952 B / 1024 kB/B = 248 kB program storage space allocated by message
256 kB - 248 kB = 8 kB boot section reserved for bootloader

Note that if you don't want such a bloated bootloader you can easily install optiboot on your Mega via MegaCore:

which fits in the minimum 1 kB boot section, freeing up 7 kB of flash.

I get this currently.

Sketch uses 244,844 bytes (96%) of program storage space. Maximum is 253,952 bytes.
Global variables use 6,581 bytes (80%) of dynamic memory, leaving 1,611 bytes for local variables. Maximum is 8,192 bytes.

This compiles and loads.

but go to 245832 and it didnt. That should still be 8120byte off... hmm

Thanks for the idea about MegaCore. I will look into that.

That is strange. I've never gotten that close to filling up the ATmega2560. The only thing that comes to my mind is that maybe the fuses aren't set correctly on your microcontroller. If you have a programmer or can set up an Arduino as ISP easily you could try doing a Tools > Burn Bootloader on your Mega, which will make sure that the fuses are as expected.

It already running the stock bootloader. Thats what has me so confused.

Unless you have checked the fuses or set them yourself you can never be sure what they are set to. The easiest way to set them to a known state is via Tools > Burn Bootloader.

Sorry thats what I mean I have already done. Its running bootloader compiled from stk500boot.c