Access to variable in SDRAM from same object


#1

Hello everyone.

Some background: I made a light 8 track step sequencer holding its data in a 2D array of uint16_t (each bit representing a step on or off). This pattern data is loaded/saved to the SD card and modified live. To avoid using precious SRAM, I declared it in SDRAM:

static uint16_t pattern[8][8] __attribute__ ((section (".sdram")));

The thing I found rather weird, is that declaring it inside Local Data made it "invisible" to the rest of the code:

[...]/axoloti/build/xpatch.o: In function `rootc::Init()':
xpatch.cpp:([...]): undefined reference to `rootc::instance8__tracks__sequencer__1::pattern'
[...]/axoloti/build/xpatch.o: In function `rootc::dsp()':
xpatch.cpp:([...]): undefined reference to `rootc::instance8__tracks__sequencer__1::pattern'

What I had to do to make everything work was to declare the pattern data inside Init Code and keep a pointer to it.

Local Data:

uint16_t (*pattern)[8];

Init code:

static uint16_t pattern_data[8][8] __attribute__ ((section (".sdram")));
pattern = pattern_data;

Can somebody point me to some directions as to why it only works that way ?
And why may the attribute ((section (".sdram"))) only be added to static variables ?

Thanks in advance !