I separated this question from a previous post: why is arduino micro bootloader so big?
Caterina-Micro.hex is 76KB. That is like 32KB of code. The Caterina lilypad USB is only 4KB with 12KB HEX file size. This is what I expected:
It says 4K is used by bootloader.
I took a look at the Caterina-Micro.hex. It does have 4KB in the end, 4,832 bytes in the beginning and just empty space in between, making up 32KB of program space. So what is the purpose of the first 4,832 bytes? Is the bootloader area not large enough so it spills over to this memory location? I read the relevant info from boards.txt Yet the boards files says max sketch size is 28K. So I expect if I upload a new code, then the first 4832 bytes get replaced. Then why are those 4832 bytes doing there?
The Micro needs to have two different USB codes running. One for the bootloader and one for the sketch. That first 4832 bytes is a preloaded sketch that has USB base code so it will be recognized by the computer when the bootloader is not running. It has code to recognize when the baud rate is set to 1200 to initiate the bootloader USB code.
Thanks for explaining to me. So if I upload a sketch, does the sketch overwrite the first 4832 bytes with exactly the same content and then the user code since every sketch needs the first 4832 bytes?
Basically the upper limit for user code is about 32K-4K-4.7K, correct?
When you upload your own sketch, part of it includes the USB core files. So if you compare the compiled sketch sizes vs. Uno compiles sizes you will see it is about 4K bigger. It will not necessarily be the first 4832 bytes. It will be where ever the linker puts it within your compiled code. But true, the actual sketch size available is closer to 24K, because 4K is being used by the USB core files.