EmbeddedRelated.com
Forums

How to define placement address of functions?

Started by Unknown August 1, 2006
Hi all,



I want to place a function in the bootload sector of my ATmega32, where I 
will do some writings to a flash table. How will I get the compiler to place 
the function and just this one function at 0x7000 ?



I have tried



//Declaration

void (*table_write) (float flash *table_ptr, float value2 )=0x7000;



//Defenition

void table_write(float flash *table_ptr, float value2)

{

           //Function body

}



I have also tried various usage of #asm(".org 0x7000"), but this always seem 
to cause problems when compiling.





What is the right approach ? I need to have the function placed at 0x7000 
since I cannot use the "spm" instruction in the app. area of the flash :(



I use the Codevision Compiler from HPinfotech.



Best Regards



Morten J�rgensen


Morten M. J�rgensen wrote:
> Hi all, > > > > I want to place a function in the bootload sector of my ATmega32, where I > will do some writings to a flash table. How will I get the compiler to place > the function and just this one function at 0x7000 ? > > > > I have tried > > > > //Declaration > > void (*table_write) (float flash *table_ptr, float value2 )=0x7000; > > > > //Defenition > > void table_write(float flash *table_ptr, float value2) > > { > > //Function body > > } > > > > I have also tried various usage of #asm(".org 0x7000"), but this always seem > to cause problems when compiling. > > > > > > What is the right approach ? I need to have the function placed at 0x7000 > since I cannot use the "spm" instruction in the app. area of the flash :( > > > > I use the Codevision Compiler from HPinfotech. > > > > Best Regards > > > > Morten J�rgensen > >
I'm not familiar with that processor or those tools, but here are some general comments, and things to look for: 1. You can't locate your function like that. It's an interesting syntax, but it isn't remotely like C syntax. 2. If 0x7000 is in nonvolatile memory see if you can control what segment a function goes into (usually with #pragma statements), and if your linker will let you command a particular segment to a particular spot. This seems to be standard these days, with linkers taking a command file that lets you define where segments go. 3. If 0x7000 is in RAM then you can copy the function at startup. This can be a royal pain, which is why linkers are so versatile these days... 4. If worse comes to worst write the whole thing in assembler, using that 'org' statement to put it at 0x7000. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Posting from Google? See http://cfaj.freeshell.org/google/ "Applied Control Theory for Embedded Systems" came out in April. See details at http://www.wescottdesign.com/actfes/actfes.html
"Morten M. J&#4294967295;rgensen" <mj@iadataFJERNMIG.dk> skrev i melding 
news:44cf47a9$0$13979$edfadb0f@dread15.news.tele.dk...
> Hi all, > > > > I want to place a function in the bootload sector of my ATmega32, where I > will do some writings to a flash table. How will I get the compiler to > place the function and just this one function at 0x7000 ? > > > > I have tried > > > > //Declaration > > void (*table_write) (float flash *table_ptr, float value2 )=0x7000; > > > > //Defenition > > void table_write(float flash *table_ptr, float value2) > > { > > //Function body > > } > > > > I have also tried various usage of #asm(".org 0x7000"), but this always > seem to cause problems when compiling. > > > > > > What is the right approach ? I need to have the function placed at 0x7000 > since I cannot use the "spm" instruction in the app. area of the flash :( > > > > I use the Codevision Compiler from HPinfotech. > > > > Best Regards > > > > Morten J&#4294967295;rgensen > >
And what toolchain are you using ?? Normally, you don't tell your compiler to place the function at a specific address. That's something you tell your linker. Typically you make the bootloader as a separate application, and tell the linker to locate the reset vector at 0x7000, and the rest of the program in the boot sector.
> I'm not familiar with that processor or those tools, but here are some > general comments, and things to look for: > > 1. You can't locate your function like that. It's an interesting syntax, > but it isn't remotely like C syntax.
Hey Tim, I found it as a code example in a compiler documentaion. I thought I could use it for my purpose, but no. The author of the compiler has sent me a strip of code that sorts out my problem. It is solved via inline asm directives before defining the function. -- Morten
Hello Jan

> And what toolchain are you using ??
The Codevission IDE has it's own compiler and uses the Atmel AVR asm.
> Normally, you don't tell your compiler to place the function at a specific > address. That's something you tell your linker.
Yup! I know that, but the problem is that you don't have acces to linking options in codevission
> Typically you make the bootloader as a separate application, and tell the > linker to locate the reset vector at 0x7000, and the rest of the program > in the boot sector.
Yup again....but I have to execute code from the bodeloading sector if I want to use the "spm" command that writes to the flash memory ;) -- Morten