How to put part of program data into local ram, the rest into external memroy?

Hi guys,

I have a question regarding how to use linker script to place specific data in the specific memory. Lets make long story short. Assume I have four arrays: a[100], b[100], c[1000], d[1000] in the main.c. I wanna put the first two array a[100], b[100] into local memory, DSOCM, while the others into the external DDR. How can I do this by linker script? Any input would be greatly appreciated!

I just found a webpage briefly touches this issue from xilinx answer database. See the solution2, It says"Another method is to keep any variables whose locations you want to control in a separate file (this example will use "special.c")." I just wondered how can I keep those variables in a separate file .c?

formatting link

Thanks in advance,

Yao

Reply to
Yao Sics
Loading thread data ...

formatting link

I did not understand which part of the above answer record your difficulty is with. Unless your data structures are an integral part of your main.c it should be fairly easy to move them to another file. Assigning an entire .o file or a section from a .o file to memory then becomes easy in the linker script. The linker script construct is described in the answer record as well as the GNU linker manual.

Apart from the method in the answer record above, you can use section attributes on your data structures to assign them to specific sections. For example,

int a[100] __attribute__((section(".mydatasection")));

Then in your linker script, create a new section assignment and assign it to the memory you want. You can do the same thing for functions. For example,

.bramdata:{

*(.mydatasection) }> BRAM

Refer to the GNU GCC docs on section attributes and the GNU linker script docs on section assignment to memory.

- Vasanth

Reply to
Vasanth Asokan

Hi Vasanth,

Thank you very much for your input.

I will give it a try for the __attribute__((section())) approach. Another quick question regarding this __attribute__. Is it only legal to be used on global variables?

Cheers,

Yao

Reply to
Yao Sics

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.