Global Static Variables

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

Global Static Variables

901 Views
salman83
Contributor II

Hi,

I encountered a problem while programming the 52259 Demo kit. All my global static variables are initialized to zero even i have explicitly initialized them to their respective values.

 

Is there anyway so that the explicit values for the variables do not get initialized to zero. I do not want to declare the variables to const.

 

Regards.

Labels (1)
3 Replies

384 Views
CrasyCat
Specialist III

Hello

I assume you intend the download code to the target board and you want to get the initialization values copied from ROM to RAM during application startup. Am I right?

I assume you are using CodeWarrior for MCU V10.x. Am I right?

If this is what you are looking for, I would recommend you to build the "MCF52259_Internal_Flash" configuration.

This build configuration is created automatically when you create your project from the v10.x project wizard.

To make sure you build this configuration:

  • Click right on the project in the CodeWarrior Project Windows
  • Select Build Configuration > Set ActiveMCF52259_Internal_Flash.
  • Now Build the project.

This project should generate the required data to get initialization data copied from ROM to RAM at startup.

The whole trick is implemented in the linker file MCF52259_Internal_Flash.lcf.

CrasyCat

0 Kudos
Reply

384 Views
salman83
Contributor II

Thanks for the quick reply.

Yes, I am copying from ROM to RAM. But in ROM, my data is initialized to zero.

I already set the active configuration to Flash. My IDE is

CodeWarrior Development Studio for ColdFire Architectures Version 7.2 Build 91218.

Here is my linker script: -

# Sample Linker Command File for CodeWarrior for ColdFire

KEEP_SECTION { .vectortable }

KEEP_SECTION { .cfmconfig }

# Memory ranges

MEMORY {

   interrupts (RX)  : ORIGIN = 0x00000000, LENGTH = 0x00000400 # 1K Vector

   cfmprotect (RX)  : ORIGIN = 0x00000400, LENGTH = 0x00000020 # 32 bytes Flash Configuration Settings

   flash (RX)  : ORIGIN = 0x00000420, LENGTH = 0x0007FBE0 # 512K - 0x420 Flash

   ram (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00010000 # 64K RAM

   ipsbar (RWX) : ORIGIN = 0x40000000, LENGTH = 0x0001FFFF

}

SECTIONS {

  #########################################################

  # Vector Section

  .vectors : {

  ___VECTOR_BASE = . ;

  vectors.c (.vectortable)

  } > interrupts

  #########################################################

  # ColdFire Flash Configuration Section

  .cfm : {

  *(.cfmconfig)

  . = ALIGN(0x4);

  } > cfmprotect

  #########################################################

  # Code Section

  .code : {

  startcf.c (.text)

  *(.text)

  . = ALIGN(0x10);

     *(.rodata)

     . = ALIGN(0x10);

  ___DATA_ROM = . ;

  } > flash

  #########################################################

  # Initialized Data Section

  .data : AT(___DATA_ROM) {

  ___BDT_START = . ;

  . = . + 512 ;

  ___BDT_END = . ;

     . = ALIGN (0x4);

  ___DATA_RAM = . ;

  ___DATA_RAM_START = . ;

     ___DATA_START = . ;

  ___sinit__     = .;

     STATICINIT

     *(.data)

     *(.relocate_code)

     . = ALIGN (0x4);

     ___DATA_END = . ;

     ___SDATA_START = . ;

     *(.sdata)

     . = ALIGN (0x4);

     ___SDATA_END = . ;

  } > ram

  #########################################################

  # Uninitialized Data Section

  .bss : {

     ___SBSS_START = . ;

     *(.sbss)

     . = ALIGN(0x4);

     *(SCOMMON)

     . = ALIGN(0x4);

     ___SBSS_END = . ;

     ___BSS_START = . ;

     *(.bss)

     *(COMMON)

     . = ALIGN(0x4);

     ___BSS_END = . ;

  ___DATA_RAM_END = . ;

  } >> ram

  ___FLASHBAR = 0x00000000;

  ___FLASHBAR_SIZE = 0x00080000;

  ___RAMBAR = ADDR(ram);

  ___RAMBAR_SIZE = 0x00010000;

  ___IPSBAR = ADDR(ipsbar);

  ___SP_INIT = (___RAMBAR - (___RAMBAR % 4)) + ___RAMBAR_SIZE - 4;

  ___SP_END = ___SP_INIT - 0x00000400;

  ___SP_AFTER_RESET = ___RAMBAR + ___RAMBAR_SIZE - 4;

}

0 Kudos
Reply

384 Views
CrasyCat
Specialist III

Hello

   If you are using CodeWarrior for Coldfire V7.2, then you need to build build target INTERNAL_FLASH.

   You can select the build target from the combo box on the left of the .mcp window.

  The linker file generated by the project wizard for INTERNAL FLASH build target is called MCF52259_INTERNAL_FLASH.lcf.

  It contains the appropriate command to generate the initialization data to be copied from ROM to RAM.

  Not sure what you did modify in your .lcf file, but you find attached the .lcf file generated by the wizard for a

  MCF52259 MCU INTERNAL_FLASH build target.

  You may have to modify it to match your own project.

  The portion of the file generating the copy down information is encoded in the section .romp.

CrasyCat