How to define placement address of functions?

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


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


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

Reply to
Morten M. Jørgensen
Loading thread data ...

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
 Click to see the full signature
Reply to
Tim Wescott

"Morten M. Jørgensen" skrev i melding news:44cf47a9$0$13979$

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.

Reply to
Jan Leithe

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

Reply to
Morten M. Jørgensen

Hello Jan

The Codevission IDE has it's own compiler and uses the Atmel AVR asm.

Yup! I know that, but the problem is that you don't have acces to linking options in codevission

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

Reply to
Morten M. Jørgensen

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.