This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Not initialise static variables



I use latest CCS 5 and 7.4.6 compiler to develop program for C6726.

If I load program into DSP by JTAG USB-510L this text works properly:

static int Var=0;

void func( void )
{
int i = Var; // i = 0
}

If I generate boot by GenAIS.pl and put it into I2C EEPROM, value of "i'" can be random.

If I write and call function Init from begining of the main:

static int Var;

void Init( void )
{
Var = 0;
}

void func( void )
{
int i = Var; // i = 0
}

Variable Var remains equal ziro and from JTAG and from I2C boot.

  • Constantine,

    For future reference, this is a C67x device forum generally for hardware and device questions. You would have received an answer more quickly from the Compiler Forum, since this is a compiler question.

    I assume that the 'static' keyword does not make any difference in your results. It should not, and for this simple example static is not necessary. But maybe you will need to use it later or like to use it by habit.


    The compiler and linker and CCS have two choices of how to initialize variables like your static var=0; Actually, the linker is the one that makes this decision and CCS can use one of the methods while a ROM-based design must use the other.

    The linker has the --ram_model and --rom_model directives to decide between the two methods. An executable can be built to have its variables initialized at load time (--ram_model) which is often useful when using CCS since it can load your initial values into RAM directly. Or, an executable can be built to have its variables initialized at run time (--rom_model) which is required when using a program loaded in ROM since there is no RAM loader available, just the C environment that powers up with all RAM = unknown.

    Please check that you are using --rom_model, or the shorter alias -c, and not --ram_model or its alias -cr.

    I always use --rom_model for all cases so there will never be a problem when I need to burn it into Flash.

    Please let us know if this is the issue. If not, we may need to move the thread elsewhere.

    Regards,
    RandyP

  • Thank you, Randy!

    I shall control ram and rom model options more accurate.

    Can be some differences from using of genAIS.pl for generating of ROM file?

  • Constantine,

    Were you using --ram_model previously, with genAIS.pl?

    With --rom_model, do you get the .cinit section placed in the Flash and now variables are initialized?

    Regards,
    RandyP

  • Thank you, Randy

    I used --ram_model with genAIS.pl last time.

    I used --rom_model before this.

    Now I understand background for this options.

    I can't say what the reason was of program error now. I seek reason of error and change model from --rom to --ram and wrote initialization subprogram and program began work properly.

  • Constantine,

    If you are going to put your program in Flash, or use any simple bootloading method, you need to use --rom_model.

    You can only use --ram_model when you have a complex loader like CCS.

    If you build it the wrong way (--ram_model for bootloaded case), you may be able to work around some problems, but there may be other hidden problems that come up unexpectedly that will be very difficult to debug.

    Regards,
    RandyP

  • Thank you Randy

    I understand what you explained