Linker file and section declaration on KDS 3.0

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

Linker file and section declaration on KDS 3.0

1,048 Views
Claudione
Contributor I

Good mornig.

I need to modify the linker file in the KDS ide.

Everything it's ok, but when I have to define a variables in a specific source file I have to declare the section for

every variables.

Ex:

__attribute__ ((section (".UartsData")))scidata SCI0_DATA;   // SCI0 data
__attribute__ ((section (".UartsData")))scidata SCI1_DATA;   // SCI1 data

 

If I don't use  __attribute__ ((section (".UartsData"))) in front of every variables, the same variable it's not in the segment I want.

Usually the segment must be declared once only at the head of the file.

Ther's a way to do this in KDS ?

 

Thanks.

Claudio

Labels (1)
0 Kudos
2 Replies

496 Views
Jiun_Yong
Contributor III

Hi Claudio

I have just done something like this.

First, I suggest you read through this article: Putting Code of Files into Special Section with the GNU Linker | MCU on Eclipse

In the linker file, you can specify that you want the output from a specified source file put in a specific memory location as follows:

This example is to store a constant array in a particular location (it's 1K in size). The array was defined on its own in a file called "boot_crc32.c"

1. In the linker file, MEMORY section, add a new line for the data:

MEMORY {

  m_interrupts (RX) : ORIGIN = 0x00001000, LENGTH = 0x000000C0

m_boot_crc32 (R) : ORIGIN = 0x00000C00, LENGTH = 0x00000400

  etc.

}

2. In the SECTIONS part of the linker file, add the following. Put it somewhere near the start before the .text section which holds the program code and data.

  /* New section for the CRC32 lookup table */

  .boot_crc32_seg :

  {

  . = ALIGN(4);

  *boot_crc32.o (.rodata .rodata*)

  . = ALIGN(4);

  } > m_boot_crc32

 

3. This tells the linker to take the compiled output from any file matching the pattern *boot_crc32.o and place any read only data in memory block m_boot_crc32

If you were placing code in this segment, change .rodata to .text.

4. The actual definition for this data reads

const uint32 TableCRC32[] = { 0x00000000, 0x04c11db7, etc.

Note that I did not have to put any __attribute__ ((section (".boot_crc32_seg "))) statement at the front of the declaration.

It's all done in the linker file (Usually called "ProcessorExpert.ld" or similar)

5. Finally, check placement in the map file

Hope this helps. I spent half a day working this out and testing it.

Good luck

Steve

0 Kudos

496 Views
Claudione
Contributor I

Hi Steve.

Thank to you for your suggestion.

I will try in the next day.

Thanks for now.

Claudio

0 Kudos