Question

i'm trying to reserve some bytes of sram where the address MUST be know at load time so that it can be fitted into PROGSPACE. Untill now i tested my code ok with a tricky allocation on the arduino nano board by setting the address to (0x1F6) and latter on the program i do

volatile byte shifty_data[3];

to ensure its not overwriten in the heap... the code is working ok, but i'm not happy with this because its not compatible with other cores and possibly with environment changes. Until now i've considered changes in malloc __heap_start (with no success because its not constant and address is not known at load time, i think), i've also looked at avr/io.h and specifically at iom328p.h thru RAMSTART defines, this might work but... its seems too low on the systemn since i want to use hardware SPI over it... and it might be a better way of doing this in an higher level preferably within the arduino files. any ideas?

Was it helpful?

Solution

I am not quite sure what you are asking here, but there are two crucial things that I believe you are misunderstanding. Program space is separate from SRAM. they are in two different address buses. AVR actually provides an instruction to copy data from program space into RAM because of this separation [making it a modified Harvard architecture]. Then, there is also the thing that any globally declared variable will either reside in the .bss section or .data sections of SRAM [this is actually part of the C standard]. The __do_copy_data and __do_clear_bss sections of the final executable take care of that [they are automatically added into the .init4 section]. You can override this mechanism using compiler flags, however, the address of each global variable is known from the time the program starts executing [something that happens out of flash memory, not SRAM].

Now, placing things into SRAM, I suggest you take a look at this page on the avr-libc manual. It deals with memory sections in general and how to tweak them. Cheers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top