Placing a key in flash memory using __at
|
|||
Home > Using scatter files > Placing a key in flash memory using __at |
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.
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
.
Example 24. Placement of the flash key variable in C or C++ code
// place flash_key in a section called .ARM.__at_0x8000
long flash_key __attribute__((section(".ARM.__at_0x8000")));
The following example shows a scatter file with manual placement of the flash execution region:
Example 25. Manual placement of flash execution regions
ER_FLASH 0x8000 0x2000 { *(+RO) *(.ARM.__at_0x8000) ; key }
Use the linker command-line option --no_autoat
to enable manual placement.
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.
Example 26. Automatic placement of flash execution regions
ER_FLASH 0x8000 0x2000 { *(+RO) ; other code and read-only data, the ; __at section is automatically selected }
实际使用测试:
; ************************************************************* ; *** Scatter-Loading Description File generated by uVision *** ; ************************************************************* LR_IROM1 0x08000000 0x00010000 { ER_IROM1 0x08000000 0x0000F000 { startup.o (RESET, +First) .ANY (+RO) } ER_IROM2 0x0800F000 FIXED 0x00001000 { main.o (.ARM.__at_0xF000) } RW_IRAM1 0x20000000 0x00004000 { .ANY (+RW,+ZI) } ; RW_IRAM3 0x20004800 UNINIT 0x0000200 ; HEAP { startup.o(HEAP) } RW_IRAM2 0x20004A00 UNINIT 0x0000600 ; STACK { startup.o(STACK) } } // main.c /* Private macro -------------------------------------------------------------*/ const char buf[4096] __attribute__((section(".ARM.__at_0xF000"))) = {"Hello World!"}
红色字体是字段标志,用于索引。