Hello. I have a question about how compiled program code is located in microcontroler, for example lets consider ATmega128 and ATmega32.
ATmega128 wrote:
128 [kB] Flash Program Memory
4 [kB] Internal SRAM
4 [kB] EEPROM
ATmega32 wrote:
32 [kB] Flash Program Memory
2 [kB] Internal SRAM
1 [kB] EEPROM
AVR Studio 4 give information about memory usage of current project in given microcontroler. This is divided into two parts: Program and Data. I have noticed that information about Program covers the Flash Program Memory, and Data the Static RAM. So we can say that program is loaded into Flash and whole program data into SRAM?
Additionally I have noticed as well that when I use global variable for example:
Code:
#define N 200
unsigned char BUFFOR[N];
int main(void)
{
...
}
Then AVR Studio inform that those 200 [kB] use place in SRAM (Data memory usage grow up). But when I do something like that:
Code:
#define N 200
void function1(void);
int main(void)
{
function1();
}
void function1(void)
{
unsigned char BUFFOR[N];
... /*Operations on this buffer*/
}
Then AVR Studio don't show where this buffer was located - Data and Program memory usage remain the same. So where this buffer is located? As well in SRAM? So if I will use many 200 [kB] buffers in functions, there is a possibility that microcontroler will have to less memory (even if AVR Studio informs that everything is correct and should fit)? Or those buffers will be located in Flash memory? That would be more practical because in my humble opinion in ATmega128 the 4 [kB] for Data is too small in comparison to 128 [kB] for Program.
My last question is about such example: let's consider that I have a project on ATmega128 and I want to migrate it to ATmega32. On ATmega128 it looks for example like this:
AVR Studio 4.18 wrote:
AVR Memory Usage
----------------
Device: atmega128
Program: 26626 bytes (20.3% Full)
(.text + .data + .bootloader)
Data: 2758 bytes (67.3% Full)
(.data + .bss + .noinit)
So the Program will fit ATmega32 32 [kB] of space, but problem is with Data because ATmega32 will need approximately 710 [B] of SRAM more. Is such migration possible? Or I will need to reduce the number of global variables to decrease used amount of SRAM?
Than You for any discussion. Those informations are only my theoretical examples, and they does not cover any practical problem (yet). |