how to write a library into a specific memory address using AtmelStudio

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Im using the same library for my firmware and the bootloader. How can I write this library into a specific memory address so I can use it form the bootloader and the firmware.

Best regards

Last Edited: Fri. Sep 14, 2018 - 12:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The library itself does not need to be in a "shared" location - just some "hook" to gain access to it's functions. That can be as little a a 16 bit pointer to a struct of function pointers.

 

Anyway assuming that by "Atmel Studio" you really mean the avr-gcc compiler then the way you manually position anything in that is by placing the code or data into some named section and then using the linker directive -section-start=.section_name=0x1234 to position it to flash address 0x1234. It's also possible to achieve this with linker scripts but the section start thing is probably the easier approach.

 

For example:

int up(int n) {
    return n + 1;
}

char down(char n) {
    return n - 1;
}

typedef void (* fptr)(void);

__attibute__((section(".shared"))) fptr functions[] = {
    (fptr)up,
    (fptr)down
};

then later:

-Wl,-section-start=.shared=0x1234

Now both this provide and also an accessor can know to look for a table of function pointers at 0x1234. The caller wanting to use down() calls through the second function pointer in this table.