linker question - passing value from linker to source or source to linker

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

linker question - passing value from linker to source or source to linker

Jump to solution
628 Views
Jim_P
Contributor III

I work with many different processors for different projects for different customers.

 

I am trying to configure a standard  project.prm for the different micro's - - - -

but some of the memory (Ram and Flash) locations will be need to be different for different projects.

 

If I define the locations in the PRM file, how can I get the C source code to know what these are.

or if defined in a project_defines.C file can I get the linker to know about the settings.

 

as I am trying to reduce the number of places that things need to be changed - - - - -

 

Thanks Jim P

Labels (1)
Tags (1)
0 Kudos
1 Solution
449 Views
kef
Specialist I

You may define custom data segment and placement to that segment. Then just put your data to that segment using compiler pragmas:

#pragma DATA_SEG placement

...data structs or varuiables...

#pragma DATA_SEG default

  

If needed, you can always get address of your custom data using address operator (&variable).

 

To get start or end of segment use linker defined symbols __SEG_START_xxx, __SEG_END_xxx, __SEG_SIZE_xxx, where xxx is placement. You need to declare those linker defined symbols in your code like

   extern int __SEG_START_xxx[];

  

In case data has to be not initialized, change type of segment in prm from READ_WRITE or READ_ONLY to NO_INIT .

 

View solution in original post

0 Kudos
2 Replies
450 Views
kef
Specialist I

You may define custom data segment and placement to that segment. Then just put your data to that segment using compiler pragmas:

#pragma DATA_SEG placement

...data structs or varuiables...

#pragma DATA_SEG default

  

If needed, you can always get address of your custom data using address operator (&variable).

 

To get start or end of segment use linker defined symbols __SEG_START_xxx, __SEG_END_xxx, __SEG_SIZE_xxx, where xxx is placement. You need to declare those linker defined symbols in your code like

   extern int __SEG_START_xxx[];

  

In case data has to be not initialized, change type of segment in prm from READ_WRITE or READ_ONLY to NO_INIT .

 

0 Kudos
449 Views
Jim_P
Contributor III

Thanks that was what I was looking for.

 

the back link from linker to source code.

 

I am looking at trying to have my code portable for different applications.

and was not liking the idea of setting a settings area in the linker and then having to

besure that the code knew where the area was.

 

The settings are the application settings and for debug and check out can be changed from the PC interface. 

this solves the problem.

 

also looking at possible logging area in flash and this again would be application / processor dependent and not wanting to have to set this in different locations

 

thanks again

Jim P

0 Kudos