Storing variables into data ocm memory

Mar 29, 2006 2 Replies

Hallo, I' developing a microcontroller based on powerpc. the only way I know to store some variables into a specific region of memory is instantiating them directly using the command:



unsigned char (*variable_name) = (unsigned char(*))XPAR_PERIPHERAL_BASEADDR;



There are other ways?



If use use the linker script there is a way to "choose" which variables store into a certain region of memory?



Many Thanks Marco


Hi Marco,

Yes, you can use a linker script for this, together with a gcc attribute to indicate which segment should receive a given variable.

For example, somewhere in the linker script you could add

. = 0x40000000; .ocm : { *(.ocm) }

This creates a new segment, "ocm", starting at address 0x40000000 (or wherever your OCM is mapped). To actually cause variables to be allocated to this segment, use something like

#define __ocm__ __attribute__((aligned(32),section(".ocm")))

and then declare your variables:

int __ocm__ foo; int __ocm__ bar[128];

You can verify that these ended up in the ocm segment with objdump. And you'll want "ld -T my_linker_script.ld"; google linker-script for tutorials.

Cheers, Peter

Many Thanks for your reply! Marco

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required