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.

Constant Data Stored and Accessed in Flash Memory

Other Parts Discussed in Thread: TMS320LF2406A

I am using the TMS320LF2406A device and Code Composer Studio.  In the simple sample code below, I want the variable 'Table' to be stored in the flash memory (because in reality this table is quite large and I don't want it to consume valuable RAM space).  I do not want the compiler/linker to locate the variable Table in RAM.  How do I do this?

int Table[10] = { 3, 6, 4, 7, 2, 9, 8, 1, 0, 5 };

int MyFunction (int Index)

{

return (Table[Index]);

}

  • Declare it as "const int Table" instead of "int Table" and in your linker command file point the .const section into flash.

  • Thanks for the reply.

    I tried to implement what you suggested, but it does not work.  I inherited the following linker cmd file.  I pointed const to flash memory in the linker cmd file as you suggested.  What I am doing wrong?

    const int Table[10] = { 3, 6, 4, 7, 2, 9, 8, 1, 0, 5 };

    int MyFunction (int Index)

    {

    return (Table[Index]);

    }

    Here is the linker cmd file:

    -stack 090h 

    MEMORY
    {
        PAGE 0:    /* Program Memory */
          VECS:       org=0000h,        len=00040h       /*   */
          PSWD:       org=0040h         len=00004h       /*   */
          PROG:       org=0044h         len=0FDBCh       /*   */

        PAGE 1:    /* Data Memory    */
          B0B1:       org=0200h,        len=01F0h        /* internal DARAM */
          B2:           org=0060h,        len=0020h        /* internal DARAM */      
          SARAM:   org=0800h,     len=0800h       /* internal SARAM */
    }

    SECTIONS 
    {

            vectors >       VECS          PAGE 0
            PaSsWoRd >      PSWD          PAGE 0

            .text   >       PROG          PAGE 0
            .cinit  >       PROG          PAGE 0
            .switch >       PROG          PAGE 0
            .const  >       PROG          PAGE 0
            .bss    >       B0B1          PAGE 1
            .sysmem >       B0B1          PAGE 1
            .data   >       B0B1          PAGE 1
            .stack  >       B0B1          PAGE 1

            saram1   >      SARAM         PAGE 1
    }

  • Sorry, I need to dust off the F24x cobwebs.  I forgot that it has separate program and data space!  This is much easier on the F28x.  :)  There's an app note written on this exact topic and some code examples too. 

    Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP (spra380.htm,12 KB) 
    15 Apr 2002 Abstract  

    http://focus.ti.com/docs/apps/catalog/resources/appnoteabstract.jhtml?abstractName=spra380 

     

  • Good information.  The example in that app note has the test data defined in assembly code.  I have the test data defined in C code, and is still not working.  Can you help one more time:

    #pragma CODE_SECTION (TestValue, "TESTSECT"); /* I also tried #pragma DATA_SECTION (TestValue, "TESTSECT"); */

    int TestValue = 0x1234;

    int MyFunction (void)

    {

    int tmpInt;

    tmpInt = PFUNC_wordRead(&TestValue);
    return (TmpInt);

    }

    In the linker cmd file I have

    MEMORY
    {
      PAGE 0:    /* Program Space */
        FLASH:      org=0044h         len=0FDBCh       /* internal FLASH */
    ...

    }

    SECTIONS 
    {
            TESTSECT >       FLASH         PAGE 0
    ...

    }

    The map file indicates the following:

    TESTSECT    0    00002880    000001     UNINITIALIZED

    The word UNITIALIZED does not appear in the app note example.  Any idea what I'm doing wrong now?

     

  • I don't know of any way to do it from C, which is likely the reason the example defines the variables in assembly.  I believe you'll need to do the same.

  • Okay.  I'll move my table from C to assembly as you suggest.   Thanks for your help!