I use a structure to communicate between my application and the bootloader. I won't go into all the reasons why they need to communicate but one reason is so that the application can notify the bootloader that he wants to be replaced by a new firmware image (which will be loaded across the CAN bus).
In both the bootloader and application I currently define the area thus:
__attribute__((address(RAMEND-sizeof(BootInterface_t)))) char __stack; #define BootInterface (*(BootInterface_t*) &__stack)
and access it thus:
// // Initialize values used by the application // BootInterface.Contents.mcucsr = Saved_MCUSR; BootInterface.Contents.RestartWasForced = false; BootInterface_SetRestartInfo( RM_Processor, RC_PowerOn_Init, 0 );
This works fine for the purpose. On an ATMega1284p the structure gets allocated at 0x40ED (the size of the struct is 19 [0x13] bytes).
This seems like a bit of a kludge and there must be a better way to locate a struct at the top of RAM and locate the stack just below it.
The other problem is that the debugger apparently can't figure out the symbol linkage so I don't have symbolic access to it (debugger says "BootInterface" is unknown).
I tried this awhile ago but it didn't work (I forget the exact reasons):
BootInterface_t BootInterface __attribute__((address(RAMEND-sizeof(BootInterface_t))));
Thanks in advance ....