Atmega 2560: RAM Bank Switching

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

I'm looking for examples/suggestions on how I can most easily go about using the extra RAM I have.

Our application quite happily runs in the 64k available at the moment
- but I some large arrays(debug type stuff) that I could cache away in the higher bank to free up some space

I'm quite familiar with the concept
- and it makes logical sense to put this data away there

I've contemplated a readByte(char *) write(char*, val) approach
- manually defining the addresses of my static arrays
- and switching banks under the covers in there
but it seems quite heavy that way

Is there a simple way to tell the compiler/linker that a static array will be in the higher bank (so it will "overlap" the lower adress space somewhere)
-then I can just manually switch when I need to access it (ensuring that I leave space in the onchip ram into which I can transfer the data)

Hope that makes sense?
- any and all suggestions gratefully received

Thanks
All the best
sd

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You might get away with a named section where you explicitly set the
start address on the commandline:

$ cat test.c
int foo[10000] = { 1, 2, 3, 4 };
volatile int z[10000];

int bar[10000] __attribute__((section("overlay1")));

int
main(void)
{
   return foo[0] + z[1];
}
$ avr-gcc -mmcu=atmega1281 -Wl,--section-start=overlay1=0x802000 -o test.elf test.c
$ avr-nm --print-size test.elf
...
00802000 00004e20 D bar
00000130 W exit
00800200 00004e20 D foo
0000010e 00000022 T main
00805020 00004e20 B z

As you can see, the allocations for foo and bar overlap.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Jörg

I've been trying to do that via our linker script:
- but the linker complains about the overlap

ld.exe: section .bss [00800454 -> 00800c26] overlaps section .bank2 [00800220 -> 00801d7f]

- i've defined the space in the script via

MEMORY
{
  text   (rx)   : ORIGIN = 0, LENGTH = 1024K
  data   (rw!x) : ORIGIN = 0x800060, LENGTH = 0xffa0
  eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
/* new section below*/
  bank2  (rw!x) : ORIGIN = 0x800220, LENGTH = 48K
 }
SECTIONS
{
/* stuff snipped*/
  .bank2 :
  {
    *(.bank2*)
     __bank2_end = . ;
  }  > bank2
  
}

I'll see if I can't get the linker to ignore the overlap via command line switches
- at least it appears to have put the required object in the right place (if I do not declare anything with the attribute the build does not complain)

Thanks
sd

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For the second bank, don't you need 0x10000==64K> 0x2000 for its starting address?

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try giving your bank2 memory segment a different origin, like 0x820220.
As all the references are then truncated to 16 bits anyway (as it's
already done for the "date" segment), that will hopefully work.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.