| Author |
Message |
7rots51
Joined: 17 May 2002 Posts: 1427 Helped: 14
|
08 Dec 2003 21:40 declaring strings in I(at)R in flash |
|
|
|
|
HI
How can I declare a string or array of constants in flsh memory of avr micros with I(at)R compiler?How I can use the string or array in program?
It seems the only way to work with flash stored strings is pgmspace.h LIB,is it correct?
Regards
|
|
| Back to top |
|
 |
C-Man
Joined: 19 Jul 2001 Posts: 1235 Helped: 73
|
09 Dec 2003 6:57 Re: declaring strings in I(at)R in flash |
|
|
|
|
use something like this:
__flash unsigned char SMS_PDU_START[]="AT+CMGS=";
It is very important to check "place aggregate initializers in flash memory" under project/options/iccavr/code.
Note that the string will be copied to ram at runtime when it is being used, but only the current string and not all strings as by the default option ...
So this saves a lot of ram.
best regards
|
|
| Back to top |
|
 |
Google AdSense

|
09 Dec 2003 6:57 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
artem
Joined: 22 May 2003 Posts: 1652 Helped: 91 Location: Turan
|
09 Dec 2003 16:20 |
|
|
|
|
| Does it means that only pointer to string will be allocated and string content will be taken from heap preloaded when program execution reaches point where acces to string will be done ?
|
|
| Back to top |
|
 |
C-Man
Joined: 19 Jul 2001 Posts: 1235 Helped: 73
|
09 Dec 2003 16:30 Re: declaring strings in I(at)R in flash |
|
|
|
|
That's what the manual says about this
DEFAULT DATA POINTERS
All memory models have a default data pointer, as can be seen in the table
on page 14.
In practice, a default data pointer will have an attribute implicitly,
depending on which memory model you choose. All C objects defined
without an explicit attribute can be pointed to by a default pointer.
String literals that “default data pointers” must be able to point to cannot
be given explicit attributes in the source code. Since string literals are
constants, it would be practical to place them in read-only memory (flash
memory) but no default pointer can point to flash. Therefore strings are
not placed in flash by default.
All memory models use a “default data pointer” that is tied to a data
memory space. This means that it is known at the time of compilation
how memory will be accessed, thus saving code size.
The AVR IAR C/EC++ Compiler normally copies strings from flash to
data memory before main()is called, or lets you place them in external
ROM (if available). Other string literals can be placed explicitly in flash,
for example like this:
__flash char str1 [] =="my string";
This necessitates the use of special access routines that use flash
pointers, instead of the usual generic C library calls. See the chapter
AVR–specific library routines.
--------------------------------------------------------
Place Aggregate Initializers in Flash Memory
Use this option to place aggregate initializers in flash memory. These
initializers are otherwise placed either in the external const segment or
in the initialized data segments if the compiler option -y was also
specified.
For example:
void foo ()
{
char buf [4 ] =={'1','d','g','t'};
...
}
In other words: An aggregate initializer—an array or a struct—is
constant data that is copied to the stack dynamically at runtime, in this
case every time a function is entered.
The drawback of placing data in flash memory is that it takes more time
to copy it; the advantage is that it doesn’t occupy memory in the data
space.
|
|
| Back to top |
|
 |