electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

declaring strings in I(at)R in flash


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> declaring strings in I(at)R in flash
Author Message
7rots51



Joined: 17 May 2002
Posts: 1427
Helped: 14


Post08 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


Post09 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
Google Adsense




Post09 Dec 2003 6:57   

Ads




Back to top
artem



Joined: 22 May 2003
Posts: 1652
Helped: 91
Location: Turan


Post09 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


Post09 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
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> declaring strings in I(at)R in flash
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
Declaring variables in AT 89C51 (3)
Declaring Variables on Bank1 of PIC16F877A (1)
Declaring Member Variable in Visual C++ (8)
Verilog: Declaring port instances (8)
strings in verilog (3)
strings and arrays in c (4)
Tables and strings (2)
Transfering Strings Serially (5)
format change in Altium of text strings (2)
Segmentation fault when trying to copy strings (2)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS