Strings going to SRAM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Strings going to SRAM

746 Views
manishsangram
Contributor IV

Hi,

We are using S12ZVMC128 MCU.

All string constants declared in the application code get assigned to SRAM by the compiler. As per what we have read constant strings should be in Flash RAM.

What settings have to be changed / declaration made to avoid this ?

0 Kudos
Reply
2 Replies

560 Views
iggi
NXP Employee
NXP Employee

Hi,

The most probably you didn't put const in front of the string defined:

const char mystring[] = "Hello";

With the const, constant string can be allocated to Flash, otherwise it will be distributed to RAM.

Also, you can use us #pragma declaration define a segment (constant, data, code) and still 'const' is necessary

Syntax:  #pragma CONST_SEG <name>|DEFAULT

This segment must be explicitly allocated within the PLACEMENT block in the link parameter file. For more information, refer to the chapter Linker Issues of the Build Tools Utilities reference manual.

The following listing exemplifies the correct usage of the CONST_SEGpragma:

/* p.h */

#pragma CONST_SEG MY_ROM

extern const int cx;

#pragma CONST_SEG DEFAULT

extern const int y;

/* p.c */

#pragma CONST_SEG MY_RAM

const int cx = 1;

#pragma CONST_SEG DEFAULT

const int cy = 2;

/* main.c */

#include "p.h"

void main(void)

{s = cx + cy;}

Find more info in CodeWarrior Help by searching "S12Z Pragmas".

Regards,

iggi

0 Kudos
Reply

560 Views
manishsangram
Contributor IV

Hello iggi,

Our usage of strings are more inline, meaning we are not declaring string constants at all but directly using them. For example.

sprintf("Hello World");

Why would the above string go to RAM ?

0 Kudos
Reply