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.

Compiler/MSP430FR2311: Initialization of variables at load time or run time.

Part Number: MSP430FR2311

Tool/software: TI C/C++ Compiler

Hi Champs,

Initialization of variables at load time(--ram_model) enhances performance by reducing boot time and by saving the memory used by the initialization tables.

It seems that there are benefits if I initialize variables at load time, is there any drawbacks using --ram_model for variables initialization? Please advise if any idea, thanks.

Best regards,

Luke

  • When you build with --ram_model, your system must include a loader which can read a .out file, find the initialization records, process those records, and thereby initialize the relevant variables.  Systems which boot themselves do not have such a loader, and thus must use --rom_model.

    As an example of a system which could use --ram_model ... Suppose this system has an ARM CPU and DSP CPU, and Linux is running on the ARM.  The ARM side could have a loader that can load a .out file on to the DSP and start it running.  In such a case, the DSP executable could be built with --ram_model.

    Thanks and regards,

    -George

  • George,

    I am using --ram_model and initialize the variables by myself in .c file.

    Is this method okay? Is there anything wrong I missed? Please advise, thanks.

    Regards,
    Luke
  • If you are executing under CCS, it will work.  Because CCS has a loader that can process the variable initialization table.  Have you tried executing while not under CCS?  What happens?

    Thanks and regards

    -George

  • Hi George,

    I used a simple code below to evaluate this case,

    #include <msp430.h>

    unsigned char counter;

    /**
    * main.c
    */
    void main(void)
    {
       WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer

       counter = 5;

       P1DIR |= BIT0;
       P2DIR |= BIT0;
       //-----------------------------------------------------------------------------------
       // Disable the GPIO power-on default high-impedance mode to activate previously
       // configured port settings
       PM5CTL0 &= ~LOCKLPM5;

       while(1)
       {
          if(counter == 5)
          {
             P2OUT &= ~BIT0;     // turn off GREEN LED
             P1OUT ^= BIT0;      // toggle RED LED
             __delay_cycles(500000);
          }
          else
          {
             P1OUT &= ~BIT0;     // turn off RED LED
             P2OUT ^= BIT0;      // toggle GREEN LED
             __delay_cycles(500000);
          }
       }
    }

    I get two FRAM used sizes below when I use both --rom_model and --ram_model, and I get same results when running the code on standalone FR2311 LaunchPad with CCS, the RED LED is toggled.

    When use --rom_model
    name origin   length   used     unused   attr    fill
    ------------------------------------------------------------
    BSL0 00001000 00000800 00000000 00000800 RWIX
    RAM  00002000 00000400 000000a1 0000035f RWIX
    FRAM 0000f100 00000e80 0000028e 00000b08 RWIX

    When use --ram_model
    name origin   length   used     unused   attr    fill
    ------------------------------------------------------------
    BSL0 00001000 00000800 00000000 00000800 RWIX
    RAM  00002000 00000400 000000a1 0000035f RWIX
    FRAM 0000f100 00000e80 00000086 00000e00 RWIX

    Any comment please?

    Best regards,
    Luke

  • Luke Chen said:
    I get same results when running the code on standalone FR2311 LaunchPad with CCS, the RED LED is toggled.

    The key words in that sentence are "with CCS".  CCS has a loader that can find the initialization records and process them, thus initializing the global variables.  It is very unlikely your end application will have a loader like that.  If that is the case, you have to use --rom_model.

    Thanks and regards,

    -George

  • Hi George,

    Sorry for the typo. I run my sample code with both --ram_model and --rom_model WITHOUT CCS and get same results, you can see I initialize the global variable in main() function. Believe that you can try it if you have any MSP430 LaunchPad on hand.

    When using --rom_model, run time support library will spend more than 700 bytes to initial variables, even I just declare one global variable. This is a memory size problem when customers use 2KB memory size MSP430. This is the reason I am trying --ram_model to bypass library variable initialization process and save memory size.

    My question is that when I use --ram_model, is there anything else we should take care, besides variables initialization?

    Best regards,
    Luke

  • Luke Chen said:
    I run my sample code with both --ram_model and --rom_model WITHOUT CCS and get same results, you can see I initialize the global variable in main() function. Believe that you can try it if you have any MSP430 LaunchPad on hand.

    I'm not aware of any method for running code on a MSP430 LaunchPad that does not use CCS.  Please point me to the documentation which describes, in detail, how that is done.

    Thanks and regards,

    -George

  • Luke Chen said:
    My question is that when I use --ram_model, is there anything else we should take care, besides variables initialization?

    In your application code you can ensure the variables are explicitly assigned before they are read by the application.

    If you are linking library functions which are written assuming that variables will be set using initializers (.data section) or zero initialized (.bss section), then using --ram_model without a loader will break the library code.

  • George,

    I use CCS to develop software and download to MSP430, then disconnect emulator, restart FR2311 LaunchPad and check result.

    This is what I mean to run the code without CCS.

    Regards,
    Luke
  • I owe you an apology.  I missed an important detail in the code example you posted on June 26.  Here it is ...

    Luke Chen said:

    unsigned char counter;

    /**
    * main.c
    */
    void main(void)
    {
       WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer

       counter = 5;

    The variable counter is initialized by an assignment statement in the function main.  Therefore counter is initialized to 5 without regard to whether you use --rom_model or --ram_model.  If you had written it ...

    unsigned char counter = 5;     // init counter here
    
    /**
    * main.c
    */
    void main(void)
    {
       WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
    
       /* counter = 5; */          // no init of counter in main 

    ... then the choice of --ram_model or --rom_model matters just as I describe.

    So, in the very narrow case that you present, you can use either --ram_model or --rom_model, and everything still works.  In the general case, which I assumed, you can use --ram_model only when an intelligent loader is part of the overall system.

    Thanks and regards,

    -George