shrikant oak

Uninitialized variable initialized to zero at power up?

Discussion created by shrikant oak on Aug 8, 2012
Latest reply on Jul 10, 2015 by Steffen Rose



I am using CW  Version: 10.2 (Build Id:120126) for MPC5604P. I am in a need to place a variable in an uninitialized separate memory segment(mode_flag). For this i made following changes in my linker file

    resetvector:           org = 0x00000000,   len = 0x00000008
    init:                   org = 0x00000020,   len = 0x00000FE0
    exception_handlers:    org = 0x00001000,   len = 0x00001000
    internal_flash:        org = 0x00002000,   len = 0x0007E000

    internal_ram:          org = 0x40000000,   len = 0x00008000
    heap  :                org = 0x40008000,   len = 0x00001000
    stack :                org = 0x40009000,   len = 0x00000FFC
    mode_flag :                org = 0x40009FFC,   len = 0x00000004


    GROUP : {
       .mode_flag ALIGN (0x4) : {}
    } > mode_flag


& in  c file


#pragma section RW "mode_flag" ".mode_flag"
__declspec (section "mode_flag") uint32_t RespModeFlag;

With this modifications i am able to place the variable within the uninitialized segment created.


in .MAP file


.mode_flag section layout
  Starting        Virtual  File
  address  Size   address  offset
  00000000 000004 40009ffc 000038a8  1 .mode_flag     Diag.obj
  00000000 000004 40009ffc 000038a8  4 RespModeFlag     Diag.obj


As mentioned earlier this is an uninitialized segment, but after power on this segment is initialized to zero in "__asm void INIT_Derivative()" function. When checked with this function, instruction "li r12,320" which loads a fixed count for a loop to initialize the RAM. When count changed from 320 to 319 it works (As uninitialized segment is placed at the top of RAM/ last 4 bytes of RAM), but then it gets initialized in one of the library function "__init_bss_section".


It will be a great help if anyone suggest how to proceed in order to not to initialize the RAM segment after Power up.

Thanks & Regards,