How to place variable in DataFlash (IAR C)

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

Hi all!
A question to all who uses IAR EWAVR. I have DataFlash chip attached to mega128. Does anybody know, how to declare variables in DataFlash? Of course I don't mean "full-featured" variables with full access thru identifier. I need only to declare them in order to give each variable its own address. But the only way I see is like this:

#define var1adr 0x0000
#define var1length 2
#define var2adr var1adr+var1length
and so on; and to use __hugeflash 3-byte pointer to that "variables".

I tried to use __huge keyword before var identifier, but unsuccessfully.

Is there another, easier way to do this?

Cats never lie. At least, they do this rarely.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As you are only defineing numbers to be used later as address there is no requirement for huge or anything else.

I am assuming as you mentioned data flash you are using a device with a serial interface. So the address carrier for tahe needs to be declared as long int

#define varlocaddr 57906
#define PuntNameAddr varlocaddr+6700

unsigned long int DataFlashAddr;
DataFlashAddr= PuntNameAddr;

Mike

Keep it simple it will not bite as hard

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tnank you Mike,

the only reason why I decided to use __hugeflash* is because it is 3 bytes long, instead of 4 taken by longint; I have to store and manage a lot of such pointers in my project.

Cats never lie. At least, they do this rarely.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you're looking for the offsetof() macro. This will allow you to use
a struct to describe the layout of the DataFlash area, but then extract
the offsets (from 0) for the actual references. You're thus using the C
compiler to manage the addresses, even though you can't use the struct
directly (with a pointer) to reference the data.

offsetof() is quasi-standard, i.e. it's not ANSI but appears in maybe 80%
of the C development packages I've used (WinAVR is unfortunately not
among them, so I can't quote at the moment). First place to look would be
stddef.h.

If you don't find it, it looks roughly (untested) like this:

#define offsetof(_structtype,_member) \
      ((size_t) ( &(((_structtype *)0)->(_member)) ))

struct DF_memory {
   int Var1;
   char Var2[5];
};

...
     second_flash_char = DF_read(offsetof(struct DF_memory),Var2[1]);
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello,
there is a very simple way to solve your problem.
use the keyword __eeprom for your variable which should be placed into the dataflash. then you have to adapt the eeprom function which can be found in eeprom.s90 to you needs.
search the user's guide for the keyword __eeprom and you will find all the information you need.

regards
gerhard