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

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

Re: [avr-gcc-list] String Arrays in FLASH & gccavr 3.0


From: Christoph Plattner
Subject: Re: [avr-gcc-list] String Arrays in FLASH & gccavr 3.0
Date: Tue, 07 Aug 2001 10:02:06 +0200

Hello,

        I always use this order ....

<type> <variable> __attribute__((progmem)) = 
{
        xxxxx
};

But this seems to be detail. Your problem is another:

(1) Here the compiler seems to ignore the __attribute__, and there is
another error, see below.

(2) The strings are correctly embedded in progmem, for the char
pinters it ignores the __attribute__ again ...

The point is: Youwant to do another thing as far I can see.
You want to have the whole character array in the FLASH !!

char char F_strings [][] __attribute__((progmem)) = 
{
     "Menu1",
     "Menu2",
     "Menu3"
};

Important is the "char X [][]" instead of "char * X []".
In one case you have an array:

F_strings:  Byte  0.. 5 "Menu1\0"
            Byte  6..11 "Menu2\0"
            Byte 12..17 "Menu3\0"

In the other case you have an array of POINTERS to the string

F_strings:  Byte  0.. 1 pointer to string 1
            Byte  2.. 3 pointer to string 2
            Byte  4.. 5 pointer to string 3

The pointers in this way is not abkle to be handled in the FLASH
very well, as the pointers in FLASH must have an another data type,
as for example the ATmega103 need 3 byte pointers here (128KB Flash).

In both methods you access the stings as
        F_strings [i] !

To use the string in the system you can do

        strcpy_P (buf, F_strings [i]);

With friendly regards
        Christoph


address@hidden wrote:
> 
> Greetings,
> 
> I am wondering if anyone has a better method of defining arrays of null
> terminated strings in FLASH.   With the additional overhead of reading
> constant byte data from FLASH, reading pointers to strings in FLASH does
> present some difficulty.   It is easy to write a macro to do the two byte
> to pointer conversion, what I am having trouble with is *forcing* gcc 3.0
> to put the pointer (address) in FLASH and not define it as constant data in
> RAM.   Defining my constant strings such;
> 
> static __attribute__ ((progmem)) char* F_strings[] =
> {
>      "Menu1",
>      "Menu2",
>      "Menu3"
> };
> 
> Results in the whole lot being placed in RAM, seems to ignore the attribute
> directive.   Change it thus;
> 
> static __attribute__ ((progmem)) char c_string1[] = "Menu1";
> static __attribute__ ((progmem)) char c_string2[] = "Menu2";
> static __attribute__ ((progmem)) char c_string3[] = "Menu3";
> 
> static __attribute__ ((progmem)) char* F_strings[] =
> {
>      c_string1,
>      c_string2,
>      c_string3
> };
> 
> Results in c_string1,2 &3 being placed in FLASH, but F_strings is still
> retained in RAM (still ignores attribute), albeit this much smaller than
> the first case.   Now how can I force the compiler to put F_strings[] in
> FLASH aswell so I can point my macros at them ?   I am sure this is a
> problem with my limited understanding of gccavr, I have done this
> previously with Hitachi and a PC, but on those projects I didn't care if my
> pointers and string data were in RAM or ROM.   Any clues ?
> 
> Matthew
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list

-- 
  +--------V--------+   address@hidden
  |  A L C A T E L  |   -----------------------------
  +-----------------+   Phone: +43 1 27722 3706 
         T A S          Fax:   +43 1 27722 3955



reply via email to

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