Linking an array to a fixed address

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

Linking an array to a fixed address

2,546 Views
mattj
Contributor II

Hello,

within Codewarrior / processor expert / CPU build options I have created a new MemoryArea at a fixed address called myromheader. Now I want the linker to put an array in this section. I've tried all ways I could find, via attribute, via declspec etc:

const unsigned char myheader[10] __attribute__((section(".myromheader"))) = {"1752"};

In the generated map file I can see that my section is created but the array is always linked to the normal code section. Any ideas what else to do?

Labels (1)
6 Replies

847 Views
BlackNight
NXP Employee
NXP Employee

Hello,

if this is for gcc and Kinetis, then this link could be helpful: Defining Variables at Absolute Addresses with gcc | MCU on Eclipse.

Keep in mind, if you change the linker file for a Processor Expert Project, you need to disable linker file generation, otherwise your changes will be overwritten. How to disable this, see the last screenshot in Disable my Code Generation | MCU on Eclipse.

Hope this helps,

Erich

0 Kudos

847 Views
mattj
Contributor II

The Kinetis linker has some different syntax, so I couldn't get this to run

0 Kudos

847 Views
carlos_neri
NXP Employee
NXP Employee

Matt,

Please find attached the sample code I wrote to test this.

This is on CW10.2 with all the patches installed. You can take a look at the xMAP file to confirm the variable is placed on the new section. Note that  that I used a pragma called "force_active" to avoid the linker to optimize the variable.

847 Views
mattj
Contributor II

Thanks,

the force on pragma made the difference now it is working when I manually edit the processor expert generated linker script. I still have to figure out how to get this running together with the processor expert memory map settings or disable the linker script generation 

0 Kudos

847 Views
carlos_neri
NXP Employee
NXP Employee

Matthias,

You require a set of pragma plus declspec.

I've created a section on my linker as follows:

.myrom_section:

{

  *(.myrom)

  . = ALIGN (0x4);

} > myrom

Then, on the code, use the pragma "define_Section" and the declspec "section" to do the job:

#pragma define_section myrom_section ".myrom" far_abs RX

__declspec(section "myrom_section")

const unsigned long gu32Test = 0x1234;

Compiled and got the expected placement on my MAP file:

# .myrom_section

  00000800 00000004 .myrom  gu32Test (main.obj)

You can refer to the app note 4498, which is on your CW installation path (10.2 or 10.3):

{CW path}\MCU\Help\PDF

0 Kudos

847 Views
mattj
Contributor II

This is exactly what I did before and I tried it again; myrom_section is created but the constant is still linked to .rodata section, regardless of what I do

0 Kudos