I finally have it running like it should!
The main problem was the I made false assumptions on what will go where in memory space!
normal data buffers go to he stack, not to the .data section.
Either the information on avr-libc memory sections is misleading or I completely misunderstood it.
if you declare the buffers satic, they go to .data and thus to the external RAM
(nearly) complete test-sketch
void enableExternalMemory() __attribute__((naked,used)) __attribute__((section (".init3")));
void enableExternalMemory()
{
XMCRA = (1<<SRE);
}
void setup()
{
uint32_t arraysize = 1024;
Serial.begin(57600);
static uint32_t dataBuffer1[1024];
static uint32_t dataBuffer2[1024];
static uint32_t dataBuffer3[1024];
static uint32_t dataBuffer4[1024];
static uint32_t dataBuffer5[1024];
uint32_t* dataBuffer6 = new uint32_t[arraysize];
uint32_t* dataBuffer7 = new uint32_t[arraysize];
Serial.println();
Serial.print("Dynamic buffer 1 of ");
Serial.print(arraysize * sizeof(uint32_t));
Serial.print(" bytes created, address: 0x");
Serial.println((uintptr_t)dataBuffer1, HEX);
Serial.print("Dynamic buffer 2 of ");
Serial.print(arraysize * sizeof(uint32_t));
Serial.print(" bytes created, address: 0x");
Serial.println((uintptr_t)dataBuffer2, HEX);
Serial.print("Dynamic buffer 3 of ");
Serial.print(arraysize * sizeof(uint32_t));
Serial.print(" bytes created, address: 0x");
Serial.println((uintptr_t)dataBuffer3, HEX);
Serial.print("Dynamic buffer 4 of ");
Serial.print(arraysize * sizeof(uint32_t));
Serial.print(" bytes created, address: 0x");
Serial.println((uintptr_t)dataBuffer4, HEX);
Serial.print("Dynamic buffer 5 of ");
Serial.print(arraysize * sizeof(uint32_t));
Serial.print(" bytes created, address: 0x");
Serial.println((uintptr_t)dataBuffer5, HEX);
Serial.print("Dynamic buffer 6 of ");
Serial.print(arraysize * sizeof(uint32_t));
Serial.print(" bytes created, address: 0x");
Serial.println((uintptr_t)dataBuffer6, HEX);
Serial.print("Dynamic buffer 7 of ");
Serial.print(arraysize * sizeof(uint32_t));
Serial.print(" bytes created, address: 0x");
Serial.println((uintptr_t)dataBuffer7, HEX);
for (size_t i=0; i<arraysize; ++i)
{
dataBuffer1[i] = i+1;
dataBuffer2[i] = i+1;
dataBuffer3[i] = i+1;
dataBuffer4[i] = i+1;
dataBuffer5[i] = i+1;
dataBuffer6[i] = i+1;
dataBuffer7[i] = i+1;
}
Serial.println();
Serial.println();
Serial.println(err_str);
/*
Serial.println("Data Buffer 1");
for (size_t i=0; i<arraysize; i+=4)
{
Serial.println();
Serial.print(i, DEC);
Serial.print('\t');
Serial.print(dataBuffer1[i], DEC);
Serial.print('\t');
Serial.print(dataBuffer1[i+1], DEC);
Serial.print('\t');
Serial.print(dataBuffer1[i+2], DEC);
Serial.print('\t');
Serial.print(dataBuffer1[i+3], DEC);
}
//----------------------------------------*/
}
void loop()
{
}
(I included only output for 1 buffer to save some space in this thread)
To complete the board&variant creation, I created a folder called variants with a subfolder xmem in the boards folder under sketches. Then modify platform.txt to select this xmem variant instead of original arduino.mega
I copied the original pins_arduino-h from the original Arduino-Mega hardware folder and added a initXmem.c file with the following content
#include <avr/io.h>
#include <avr/iomxx0_1.h>
void enableExternalMemory() __attribute__((naked,used)) __attribute__((section (".init3")));
void enableExternalMemory()
{
XMCRA = (1<<SRE);
}
Now the board can be selected via boardmanager and used just as a normal Arduino board
I hope that this works fine for everybody else
here is the .zip that has to go into "arduino sketches folder"/hardware
XmemMega.zip (5.2 KB)
Cheers and thanks for all help here and very very much at mikrocontroller.net