Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Re: need variables to be stored in EEPROM

2005-04-25 by David Kelly

On Mon, Apr 25, 2005 at 05:12:13PM -0000, arhodes19044 wrote:
> 
> 
> Actually, that struct idea is just perfect.
> 
> I definitely was planning on keeping an SRAM version of the 
> variables, then only save the requesite info when necessary.
> 
> One of these will be a "first-run" flag which will allow 
> initialization of the EEPROM, then there are some setting and 
> calibration values to keep.

You can compile the default values of your EEPROM contents into your
code by placing them in the .eeprom section. This way the ISP and/or
JTAG programmer will write them when the FLASH code is written during
production.

As for the syntax of compiling EEPROM variables all I can say is, "I've
done it" but don't have an example under my fingertips or in CVS. IIRC
the variables were defined in a .c source file reserved specifically for
this purpose. In the Makefile this one source file was compiled with an
option to map .data to .eeprom, or some such thing.

It may be one can tag the variable with an attribute to place it in
EEPROM.

One has to be careful with this sort of mapping to EEPROM because these
variables can not be reached without special handling, yet appear to
have addresses same as any other variable.

So one might use a typedef to define the struct which is to contain
EE-backed data. Then use the typedef to allocate one in eeprom and
another in sram.

//  in ee_backed.h file place something like this:
typedef struct {
	uint32_t	serial_number;
	uint8_t		cal[8];
} EE_BACKED;

// in a code file place something like this:
#include "ee_backed.h"
EE_BACKED sram_ee;

// then in a special file just for ee variables:
#include "ee_backed.h"
uint8_t	im_afraid_to_use_byte_0;
EE_BACKED ee_ee.

Then someplace, probably your startup code in main():

eeprom_read_block( &sram_ee, &ee_ee, sizeof(sram_ee) );

The whole point is to make the compiler do the work of allocating a
local copy and of keeping track of where the data was stashed in eeprom.

-- 
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.