I have a project where I need a global variable to not be erased after the bootloader calls _Startup(). I have noticed in my *.map file that not all sections of RAM are erased and I'm not sure how these values that are used for erasing RAM are created. I don't feel comfortable just placing this 1 byte variable in a section that is currently not erased because I'm afraid future development might cause the variable to be erased later. Is there some sort of keyword or parameter I can give this variable to assure it is not re-initialized after the bootloader runs?
I'm using CW 5.9.0
Thanks for any suggestions!
Solved! Go to Solution.
Hi Marshall:
Thanks for clarifying.
That sounds like a good workaround for me, but have you tried actually leaving that section uncommented and removing those bytes from your ram section? Or even easier, leave it commented as a "signal" just like you mention and take out those bytes from the ram section in PRM. This way the variable will never be overwritten.
The normal approach is to place reserved variables at the end of your ram (or flash) and tell the linker not to use that space.
Regards!
Jorge Gonzalez
Hello Marshall:
What is the target MCU you are using?
I do not fully understand your purpose. Do you want to maintain a variable in RAM with the same value between bootloader and application?
This kind of behavior is sometimes possible by modifying the linker file, but please provide more details and I can give you some hints.
Regards!
Jorge Gonzalez
Thanks for the reply Jorge.
I am using the MC9208QE128.
You are exactly correct, I want to set a flag (1 byte) at startup and be able to use that flag later in normal execution. The only way I have found I can do this is by specifically placing the variable at a particular address (i.e. @ 0x1800). This puts my variable in its own section called ".abs_section_1800" which does not get initialized in Start08.c::init(). Furthermore, for now I have placed in the PRM a commented out memory section: BOOTLOADER_VARIABLE = NO_INIT 0x1800 TO 0x1801. This memory section in the PRM does nothing more than alert the next person who looks in the code to avoid that memory location.
I do not know if this is the normal way to solve this problem, but it sure feels like a workaround. I feel like it could be an issue that may come up in the future where this variable is getting overwritten again because of some other unrelated change changing how the linker is allocating memory.
Thanks,
Marshall
Hi Marshall:
Thanks for clarifying.
That sounds like a good workaround for me, but have you tried actually leaving that section uncommented and removing those bytes from your ram section? Or even easier, leave it commented as a "signal" just like you mention and take out those bytes from the ram section in PRM. This way the variable will never be overwritten.
The normal approach is to place reserved variables at the end of your ram (or flash) and tell the linker not to use that space.
Regards!
Jorge Gonzalez
Thanks for the quick reply Jorge.
Sorry, I forgot to mention that I did indeed remove those bytes from my RAM section - but thank you for reminding me that this is important. It sounds like this is the normal way to address this issue :smileyhappy:
Thank you for your help!