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.

spreading data table over info segments B and C

Other Parts Discussed in Thread: MSP430G2553

I want to use a 128 bytes data table in CCS for an MSP device that has 64 bytes info sections.

Therefore i want to spread it out between infoC and infoB

currently i use the code below which is bad for two reasons:

- I am accessing data[] for higher indices than it was declared (knowing that data2 will be behind it)

- I need the first line in main to convince the compiler to also put data2 in the memory, otherwise it will assume I am stupid and need some help deleting unused variables.

Is there a way to do this while:

- keeping the data in the info sections (I want to keep memory usage as small as possible)

- losing the dummy read (first line of main() ) to trick the compiler.

- keeping the data in the program (I don't want to do a separate data upload step in CCS each time)

#pragma location=0x1080   // second part of data table, stored at address of info segment B
const unsigned char data2[64] = {34,39,46,52,59,67,74,82,90,97,104,111,116,121,124,127,127,127,124,121,116,111,104,97,90,82,74,67,59,52,46,39,34,29,24,20,17,13,11,8,6,5,3,2,1,0,0,0,0,0,0,0,1,2,3,5,6,8,11,13,17,20,24,29
#pragma location=0x1040   // first part of data table, stored at address of info segment C
const unsigned char data[64] =   {74,81,87,94,102,109,116,124,132,139,147,155,163,170,178,185,192,199,205,212,218,223,229,233,238,242,245,248,251,253,254,255,255,255,254,253,251,248,245,242,238,233,229,223,218,212,205,199,192,185,178,170,163,155,147,139,132,124,116,109,102,94,87,81};

int main(int argc, char *argv[])
{
    int T, dummy;

    dummy=data2[0];                                    // (:) needed to keep compiler from throwing it out :-)

    T=127;

     while (T) {

         somefunction(data[T]);

         T--;

       }

}

  • Bart Van Thielen said:

    - I am accessing data[] for higher indices than it was declared (knowing that data2 will be behind it)

    May be you can use a pointer.

  • Bart,

    i think the most convenient way to do this is by changing the linker command file to define a combined memory section of INFOB and INFOC.

    For example in the default linker command file of MSP430G2553, it is defined:

    MEMORY
    {

         INFOB : origin = 0x1080, length = 0x0040
         INFOC : origin = 0x1040, length = 0x0040

    }

    SECTIONS
    {

      .infoB : {} > INFOB

      .infoC : {} > INFOC

    }

    Instead you can create new section as follows:

    MEMORY
    {

         //INFOB : origin = 0x1080, length = 0x0040
         //INFOC : origin = 0x1040, length = 0x0040

        INFOB_C : origin = 0x1040, length = 0x0080

    }

    SECTIONS
    {

      //.infoB : {} > INFOB

      //.infoC : {} > INFOC

      .infoB_C : {} > INFOB_C

    }

    So if i have the following test code:

    #include <msp430.h>

    #pragma DATA_SECTION(my_var, ".infoB_C")
    #pragma RETAIN(my_var)
    const unsigned char my_var[128] = {
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
    0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
    0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
    0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
    0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
    0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f
    };

    void main(void)
    {
      WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer 

      while(1);
    }

    The pragma RETAIN is used so that my_var is not removed by the compiler eventough it is not referred anywhere in the code, and the pragma DATA_LOCATION is for locating the variable into the new combined memory section. Generating the binary TXT file, i get the following:

    @1040
    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
    20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
    30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
    40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
    50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
    60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
    70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
    @c000
    0A 12 09 12 3F 40 00 00 3F 90 01 00 19 28 3F 40
    00 00 3F 90 01 00 14 28 3A 40 00 00 3A 80 00 00
    3A 50 03 00 0A 11 0A 11 39 40 00 00 3C 49 7F 4C
    4F 4F 0F 5F 1F 4F 00 00 3D 49 8F 12 1A 83 F6 23
    3F 40 00 00 3F 90 00 00 08 24 3A 40 00 00 02 3C
    3F 4A 8F 12 3A 90 00 00 FB 23 30 40 82 C0 31 40
    00 04 B0 12 90 C0 0C 93 02 24 B0 12 00 C0 0C 43
    B0 12 88 C0 B0 12 94 C0 34 41 35 41 36 41 37 41
    38 41 39 41 3A 41 30 41 B2 40 80 5A 20 01 FF 3F
    1C 43 30 41 03 43 FF 3F
    @fffe
    5E C0
    q

    As you can see, the variable is perfectly generated through the INFOB and INFOC.

    Here is the complete test code and CCS project files:

    3225.TEST_INFO.zip

**Attention** This is a public forum