cancel
Showing results for 
Search instead for 
Did you mean: 

how to store a variable at a particular location in flash?

Aatif Shaikh1
Associate III

Hello!

I'm starting to work on a project and it is built on the IAR IDe (the controller is stm32f103rct6). My task is to change the IDe (to Keil) of this existing project. After reviewing the existing code, I noticed, few configurational structures are getting stored in the Internal-Flash. The base address of these configurational structures is present in the ".icf" file (check the code snippet below).

/**ICF file**/
place at address mem: 0x08006400    { readonly section ConfigParSection };
place at address mem: 0x08006800    { readonly section ConstSection1 };

In the "main.c" file he was defining the location of these structures using #pragma.

/********************struct definition**********************/
#pragma pack(push,1) // for remove padding
typedef struct
{  
	int a;	float f;	char c [10];	
}TsAFMConfig_StructTypeDef;
 
#pragma pack(pop)
 
/********************struct variable**********************/
#pragma location = "ConfigParSection" 
__root const TsAFMConfig_StructTypeDef  AFMMCUFlashConfig = 
{
	56, 3.14, "1.1.0",	}
 
#pragma location = "ConfigParSection" 
__root const char Fake[0x400 - sizeof(AFMMCUFlashConfig)];    //400

 Now, I want to do the same thing in the Keil IDe without making any big changes, but unfortunately, I can't find the linking of ".icf" file and the Keil compiler doesn't know the meaning of "__root". can someone help me with this?

4 REPLIES 4
Ozone
Lead

I am not sure why you want to enforce a particular location.

Declaring it as constant will create it in Flash, and you can refer to it by the variable name, without caring about the actual location.

The icf - file is an IAR specific linker configuration file.

Under Keil uVision, there use to be scatter files with an *.sct extension: https://www.keil.com/support/man/docs/armlink/armlink_pge1362065968963.htm

the code snippet mentioned above was already written by a firmware developer (he was working on this project previously). The reason he enforced the structure to a particular location is that multiple codes like bootloader, code_1 and code_2 all of them are using the same structure for some particular process.

Additionally, there are thousands and thousands of devices that are already in the field. Hence, changing anything bootloader isn't possible at all.

christian B.
Associate II

If you want to place some data in a fixed position in memory, you must use linker file for your application defining a section in flash memory.

Then you can assign your data in this section but this is peculiar to your toolchain, you have the keywords let see your toolchain doc (i use gcc and not Keil)

This makes sense.

My company has similar applications, too. Often with post-build Hex/S19 file postprocessing to patch addresses or checksum in.

I'm no Keil user, and have very little experience with Keil's SCT files.

So I could only recommend the given link to the manual, or the Keil forum.

At least some while ago, this forum was quite active and helpful.