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.

Static and Global variables aren't initialized in CCS v4

Other Parts Discussed in Thread: AM1808, OMAP-L138

Can someone tell me why my global and static variables are not being initialized even though my code specifically initializes them?

I'm using CCS v4.1.1 and am compiling the UBL modified for my target using an AM1808 processor.

 

if I use the const keyword I can get it to initialize.

const GPIOP pGPIO = GPIO_BASE_ADDRESS;

const pinmux_config pinmux_gpio[] =
{
   { 0,0x88880888},    // PINMUX0   
   { 1,0x88080880},    // PINMUX1  
   { 2,0x44444448},    // PINMUX2  
   { 3,0x00440000},    // PINMUX3  
   { 4,0x88008844},    // PINMUX4  
   { 5,0x00888888},    // PINMUX5  
   {13,0x88888000},    // PINMUX13 
   {14,0x00000088},    // PINMUX14 
   {16,0x88888800},    // PINMUX16 
   {17,0x00000080},    // PINMUX17 
   {18,0x88800000},    // PINMUX18 
   {19,0x08000088},    // PINMUX19
   {MAXMUXREGS,0},    // Last entry in table
};

 

but global variables like this won't initialize. Putting static in front doesn't work either.

Uint8 ledState = 0;

static Uint8 ledState = 0;

I'm working in the debugger, but believe that even running out of flash has the same result that the variables aren't initialized unless I specifically do it in code or use the const keyword. I know this because it was crashing when I didn't use const.

Is there something in the map or listing files that will tell me if the variable is being initialized?

Here are my linker options:

-z -m"C:/P4/Proj_10083_UBL/dev/DEV_UBL/OMAP-L138_FlashAndBootUtils_2_30/OMAP-L138/CCS/UBL_ARM/NOR/UBL_NOR.map" --warn_sections -i"C:/Program Files/Texas Instruments/ccsv4/tools/compiler/tms470/lib" -i"C:/Program Files/Texas Instruments/ccsv4/tools/compiler/tms470/include" -i"C:/P4/Proj_10083_UBL/dev/DEV_UBL/OMAP-L138_FlashAndBootUtils_2_30/OMAP-L138/CCS/UBL_ARM/UBL_NOR" -i"C:/P4/Proj_10083_UBL/dev/DEV_UBL/OMAP-L138_FlashAndBootUtils_2_30/OMAP-L138/CCS/UBL_ARM" --reread_libs --retain="*(.selfcopy)" --rom_model --fill_value=0xBEEF --compress_dwarf=off

