Execute code from SRAM on AVR32

Atmel has an application note explaining how to execute code from SRAM 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 :

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


Use objdump and nm to check the resulting elf

Execute avr32-objdump on the elf

avr32-objdump -h file.elf

This should list something like

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
 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.

A note on writing to flash memory

One reason you’ll want to run code from SRAM is when you need to update flash memory. There are couple of situations when this can fail


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