Forums

__Attribute__ ()

Started by jdauchot October 26, 2007
Hi All
OK it is not an LPC2000 problem, but I woul like to how to tell the GNU
linker to place a memory section so that I can use external memory on a
LPC 2294

Regards

Jean-Jacques

An Engineer's Guide to the LPC2100 Series

> Hi All
> OK it is not an LPC2000 problem, but I woul like to how to tell the GNU
> linker to place a memory section so that I can use external memory on a
> LPC 2294
>
> Regards
>
> Jean-Jacques

You can check my remark in message 28608 :)

Regards,

Armand ten Doesschate
--- In l..., "jdauchot" wrote:
>
> Hi All
> OK it is not an LPC2000 problem, but I woul like to how to tell the GNU
> linker to place a memory section so that I can use external memory on a
> LPC 2294
>
> Regards
>
> Jean-Jacques
>

Pretty much answered in message 28572

To the MEMORY section, add a name and a definition for the memory block
MEMORY
{
flash: .....
ram: .... <= internal RAM
myexternalram: ORIGIN = , LENGTH =
}

myexternalram should have attributes such as (X) for executable or (A)
for allocatable (variables). See page 47 of the 'ld' manual.

Define a SECTION that goes into 'myexternalram' as

SECTIONS
{
.text: {...}
.data: {...}
.bss: {...}
.mynewsection
{
.. other sections within mynewsection
} > myexternalram
}

This works as long as myexternalram doesn't need to be initialized.
If it does then you do something like the script does with .data and
change the last line

} > myexternalram AT >flash

This puts the initial contents in flash. Now define symbols like
those used for .data so your startup code can copy the initial
contents from flash to RAM by knowing the starting points for the copy
and the length to copy.

So far, it doesn't matter whether you are copying code or data.

Define functions to run from 'myexternalram' as

void foobar (void) __attribute__ ((section(".mynewsection")));

Define variables as

int k __attribute__ ((section(".mynewsection")));

You can not call foobar from code in flash because the displacement is
too large (usually). You need to call it with a function pointer see
message 24863.

To get this to work you are going to have to spend time with the 'ld'
and 'gcc' manuals. Expect to spend time pouring over the .map file
and probably the .lss file. Make a couple of test cases for functions
and data, modify the linker script, modify the startup code and see
what happens. Certainly no more complicated than, say, a blinking LED.

I think my first test case would be to have the loop variable for a
blinking LED in 'myexternalram'. The second case would have the loop
code in flash call a function in 'myexternalram' to change the state
of the LED pin. Finally, I would have a stub in flash call the
blinking LED code in 'myexternalram' with the loop variable in .bss or
.data. These tests would pretty much tell whether the code, linker
script and startup code were in agreement.

Richard