Execute code from SRAM on AVR32


Atmel has an application note explaining how to execute code from SDRAM and another document explaining how to use linker scripts. GNU ld and as docs are also useful references.

Create a new section

Add the following section in the SECTIONS of linker script, probably after the .data section. The location pointer should be in the SRAM, usually indicated by a statement such as . = ORIGIN(SRAM)

  .text_sram :
  {
    *(.text_sram.*)
  } >SRAM AT>FLASH

The MEMORY spec in the linker script should place SRAM and FLASH used above in the appropriate memory regions.

Modify functions

Add the following attribute to the functions that will be located in the SRAM

__attribute__((__section__(".text_sram")))

Use objcopy and nm to check the resulting elf

Execute avr32-objcopy on the elf

avr32-objdump -h file.elf

This should list something like

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
...
  8 .data         000005d4  00000578  8000e778  0000ed78  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  9 .text_sram    00000044  00000b4c  8000ed4c  0000f34c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 10 .bss          00004138  00000b90  8000ed90  0000f390  2**2

Use avr32-nm to check location of symbols in memory

avr32-nm file.elf

This lists something like

00000b4c T func

The function func is loaded into FLASH but executed from SRAM.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s