ARM Technical Support Knowledge Articles

WRITING RELOCATABLE C FUNCTIONS FOR COPYING TO RAM

Applies to: C166 C Compiler

Answer


Information in this article applies to:


QUESTION

I have read application note 138, which describes how to copy assembler routines from Flash memory to RAM for execution. I want to copy C routines. Is this possible?

ANSWER

Yes. However, you must locate the C code in FAR memory (MEDIUM, LARGE, or HLARGE memory model) and you must use the RENAMECLASS directive to specify the correct name for the code class.

Write your C functions in a separate source file as functions. For example:

#pragma LARGE     // only required when you are using the SMALL memory model!
#pragma RENAMECLASS(FCODE=FLASH_CODE)

int PFlash_Erase (void huge *sector_adr)
{
sector_adr = sector_adr;   /* Avoid compiler warning */

return (0);
}

int PFlash_Write (void huge *target_adr, void huge *buffer)
{
target_adr = target_adr;   /* Avoid compiler warning */
buffer = buffer;           /* Avoid compiler warning */

return (0);
}

void PFlash_Reset (void)
{
}

Your C routines are then ready to use!

You will probably receive a linker warning similar to the following:

*** WARNING L14: INCOMPATIBLE MEMORY MODEL
    MODULE:  pflash.obj (PFLASH)
    MODEL:   LARGE

The warning is caused (in this instance) because the memory model of the program is SMALL while the memory model of the PFLASH module must be LARGE. It is safe to ignore this warning.

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-06-01 12:55:30

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential