Forum : ARM
Original Post
Post Information | Post |
---|---|
February 25, 2013 - 8:28pm
|
I am trying to store some runtime data into flash and it is instead storing into RAM. I need it to persist so after power cycle I can read it back in. I have this in my header file: // base address for flash storage I've also tried different values for the above but it seems the data is always stored at 0x20000054 Not sure what I have wrong but this sticks out, in my LD Linker setup, it calls out crt0_STM32.o and I see this file doesn't exist?? |
Ride v7.42.12.0305
RKit v1.46.12.0305
Hi,
I'm afraid it's more complex than a #define. (much)
And changing this define, if as I guess it's the one from the ST lib (?), will make other things fail.
For doing this you need to use a custom linker script (usually copied from the default as starting point), then in this script create a new MEMORY region and a new SECTION for your Flash storage, and then in the source code use "_attribute_" to place your variables in your new section.
Also be careful that for writing Flash you cannot use simple C affectations. You need to use the Flash writing functions from the ST lib.
See the GettingStartedARM document for how to use a custom linker script and how to find the default script for your CPU.
See the GCC doc and example scripts for how to create MEMORY regions and SECTIONs in your linker script.
See the ST lib doc for how to use it for writing in Flash.
I hope it helps.
Best Regards,
Vincent
Thanks, got it!
Turns out first thing was the address I was trying to use was out of the range of the chip's flash size. I also did make a custom linker script, pretty easy with a couple posts I found.
OK, spoke too soon. I can only write once and the ST datasheet says the value should be 0xFFFF before writing, which proves the write once. I didn't seem to need to use the "_attribute_" declaration and if I try to use it, it says I've reached my debugging code size limit. What am I missing?
// base address for flash storage
#define BASE_ADDRESS ((uint32_t)0x08002000)
Hi,
Well, I can already tell you that you'll have problems if you declare memory regions that overlap as FLASH and STORAGE_REGION do in your script. ;)
Where does the "BASE_ADDRESS" quote come from? Does it come from an example or library? (which one? from who?)
The message about debug limit comes because you used as starting point a default linker script generated for a project that had the "Starter Kit Limit" option activated. See the GettingStartedARM doc for what this option means. You should start again from a script generated for a project that does not have this option, which will remove this check and message from the script. Then you might have (or not) another message like 'memory full' which is what really happens for what the linker sees. Of course if you are in Lite with a standard RLink, then you must refrain from using the second half of the Flash, otherwise you'll not be able to debug the application. (you can compile and program it, no problem, but not debug it)
I hope it helps.
Best Regards,
Vincent
The BASE_ADDRRESS is defined in my header file. Turns out I didn't need a custom linker script at all. I just need to erase the page before writing to it again.
Hi,
Glad to hear that you are making progress.
I still think you'll need a custom linker script, if only to prevent the linker from placing data or code in the area that you want to use as data flash. But for this you don't need to create a new region and a new section. Just reduce the existing Flash region.
Best Regards,
Vincent