"Strings" in program memory?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
GuNo_288966
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

Hi,

   

for a project with a CY8Y5856 with a display I need to store lots of text to be displayed.

   

How can I put the text into the program memory so that it does not waste RAM?

   

The text should be stored in a struct or at least in an array.

   

Best regards,

   

Günter

0 Likes
8 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

 How many bytes you are looking to store?

   

odissey1

0 Likes
EvPa_264126
Level 7
Level 7
500 replies posted 250 replies posted 100 likes received

   

for PSoC3 I use the following:

   

   

const uint8 code TestStr[1024]={0};

   

   

for PSoC4 and 5 seems to need another ...

0 Likes
GuNo_288966
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

Hi,

   

there will be about 400 "strings" of 20 bytes each (several languages on the display).

   

It seems that the "const" keyword does the job for PSoC5LP.

   

Thanks,

   

Günter

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Re the ARM compilers -

   

 

   

    

   

                    

   

I would have liked to see a different solution like a "flash" qualifier, but GCC developers have choosen a different solution. Now the "const" qualifier has two different meanings depending on the context it appears.

   

Used in a parameter-list the consequences are: the parameter will not be modified by a direct assignment.

   

Used in a variable declaration and followed by an initialization the variable will be put into the code area which will be flash memory in all embeddeds.

   

This improvement is not ARM specific but works in GCC generally.

   

http://www.keil.com/support/docs/2829.htm     Abs variable location Keil and ARM GCC

   

 

   

Regards, Dana.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Actually its not really something gcc invented. The different meanings of const are defined in the C / C++ standards. Its merely an optimization gcc can do that const strings / fields can be put to flash memory.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Hli, can you point put where in the standard const adresses storage class ?

   

I cannot seem to find it.

   

 

   

    

   

          http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899

   

 

   

Regards, Dana.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Like I said, the C/C++ standard addresses the different semantics of const (namely that the affected variable / field is not to be modified, and depending on context is either a requirement or a guarantee).

   

GCC (when compiling for embedded environments) uses this information to handle variable placement in flash or volatile memory. So in that sense GCC has added an additional meaning to const, but it still has the other one as before.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Excerpt from AN89610    www.cypress.com/

   
    It is more efficient to have all constant data, for example fixed data tables in arrays, be located in flash, however the default is to place them in SRAM.   
   
    To force placement of a variable in     flash, set its type to const and explicitly initialize it,   
   
    for example:   
   
    uint32 const var_in_flash = 0x1234567   
   

Bob

0 Likes