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/TM4C1294NCPDT: save the const in Flash in CCS IDE

Part Number: TM4C1294NCPDT

Tool/software: TI C/C++ Compiler

Hi e2e,

Here is a question about const data saving in Flash in CCS.

The MCU is TM4C1294, we want to put the const data in Flash to save the RAM usage, in below code, how we can approach this. 

#define _CODE __attribute__ ((section ("._OEM_BU1_RODATA ")))

and in cmd file, how we create the section  ._OEM_BU1_RODATA? can you help to correct above?

thanks in advance.

  • The simple way is to declare the variable with the const qualifier outside of function scope:

    #include <stdint.h>
    #include <stdbool.h>
    #include "driverlib/sysctl.h"
    
    const uint8_t name[] = {"my name\0"};
    
    int
    main(void)
    {
    
        volatile uint8_t ram_name[10];
        //
        // Run from the PLL at 120 MHz.
        //
        SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN |
                                           SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);
        memcpy(ram_name, name, sizeof(name));
    
    }
    

    The array name will be in the ".const" section. The standard link command file that is in project0 will put that section into flash memory. In my simple example it ends up at address 0x720.

    .const     0    000004d4    00000260     
                      000004d4    000001b0     driverlib.lib : sysctl.obj (.const:g_pppui32XTALtoVCO)
                      00000684    0000006c                   : sysctl.obj (.const:g_pui32Xtals)
                      000006f0    00000030                   : sysctl.obj (.const:g_sXTALtoMEMTIM)
                      00000720    00000009     main.obj (.const:.string:name)
                      00000729    00000003     --HOLE-- [fill = 0]
                      0000072c    00000008     driverlib.lib : sysctl.obj (.const)
    
    

  • Hi Bob,

    Yes, it works, thanks for your help.

    LEON