avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Allocating code to separate sections


From: Alistair Gadd
Subject: Re: [avr-gcc-list] Allocating code to separate sections
Date: Thu, 09 Oct 2014 08:49:27 +0200
User-agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0


On 2014/10/09 08:29 AM, Senthil Kumar Selvaraj wrote:
On Thu, Oct 09, 2014 at 07:32:51AM +0200, Alistair Gadd wrote:
Hi Everybody,

I'm hoping this is an easy one for someone out there.

I'm putting together a bootloader for an ATmega328P using Atmel Studio 6.2
and I would just like to ask if there is an easy way configure the IDE so
that I can have separate sections that I can allocate code to. I have been
using "-Ttext 0x7000" as a linker flag in "Configuration
Manager->Toolchain->AVR/GNU Linker->Miscellaneous", which places all the
code starting with reset vector at 0x3800 onwards, but I would like to have
another section in the application section where I can place an SD card
library that will be accessible by the bootloader and by future
applications.

I have defined another "FLASH segment" - ".sdlib=0x2000" in "Configuration
Manager->Toolchain->AVR/GNU Linker->Memory Settings, but I don't know how to
configure .c source files and assembler .s files so that their code is
allocated to this segment.

Can anybody give me some ideas on how I could achieve this?
There are a couple of ways.

1. Create a linker script that groups code from specific object
files into custom output sections. Something like

.sdlib :
{                                                                                                                                                                                                       
    foo.o(*.text)
}

where foo.o is the object file containing the code to go into the
section.

2. Use attributes in C code and .section directives in assembler code to
specify the section.

void __attribute__((section(".sdlib"))) my_function() {}
int main() { return 0; }

This makes the place the my_function's code in a .sdlib section. main's
code still goes into .text.

Hope this helps.

Regards
Senthil
Thanks very much Senthil,

I have tried the __attribute__((section(".sdlib"))) directive which works but I'm having problems trying to define variables in flash by using:

const unsigned char __attribute__((section(".sdlib"))) array[5] PROGMEM  = {1,2,3,4,5};
or:
const unsigned char array[5] __attribute__((section(".sdlib"))) PROGMEM  = {1,2,3,4,5};

I think I prefer your first option though because it would put everything in that module into the .sdlib section, but my problem is I don't know how to create and use the linker script. Can you maybe point me to some documentation that would show me how it is used.

Best regards,
Alistair.



--




reply via email to

[Prev in Thread] Current Thread [Next in Thread]