According to the C compiler guide using the --rom_model should cause initialized variables to be initialized on load.

 

  • I'm pretty sure this is not a compiler issue, but a problem with how you are configuring the system.  I'll move this thread to the ARM18x processor forum.

    Thanks and regards,

    -George

  • The ".cinit" section contains the initial value of the global variables. Can you please check if this section is properly placed in the memory.

    Regards,
    Gaurav

  • Thank you for your quick response.

    Here is what I get (in the map file) using the -rom_model

    The line of code is Uint8 ledState = 5;

    .cinit     0    80009ca0    00000070    
                      80009ca0    00000017     (.cinit..data.load) [load image, compression = rle]
                      80009cb7    00000001     --HOLE-- [fill = 0000beef]
                      80009cb8    0000000c     (__TI_handler_table)
                      80009cc4    00000004     --HOLE-- [fill = 0000beef]
                      80009cc8    00000008     (.cinit..bss.load) [load image, compression = zero_init]
                      80009cd0    00000008     (.cinit..fiqstack.load) [load image, compression = zero_init]
                      80009cd8    00000008     (.cinit..irqstack.load) [load image, compression = zero_init]
                      80009ce0    00000008     (.cinit..svcstack.load) [load image, compression = zero_init]
                      80009ce8    00000028     (__TI_cinit_table)

    The listing file shows this

          56                            .dwattr $C$DW$5, DW_AT_decl_column(0x0c)
          57                            .global ledState
          58 00000000                   .data
          59                            .align  1
          60 00000000           ledState:
          61 00000000 00000005          .field  5,8                     ; ledState @ 0

    When I load the program using the debugger in Code Composer

    When I use the -ram_mode my variables get initialized when I load the program using the debugger.But section 6.9.4 of SPNU151E seems to indicate that I shouldn't use this option if my code is burned to flash. It says "A loader (which is not part of the compiler package) must be able to perform the following tasks to use initialization at load time:"

    I understood this to mean that I must provide a piece of code that copies it from flash to ram at run time. However, at least in the debugger, using this option seems to have the desired result. My variables are initialized. The sections look like this.

    .cinit     0    80000000    00000000     UNINITIALIZED

    .data      0    80009924    000001ad    
                      80009924    00000194     irq.obj (.data:sysISRtbl)
                      80009ab8    00000008     rtsv4_T_le_eabi.lib : _lock.obj (.data)
                      80009ac0    00000008                         : exit.obj (.data)
                      80009ac8    00000004                         : stkdepth_vars.obj (.data)
                      80009acc    00000004     ubl.obj (.data)
                      80009ad0    00000001     irq.obj (.data)
    From the listing I get

          56                            .dwattr $C$DW$5, DW_AT_decl_column(0x0c)
          57                            .global ledState
          58 00000000                   .data
          59                            .align  1
          60 00000000           ledState:
          61 00000000 00000005          .field  5,8                     ; ledState @ 0
          62                   
          63                    $C$DW$6 .dwtag  DW_TAG_variable, DW_AT_name("ledState")
          64                            .dwattr $C$DW$6, DW_AT_TI_symbol_name("ledState")
          65                            .dwattr $C$DW$6, DW_AT_location[DW_OP_addr ledState]
          66                            .dwattr $C$DW$6, DW_AT_type(*$C$DW$T$24)
          67                            .dwattr $C$DW$6, DW_AT_external
          68                            .dwattr $C$DW$6, DW_AT_decl_file("C:/P4/Proj_10083_UBL/dev/DEV_UBL/OMAP-L138_FlashAndBootUtils
          69                            .dwattr $C$DW$6, DW_AT_decl_line(0x0b)
          70                            .dwattr $C$DW$6, DW_AT_decl_column(0x07)

    And voila my variable is initialized.

    So I don't understand really which one I should use. Hopefully you can explain to me why the option I think shouldn't work does, and the one that I think should work doesn't.

  • Here is my linker command file.

     

    -e _init_stack
    --retain=INT_VECS

    -l rtsv4_T_le_eabi.lib
    IRAMStart  = 0x80000000;
    IRAMSize   = 0x00008000;
    DRAMStart  = 0x80000000;
    DRAMSize   = 0x00008000;

    -heap 0x1000
    -stack 0x800

    ASYNC_MEM_START    = 0x62000000;

    INTERNAL_RAM_START = 0x80000000;
    INTERNAL_RAM_SIZE  = 0x0001F800;
    STACK_START = INTERNAL_RAM_START + INTERNAL_RAM_SIZE;


    MEMORY
    {
      ARM_I_IVT       (RX)  : origin = 0xFFFFD000   length = 0x00000020
      ARMRAM                (RWX) : origin = 0xFFFF0000    length = 0x00002000
     
      shared_ram      (RWX) : origin = 0x80000000   length = 0x0001F800
      UBL_STACK       (RWX) : origin = 0x8001F800   length = 0x00000800
      UBL_DRAM        (RWX) : origin = 0x40000000   length = 0x02000000
    }
    SECTIONS
    {
        .boot            > shared_ram
       .text       > shared_ram        /* Executable Code                    */
       .const      > shared_ram        /* Constant Data                        */
       .bss        > shared_ram        /* Global & Static Variables         */
       .far        > shared_ram        /* Far Global & Static Variables    */
       .switch     > shared_ram        /* Jump Tables                            */
       .data       > shared_ram
       .cinit      > shared_ram        /* Initialization Tables            */
       .sysmem     > shared_ram        /* Dynamic Memory Allocation Area*/
       .cio        > shared_ram        /* C I/O Buffer                        */
        .svcstack    > shared_ram        /* Supervisor Mode Stack            */
        .irqstack    > shared_ram        /* IRQ Interrupt Stack                */
        .fiqstack    > shared_ram        /* FIQ Interrupt Stack                */
        .intvecs        > ARMRAM            /* Interrupt Vectors                */
      .stack :
      {
        .+=0x0800;
      } run = UBL_STACK, type=DSECT, SIZE(STACK_SIZE)
      .ddr_mem :
      {
        . += 0x02000000;
      } run = UBL_DRAM, type=DSECT, RUN_START(EXTERNAL_RAM_START), RUN_END(EXTERNAL_RAM_END), SIZE(EXTERNAL_RAM_SIZE)
    }