I realized that on the atmega boards the bootloader is programmed into the chip.
I'm curious, when compiling a sketch how does the compiler/assembler differ from compiling a standard C program for a chip without a bootloader?
Is there still a main? Does the linker put the startup code in a different area? Obviously with the bootloader you're no longer compiling a program which places code at the reset address.
-
1stackoverflow.com/questions/919781/…jsotola– jsotola2023年02月24日 05:56:31 +00:00Commented Feb 24, 2023 at 5:56
1 Answer 1
On the Uno and similar AVR-based boards, the compiler and assembler are
not aware of the bootloader. The compiled program starts at address
zero. There you have the interrupt vector table, starting with the reset
vector. That vector is a jump to the C runtime startup code, which does
some low-level initialization, then calls main()
from the Arduino core
library, which calls setup()
and loop()
from your sketch.
The bootloader lives at the end of the flash. The AVR chip has a few bytes of non-volatile configuration memory called "fuses". These bytes are configured by the Arduino board maker to dedicate the last 512 bytes of flash to the bootloader, and to start executing the code at the start of the bootloader on power up and on reset events. It is then the bootloader's responsibility to jump to address zero in order to start the user's program.
-
So I can write standard programs with avr studio and not change anything and have them loaded?FourierFlux– FourierFlux2023年02月24日 13:51:21 +00:00Commented Feb 24, 2023 at 13:51
-
@FourierFlux: I have never used AVR Studio, but I do occasionally write regular AVR programs using avr-libc, compile them with avr-gcc, and upload them to an Uno using avrdude.Edgar Bonet– Edgar Bonet2023年02月24日 13:58:08 +00:00Commented Feb 24, 2023 at 13:58
-
Ok but the point is you just compile a standard C program.FourierFlux– FourierFlux2023年02月24日 14:22:07 +00:00Commented Feb 24, 2023 at 14:22
-
warning for future readers. the answer really only applies to AVR architecture. it doesn't carry over to other architectures2023年02月25日 07:08:15 +00:00Commented Feb 25, 2023 at 7:08
Explore related questions
See similar questions with these tags.