AVR32795: Using the GNU Linker Scripts on AVR UC3 ... - Atmel

AVR32795: Using the GNU Linker Scripts on AVR UC3 ... - Atmel AVR32795: Using the GNU Linker Scripts on AVR UC3 ... - Atmel

06.02.2013 Views

6 Examples 6.1 Controlling ong>theong> location of functions and variables in ong>theong> flash 6.1.1 Process flow 10 ong>AVR32795ong> A. Define a custom section, .flash_nvram, located in flash: A.1. Handle a default or pre-defined size for this section: /* Use a default flash NVRAM size if flash NVRAM size was not defined. */ __flash_nvram_size__ = DEFINED(__flash_nvram_size__)?__flash_nvram_size__:4K; A.2. Describe ong>theong> output section, .flash_nvram: .flash_nvram ORIGIN(FLASH) + LENGTH(FLASH) - __flash_nvram_size__ : { *(.flash_nvram) } >FLASH AT>FLASH :FLASH_NVRAM B. Locate a variable in a custom section, .flash_nvram: � Extensions to ong>theong> C language family: o Specifying attributes of variables __attribute__((__section__(".flash_nvram"))) static int flash_nvram_data; C. Locate a function in a custom section, .flash_nvram: � Extensions to ong>theong> C language family: o Declaring attributes of functions VMA of this output section Include all input sections .flash_nvram Assign this section to a program segment (cf PHDRS{ }) Specify ong>theong> memory region FLASH for ong>theong> section’s LMA Assign this section to ong>theong> FLASH region of memory (cf. MEMORY{ }) __attribute__ ((__section__(".flash_nvram"))) void Func(void) {…} NOTE Placing a variable or a function at a specific address has to be done through ong>theong> linker script (place ong>theong> custom section at ong>theong> specific address). 32158A-AVR-01/11

6.1.2 Related examples in ong>theong> software framework 32158A-AVR-01/11 ong>AVR32795ong> • drivers/flashc/flash_example/: Controlling ong>theong> location of a variable in flash • drivers/cpu/mpu/example/: Controlling ong>theong> location of a function in flash 6.2 Controlling ong>theong> location of functions in internal RAM 6.2.1 Process flow 6.2.2 Related examples A. Define a custom output section, .ram_fcts, with VMA in RAM and LMA in flash: .ram_fcts : { *(.ram_fcts.*) } >INTRAM AT>FLASH :FLASH B. Locate a function in a custom section, .ram_fcts: � Extensions to ong>theong> C language family: o Declaring attributes of functions Include all input sections .ram_fcts Assign a section to a previously defined segment (cf PHDRS command) Specify a memory region for ong>theong> .text section LMA Assign this section’s VMA to ong>theong> INTRAM region of memory (defined in MEMORY{ }) __attribute__ ((__section__(".ram_fcts"))) void Func(void) {…} C. The startup routine is responsible for copying ong>theong> .ram_fcts LMA (in flash) to ong>theong> .ram_fcts VMA (in INTRAM), as is done for ong>theong> .data section. Examples of a startup routine implementation can be found in ong>theong> AVR Software Framework under utils/startup_files/gcc/ in ASF v1 and under utils/startup/startup_uc3.S in ASF v2. An example using ong>theong> same method can be found here: AVR32749 Application note: Software Workaround Implementation for ong>theong> Erratum Flash Read-after-Write for AT32UC3A0512 / AT32UC3A1512 Revision E, H and I. 11

6 Examples<br />

6.1 C<strong>on</strong>trolling <str<strong>on</strong>g>the</str<strong>on</strong>g> locati<strong>on</strong> of functi<strong>on</strong>s and variables in <str<strong>on</strong>g>the</str<strong>on</strong>g> flash<br />

6.1.1 Process flow<br />

10 <str<strong>on</strong>g><strong>AVR</strong>32795</str<strong>on</strong>g><br />

A. Define a custom secti<strong>on</strong>, .flash_nvram, located in flash:<br />

A.1. Handle a default or pre-defined size for this secti<strong>on</strong>:<br />

/* Use a default flash NVRAM size if flash NVRAM size was not defined. */<br />

__flash_nvram_size__ = DEFINED(__flash_nvram_size__)?__flash_nvram_size__:4K;<br />

A.2. Describe <str<strong>on</strong>g>the</str<strong>on</strong>g> output secti<strong>on</strong>, .flash_nvram:<br />

.flash_nvram ORIGIN(FLASH) + LENGTH(FLASH) - __flash_nvram_size__ :<br />

{<br />

*(.flash_nvram)<br />

} >FLASH AT>FLASH :FLASH_NVRAM<br />

B. Locate a variable in a custom secti<strong>on</strong>, .flash_nvram:<br />

� Extensi<strong>on</strong>s to <str<strong>on</strong>g>the</str<strong>on</strong>g> C language family:<br />

o Specifying attributes of variables<br />

__attribute__((__secti<strong>on</strong>__(".flash_nvram"))) static int flash_nvram_data;<br />

C. Locate a functi<strong>on</strong> in a custom secti<strong>on</strong>, .flash_nvram:<br />

� Extensi<strong>on</strong>s to <str<strong>on</strong>g>the</str<strong>on</strong>g> C language family:<br />

o Declaring attributes of functi<strong>on</strong>s<br />

VMA of this output secti<strong>on</strong><br />

Include all input secti<strong>on</strong>s .flash_nvram<br />

Assign this secti<strong>on</strong> to a program segment (cf PHDRS{ })<br />

Specify <str<strong>on</strong>g>the</str<strong>on</strong>g> memory regi<strong>on</strong> FLASH for <str<strong>on</strong>g>the</str<strong>on</strong>g> secti<strong>on</strong>’s LMA<br />

Assign this secti<strong>on</strong> to <str<strong>on</strong>g>the</str<strong>on</strong>g> FLASH regi<strong>on</strong> of memory (cf. MEMORY{ })<br />

__attribute__ ((__secti<strong>on</strong>__(".flash_nvram"))) void Func(void) {…}<br />

NOTE Placing a variable or a functi<strong>on</strong> at a specific address has to be d<strong>on</strong>e through <str<strong>on</strong>g>the</str<strong>on</strong>g> linker<br />

script (place <str<strong>on</strong>g>the</str<strong>on</strong>g> custom secti<strong>on</strong> at <str<strong>on</strong>g>the</str<strong>on</strong>g> specific address).<br />

32158A-<strong>AVR</strong>-01/11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!