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.

CCS for MSP430 Launchpad - how to store constant array



Hello,

I installed CCS and trying to store constant array in FLASH. in "hello world" project, I put following:

const int testaray[5] = { 0x11, 0x22, 0x33, 0x44, 0x55 };
const int globconst = 0x4142;

But if I have a look into generated MAP file or HEX, I can see only "globconst" variable. No "testarray" values at all.

Below is the part of LST file. I see that there is different section for "testarray" and it looks it is not linked into HEX. What shall I do to correctly link such application ?

Thank you in advance.

 

      40 000000               .sect   ".const:testaray"
      41                    .clink
      42                    .align  2
      43 000000       testaray:
      44 000000 0011          .field  17,16                   ; testaray[0] @ 0
      45 000002 0022          .field  34,16                   ; testaray[1] @ 16
      46 000004 0033          .field  51,16                   ; testaray[2] @ 32
      47 000006 0044          .field  68,16                   ; testaray[3] @ 48
      48 000008 0055          .field  85,16                   ; testaray[4] @ 64
      49           
      50            $C$DW$6 .dwtag  DW_TAG_variable, DW_AT_name("testaray")
      51                    .dwattr $C$DW$6, DW_AT_TI_symbol_name("testaray")
      52                    .dwattr $C$DW$6, DW_AT_location[DW_OP_addr testaray]
      53                    .dwattr $C$DW$6, DW_AT_type(*$C$DW$T$22)
      54                    .dwattr $C$DW$6, DW_AT_external
      55                    .global globconst
MSP430 Evaluation Assembler PC v3.3.2 Wed Jun 08 15:40:40 2011

Tools Copyright (c) 2003-2010 Texas Instruments Incorporated
C:\DOCUME~1\cz2p10h1\LOCALS~1\Temp\0474411                           PAGE    2

      56 000000               .sect   ".const"
      57                    .align  2
      58 000000       globconst:
      59 000000 4142          .field  16706,16                        ; globconst @ 0
      60           
      61            $C$DW$7 .dwtag  DW_TAG_variable, DW_AT_name("globconst")
      62                    .dwattr $C$DW$7, DW_AT_TI_symbol_name("globconst")
      63                    .dwattr $C$DW$7, DW_AT_location[DW_OP_addr globconst]
      64                    .dwattr $C$DW$7, DW_AT_type(*$C$DW$T$21)
      65                    .dwattr $C$DW$7, DW_AT_external
      66            ;       D:\opt\CCS_MSP430\ccsv4\tools\compiler\msp430\bin\opt430.exe C:\\DOCUME~1\\cz2p10h1\\LOCALS~1\
      67 000000               .sect   ".text:main"
      68                    .align  2
      69                    .clink
      70                    .global main

  • The linker does not link code or data that is never referenced. So if you do not access testarray anywhere in your code, then it is not linked.

    That's what the linker is supposed to do.

  • Yes, you are right, thank you. I forgot to use the function which uses defined array.

    Anyway, "const int" is not excluded even if it is not used ? Is that correct in this case ?

  • VaclavPeroutka said:
    Anyway, "const int" is not excluded even if it is not used ? Is that correct in this case ?

    Honestly, I don't know. I had expected it to be excluded from link too.

    However, liker algorithms are an implementation issue. There is no global standard. The MSPGCC linker, for example, includes everything that is in the same compilation unit (c source file) if at least one element is referenced from outside. You'll need special compiler/linker flags to make it discard unreferenced functions if there is a referenced one in the same c file.

    Maybe in your case, the linker handles simple types (int etc.) differently from complex types (structs, arrays). Perhaps it is documented somewhere in the docs, or maybe only the prorammer knows.

**Attention** This is a public forum