7.2.10 Placement of a key in flash memory with an __at section

Some flash devices require a key to be written to an address to activate certain features. An __at section provides a simple method of writing a value to a specific address.

Placement of the flash key variable in C or C++ code

Assuming a device has flash memory from 0x8000 to 0x10000 and a key is required in address 0x8000. To do this with an __at section, you must declare a variable so that the compiler can generate a section called .ARM.__at_0x8000.

// place flash_key in a section called .ARM.__at_0x8000
long flash_key __attribute__((section(".ARM.__at_0x8000")));

Manual placement of flash execution regions

The following example shows a fragment of a scatter file with manual placement of the flash execution region:

ER_FLASH 0x8000 0x2000
{
  *(+RW)
  *(.ARM.__at_0x8000) ; key
}

Use the linker command-line option --no_autoat to enable manual placement.

Automatic placement of flash execution regions

The following example shows a scatter file with automatic placement of the flash execution region. Use the linker command-line option --autoat to enable automatic placement.

LR1 0x0
{
  ER_FLASH 0x8000 0x2000
  {
    *(+RO)                   ; other code and read-only data, the
                             ; __at section is automatically selected
  }
  ER2 0x4000
  {
    *(+RW +ZI)               ; .ARM.__at_0x4000 is selected by +RW
  }
}
Non-ConfidentialPDF file icon PDF versionARM DUI0474M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.