This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

In a scatter file explicitly place variable initializer values in a flash region

Hi,

Is there a way to explicitly place variable initializer values in a defined flash region using scatter files?

For example, using the scatter file below,

LOAD_ROM 0x0000 0x8000       ; Name of load region (LOAD_ROM),
                             ; Start address for load region (0x0000),
                             ; Maximum size of load region (0x8000)
{
    EXEC_ROM 0x0000 0x8000   ; Name of first exec region (EXEC_ROM),
                             ; Start address for exec region (0x0000),
                             ; Maximum size of first exec region (0x8000)
    {
        * (+RO)              ; Place all code and RO data into
                             ; this exec region
    }
    SRAM 0x10000 0x6000      ; Name of second exec region (SRAM),
                             ; Start address of second exec region (0x10000),
                             ; Maximum size of second exec region (0x6000)
    {
        * (+RW, +ZI)         ; Place all RW and ZI data into
                             ; this exec region
    }
}

If I declare

int aGlobalVar = 0xDEADBEEF;


aGlobalVar will get placed in SRAM, and the initializer value 0xDEADBEEF will get placed at the end of EXEC_ROM (this seems to be the case according to my experiment).

Is there a way for me to force explicit placement of 0xDEADBEEF in a flash region?

Thanks,
LJ

Parents
  • To explicitly place a variable into FLASH (or other valid addresses) you can use a compiler-specific-feature; attribute keyword.

    To place your aGlobalVar at the absolute address 0x00021C00, you can do this:

    int aGlobalVar __attribute__((at(0x00021C00))) = 0xDEADBEEF;
    

    The ARM linker will place the value 0xDEADBEEF at the address 0x00021C00.
    The value of aGlobalVar is 0xDEADBEEF.
    The address of aGlobalVar is 0x00021C00.

    As directed by Westonsupermare Pier:
    Creating new ER region ER_BEACON_CONFIGURATION_DATA in the scatter file and

    int aGlobalVar __attribute__((section("ER_BEACON_CONFIGURATION_DATA"))) = 0xDEADBEEF;
    

    will place the 0xDEADBEEF in the address defined for ER_BEACON_CONFIGURATION_DATA in the scatter file. And, the compiler will generate scatter load codes to copy the data in ER_BEACON_CONFIGURATION_DATA to RAM to be called in __main().

    One main difference between the two methods is where the aGlobalVar is located in memory.
    In the first method, every time you access aGlobalVar it will go to 0x00021C00 (FLASH?).
    In the second method, every time you access aGlobalVar it will go to RAM address assigned by the linker (you dont know it's address before the linker has done it work).

    Obviously, the second method is faster if you run code from flash.

    Note1: to compile under ARMCC6, GNU GCC, IAR or other compilers, you have to change the syntax for the __attribute__ keyword.

    Note2:

    ER_BEACON_CONFIGURATION_DATA 0x00021C00 FIXED 0x400 { ; Beacon configuration
       beaconconfiguration.o (+RO +RW)
      }
    


    The linker will place code and data (RO and RW) generated by the compiled beaconconfiguration.c into this flash section.

Reply
  • To explicitly place a variable into FLASH (or other valid addresses) you can use a compiler-specific-feature; attribute keyword.

    To place your aGlobalVar at the absolute address 0x00021C00, you can do this:

    int aGlobalVar __attribute__((at(0x00021C00))) = 0xDEADBEEF;
    

    The ARM linker will place the value 0xDEADBEEF at the address 0x00021C00.
    The value of aGlobalVar is 0xDEADBEEF.
    The address of aGlobalVar is 0x00021C00.

    As directed by Westonsupermare Pier:
    Creating new ER region ER_BEACON_CONFIGURATION_DATA in the scatter file and

    int aGlobalVar __attribute__((section("ER_BEACON_CONFIGURATION_DATA"))) = 0xDEADBEEF;
    

    will place the 0xDEADBEEF in the address defined for ER_BEACON_CONFIGURATION_DATA in the scatter file. And, the compiler will generate scatter load codes to copy the data in ER_BEACON_CONFIGURATION_DATA to RAM to be called in __main().

    One main difference between the two methods is where the aGlobalVar is located in memory.
    In the first method, every time you access aGlobalVar it will go to 0x00021C00 (FLASH?).
    In the second method, every time you access aGlobalVar it will go to RAM address assigned by the linker (you dont know it's address before the linker has done it work).

    Obviously, the second method is faster if you run code from flash.

    Note1: to compile under ARMCC6, GNU GCC, IAR or other compilers, you have to change the syntax for the __attribute__ keyword.

    Note2:

    ER_BEACON_CONFIGURATION_DATA 0x00021C00 FIXED 0x400 { ; Beacon configuration
       beaconconfiguration.o (+RO +RW)
      }
    


    The linker will place code and data (RO and RW) generated by the compiled beaconconfiguration.c into this flash section.

Children
No data