please help me understand this. When I compile a program and get HEX file, which I can later load via ISP programmer, does this HEX file contain bootloader as well as core code and my app code? For example, if I compile same program while IDE is set to Uno, HEX file is 16k size, but if set to Leonardo/Micro, HEX file comes out as 20k. Does this 4k difference account for different bootloaders or different chip core code? Can I program HEX file directly via ISP into blank AVR chip and it will get bootloader as well as my code?
Also, why are bootloader files in hardware\arduino\bootloaders\caterina so big, 76k in size?
I just recently started using Leonardo because I need integrated USB Serial port, but my finished project does not need a bootloader , only my code and USB Serial support, so I am trying to understand, is USB code part of core, which would be compiled in the HEX file , or is it part of bootloader? If I flash HEX file via ISP, will it have USB Serial support with or without bootloader?
There is a also a fuse bit which controls bootloader execution, but I can't find documentation for it in Atmega32u4 PDF. Maybe I can just set this bit so my code always runs without bootloader?
The hex file generated is just your code. So when you upload it via ISP, you are actually getting rid of the bootloader that's on the chip. This will cause your sketch to start running immediately when the chip is first powered up, as opposed to going through a bootloader first which would take a second or two depending on the hardware used.
When you upload a sketch through the Arduino IDE (by hitting 'Upload' as opposed to 'Upload Using Programmer'), it's only uploading the sketch code, and puts it after the bootloader already on the chip.
You CAN upload a sketch without needing a bootloader on the chip, and it will run just fine.
"does this HEX file contain bootloader as well as core code and my app code?"
No. If you load it via ICSP (FIle:Upload Using Programmer) it overwrites the bootloader.
Leonardo also includes code for the USB interface, with Uno that code is on a different chip.
"If I flash HEX file via ISP, will it have USB Serial support with or without bootloader?"
Good question.
Fuse - see 28.2, Table 28.3:
HWBE 3 Hardware Boot Enable
and Table 28.4:
BOOTSZ1 2
Select Boot Size (see Table 28-7
for details)
0 (programmed)(2)
BOOTSZ0 1
Select Boot Size (see Table 28-7
for details)
0 (programmed)(2)
BOOTRST 0
Select Bootloader Address as
Reset Vector
1 (unprogrammed, Reset
vector @0x0000)
76K file size, I don't know.
Hex file will have address, databytes, checksum, all add to file size, but do not wind up in the chip.
Thank you both for prompt responses. I don't know how I missed fuse section in the manual
I just tested and confirmed that USB Serial is part of core code, which is part of HEX file and not related to bootloader.
I flashed HEX file, which of course killed bootloader, and I also cleared BOOTRST fuse, so bootloader would not even run if it was present.
My code is running happily and USB serial is working just fine.