Hi guys, I'm new to the forum and quite new to the ATMEL MCUs world anyway I have some basis on C and ASM languages. I have some Arduino UNO board and also some standalone ATMEGA328P-PU chips so, in order to learn these a bit deeper, I'm studying the datasheet and the Optiboot too.
I have a question about the Optiboot assumption that "SP points to RAMEND": in the datasheet I can read:
- the SP must be initialized by the user program "in the Reset routine (before subroutines or interrupts are executed)"
- if the high fuse BOOTRST bit is programmed then the Reset vector points to the start of the bootloader flash section and, as far as I know, this is the case for the UNO board with the Optiboot installed, correct?
Now, if all above is correct, this tells me that the very 1st code running after a MCU reset is the Optiboot code so: could anybody please explain how the Optiboot can safely assume that "SP points to RAMEND"? When and where does it assume the SP is initialized to RAMEND?
By the way, in the Optiboot code I can see instruction:
#ifdef __AVR_ATmega8__ SP=RAMEND; // This is done by hardware reset #endif
which initializes the SP but as I can see in the .lst file (disassembled code) this is not considered for the ATMEGA328P..
Thanks very much in advance for the explanation.