[Top][All Lists]

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

Re: [avr-gcc-list] AVRGCC initialisation of variables

From: Bruce D. Lightner
Subject: Re: [avr-gcc-list] AVRGCC initialisation of variables
Date: Mon, 23 Jul 2001 09:55:57 -0700


> Does anyone have a gracefull method of avoiding AVRGCC cleaning out variables 
> @ reset ?
> I want to retain the value of my Realtime Clock variables when the part 
> resets.

We do this by using our own "linker script file".  We start with the
"default one", which you can easily get from running the linker with
"--verbose".  Then we add a single line for a new section called, for
example, "uninitialized_data" to the logic that outputs the ".bss" data. 
For example:

  .bss  SIZEOF(.data) + ADDR(.data) :
       AT (ADDR (.text) + SIZEOF (.text) + SIZEOF (.data))
     PROVIDE (__bss_start = .) ;
     PROVIDE (__bss_end = .) ;
    *(uninitialized_data)         <--- ADD THIS LINE
     _end = . ;
  }  > data

When linking, you will need to add the -T option to specify your modified
linker script in place of the "default" one.

To make use of your new section called "uninitialized_data" in C-code, use
something like...

  unsigned char RTCvars[8] __attribute__((section ("uninitialized_data")));

In AVR assemply, use something like;

   .pushsection uninitialized_data
   .gloal RTCvars
   RTCvars: .skip 8

Create and check the "link map" file to verify that things when as planned. 
You should find your global label listed in the correct place *after* the
.bss data.  Of course, the .bss section is automatically zeroed after the
AVR part is reset by the crt1.s startup-file, but your new section should be
left untouched!

Obviously, you should not expect these locations to contain any particular
data values after the AVR part is power-cycled.

Best regards,


 Bruce D. Lightner
 Lightner Engineering (http://www.picoweb.net/)
 La Jolla, California
 Email: address@hidden
 URL: http://www.lightner.net/lightner/bruce/

reply via email to

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