2021-02-26 02:09 AM
I want to store my software version and data at a pointed section of STM32's Flash.I have tried to config the stc file in keil mdk,but it seems not working.So could anyone help me to find which step not right,thanks.
1. I set in keil to use user configured stc file;
2. I set the sct file like this:
;Add 0x0x0801B000 start address,2k=0x800 length to define as myram section to store user data
3.I define MYRAM as __attribute__((section("myram"))):
4.I use MYRAM to define user data const variable:
then i rebuild this program and download the hex to STM32G4,but the sct file defined style
variable could not be found at MYRAM section at 0x0801B000;
But when I use the style liking attribute at + address,it is useful;
So the attribute at + address method is useful,but if I want to define another const variable behind the UserData_BlockValue2, I have to calculate the address because of the length of UserData_BlockValue2, this seems a little tedious.
I want to know is it possible to use sct file to define a section of flash to store my const variables Value1,Value2,Valu3...and so on,these variables' address are automaticlly in turn loacted at the section? Thanks.
Solved! Go to Solution.
2021-02-26 06:41 AM
Hello
define the version string as const
static const char xxxx[]={"version string"};// ensure will COMPILE as RO DATA
Make a new REGION and write to LOAD adress *(.rodata.xxxx)
LR_IROM2 0x0801B000 0x00000800 { ; load region size_region
ER_IROM2 0x0801B000 0x00000800 { ; load address = execution address
*(.rodata.xxxx)
}
}
Note that, LR_IROM2 region must be outside of the default region.
2021-02-26 06:41 AM
Hello
define the version string as const
static const char xxxx[]={"version string"};// ensure will COMPILE as RO DATA
Make a new REGION and write to LOAD adress *(.rodata.xxxx)
LR_IROM2 0x0801B000 0x00000800 { ; load region size_region
ER_IROM2 0x0801B000 0x00000800 { ; load address = execution address
*(.rodata.xxxx)
}
}
Note that, LR_IROM2 region must be outside of the default region.
2021-02-26 07:14 PM
Thanks, combine your advice and my searching result by Google,I find a more useful method:
1.Revise sct file and define a section for userdata;
Here I define myram form 0x0801C000 with a length of 2K(0x00000800),this section is put at outside of the default region;
2.Use macro definition in your program;
Here use keyword attribute to locate at the pointed section, keyword used will prevent the defined const variable from being ignored by MDK compiler even though it is not referenced at anywhere in your program code.This will be helpful when you want to store your software version at a pionted section at STM32's FLASH,maybe you will never read or write this software version until the product go back home for repairing,then you could use STLINK to read the software verion at the pointed address.So the keyword used is useful.If not used this keyword,you will not find the initial data for your const variable when this variable is not referenced at any place in your code.
3.Use macro definition to define the const variable;
Here I jsut define the const variables for user data at the pointed section,they will be stored one by one at the pointed address without my own calculating starting address for each varioable,so it is convenient.
4.At last, let me check the falsh data at my defined section at the pointed address,the data is as what I want to be stored.
Thanks for Vangelis Fortounas's answering and advice,here this article is also helpful for this solution:
https://www.amobbs.com/thread-5724606-1-1.html.
So this question has a good result,may it will help someone else.
2021-02-27 01:06 AM
Hello
@ZYu.1
Note also the macros __DATE__ and __TIME__ that are available at compile time . Usefull to embed compilation date and time to flash memmory
2021-02-28 11:09 PM
Thank you,that's a good advice.