How to use a Section for variables

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User11996
Level 3
Level 3
Hi.

How can i use a separate ram section for variables.

I declare a new section in the linkerscript.
I declare a variable in my new section

but the compiler places the variable only in the .bss section.


C-Code:

uint32_t RAMTest[3000] __attribute__((section(".MyRam")));

Linker File:

@ Memory

MYSEPARATERAM(!RX) : ORIGIN = 0x40000000, LENGTH = 0x4000

than between data and bss-section:

/* RAM section */
.MyRam(NOLOAD) :
{
. = ALIGN(4); /* section size must be multiply of 4. See startup.S file */
__MyRam_start = .;
*(.MyRam*);
. = ALIGN(4); /* section size must be multiply of 4. See startup.S file */
__MyRam_end = .;
} > MYSEPARATERAM
__MyRam_size = __MyRam_end - __MyRam_start;



But the Compiler is placing the variable in .bss/SRAM_Combined.
Wo warning about a not existing section.

Is the a way to use the ram section for my variables?
0 Likes
2 Replies
User11996
Level 3
Level 3
No one there, who has a tip for me?

It seem's the linker-file is ignored. The path of the linker file is correct.

I can declare a variable in the C-Source with a section. The linkers is creating the section by himself (myarea) !.

A entry in the linker-file is complete ignored (myram).


C-Source:

__attribute__((section(".myram"))) uint32_t RAMTEST[100];
__attribute__((section(".myarea"))) uint32_t RTEST[100];
or
uint32_t RAMTEST[100] __attribute__((section(".myram")));
uint32_t RTEST[100] __attribute__((section(".myarea")));

linker_script.ld:

MEMORY
{
FLASH_1_cached(RX) : ORIGIN = 0x08000000, LENGTH = 0x7FF00
FLASH_1_uncached(RX) : ORIGIN = 0x0C000000, LENGTH = 0x7FF00
PSRAM_1(!RX) : ORIGIN = 0x1FFFC000, LENGTH = 0x4000
DSRAM_1_system(!RX) : ORIGIN = 0x20000000, LENGTH = 0x8000
DSRAM_2_comm(!RX) : ORIGIN = 0x20008000, LENGTH = 0x8000
SRAM_combined(!RX) : ORIGIN = 0x1FFFC000, LENGTH = 0x14000
}

SECTIONS
{
.myram 0x1FFFC000 (NOLOAD) :
{
KEEP(*(.myram)) /* keep my variable even if not referenced */
} > PSRAM_1

.myTestBlock 0x20001000 (NOLOAD) :
{
KEEP(*(.mytestcmd)) /* keep my variable even if not referenced */
} > DSRAM_2_comm


Result in Map-File:

PSRAM_1 is complete ignored and unused. I miss 16kB of the RAM. (.bss only @ 0x20000000)
-> how can i force the linker to place variables in psram? ?????????
My ram is running over without the PSRAM. -> section `.bss' will not fit in region `SRAM_combined'
.settings/properties.index is correct:




Stack 0x20000000 0x800
0x20000000 __stack_start = .

.data 0x20000800 0x1934 load address 0x0c01fad0


.myarea 0x20002134 0x190 load address 0x0c021404 -> created by the linker, without a entry in linker_script.ld
.myarea 0x20002134 0x190 ./CAN/CAN_drv.o
0x20002134 RTEST

.myram 0x200022c4 0x190 load address 0x0c021594 -> entry from linker_script.ld ignored.
.myram 0x200022c4 0x190 ./CAN/CAN_drv.o
0x200022c4 RAMTEST

.bss 0x20002458 0xd9c0 load address 0x0c021724
0 Likes
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

As a reference you can take the implementation of the no_init section in the default linkers and its usage in the system_xxx.c files.

Regards,
Jesus
0 Likes