How to avoid RAM cleaned in start up for S12ZVML

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

How to avoid RAM cleaned in start up for S12ZVML

1,789 Views
dannydeng
Contributor III

Dears,

   Do you have any idea to avoid RAM cleaned in start up for S12ZVML, thanks,

6 Replies

1,341 Views
RadekS
NXP Employee
NXP Employee

Hi Ray,

Pratik is right, you may exclude part of RAM from linker usage and access that part of RAM by pointers.

If you want to use slightly more comfortable way and define any variable at that memory, you should tell your needs to the linker by NO_INIT qualifier. Such memory will not be initialized by _Startup() code.

 

For example:

In prm linker file:

SEGMENTS

//…

   RAM           = READ_WRITE  0x001000 TO 0x001FFF;

   UNINITIALIZED_RAM = NO_INIT 0x002000 TO 0x002FFF;

//…

END

PLACEMENT

//…

   DEFAULT_RAM INTO   RAM;

   MY_RAM INTO UNINITIALIZED_RAM;

//…

END

 

In *.c file:

#pragma DATA_SEG MY_RAM

unsigned int my_variable;

#pragma DATA_SEG DEFAULT

Note: we should avoid using init value for variables in that memory like unsigned int my_variable = 0x1234;.

 

More details is in
c:\Freescale\CW MCU v10.7\MCU\Help\PDF\MCU_Build_Tools_Utilities.pdf

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,341 Views
lipengfei
Contributor II

Hello Radek,

      there is a note in your reply,such as

Note: we should avoid using init value for variables in that memory like unsigned int my_variable = 0x1234;.

Can you explain it more,

I am so confused,

i got a problem that everytime i powered up the MCU ,the FirmwareUsbRequestFlag value is easy to change,

111  ,   127 ,   50 etc.

i don't know why, Can you explain it ??

 #pragma DATA_SEG RAM_TEST
unsigned char FirmwareUsbRequestFlag = 0;
#pragma DATA_SEG DEFAULT 

have a great day!!

i appreciate your reply.thanks.

0 Kudos
Reply

1,341 Views
RadekS
NXP Employee
NXP Employee

Hi Li Peng Fei,

The RAM content after power-on reset is random. The RAM content is not affected in the case of system resets like COP,  Low Voltage reset,…

 

When you specify some specific default value for a variable like:

unsigned char FirmwareUsbRequestFlag = 100;

The startup code will read this value from flash and store it at the FirmwareUsbRequestFlag position in RAM.

If you do not specify a specific default value, like:

unsigned char FirmwareUsbRequestFlag;

The startup code will clear FirmwareUsbRequestFlag position in RAM (=0).

 

When you place your FirmwareUsbRequestFlag variable into the NO_INIT segment, the startup code will simply ignore this variable = no load from flash/ no clearing. So, variable value will be random after Power-On reset and stay unchanged after other resets.

The reset type may be checked by flags like PORF. Please be aware, that you have to clear this flag after reading for correct reset type detection.

For example:

  if (CPMURFLG_PORF)
    {
      FirmwareUsbRequestFlag = 0;
    }
  CPMURFLG = 0x6B; //clear all flags

I hope it helps you.

 

Have a great day,
Radek

1,341 Views
lipengfei
Contributor II

Hi, Radek,

      You are so kindness, your reply helps me a lot.

Now i delete the un_init variables,instead,directly use the CRGFLG_PORF as the dection of  i should press the button when the mcu was power-on but not when the mcu after other resets.

For example:

if(CRGFLG_PORF == 1)
while(!PT1AD1_PT1AD16);

thanks a lot.

0 Kudos
Reply

1,341 Views
RadekS
NXP Employee
NXP Employee

Hi Li Peng Fei,

You are welcome.

I am glad that it works now according your needs.

 

Note: some more probably useful details about object allocation may be found at: https://community.nxp.com/docs/DOC-334387

 

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,341 Views
pratikpatil
Contributor I

Hello Ray,

You can avoid RAM clean up by reserving RAM space in linker script (.prm file)

In linker file this section is mentioned as RAM

example :

   SEGMENTS

   RAM 0x001000 to 0x002FFF;

   END


   PLACEMENT

   DEFAULT_RAM INTO   RAM;

Modify this code as below:

   SEGMENTS

   RESERVED_RAM 0x001000 TO 0x001003;

   RAM                         0x001003 to 0x002FFF;

   END

Now you directly can write at reserved location and it wont be cleaned even after MCU reset