# Writing a Function at specific memory location of Flash

I want a function to go at specific memory location of Flash and I am not able to figure it out.

Do I need to do modification in Linker File?

Also, I have idea that in GCC, I would use #pragma directives by which I can put my code in specific section but don't know how to assign that section to specific address.

I am using Keil and programming LPC2138.

To put a function in a section with GCC, use a function attribute

extern void foobar (void) __attribute__ ((section ("bar")));


Then, declare a section called bar in your linker script. Eg.

MEMORY
{
FLASH (rx): ORIGIN=0xDEADBEEF, LENGTH=0x80000000
}

SECTIONS
{
.bar:
{
KEEP(*(.bar))
} > FLASH
}

• Thanks Joby. But has anyone tried this with Keil?? – Swanand Mar 19 '12 at 10:09
• – Toby Jaffey Mar 19 '12 at 10:22