Hi Jose,

What is wrong with what GCC is doing from you point of view? It allocates only the minimum stack space it needs. It reuses this space for different purposes in different sections of the code, so r2 an r3 presumably occupy the same RAM. If you use -O2 it will not allocate any space for r2 or r3. Although they are declared volatile, this attribute has no effect on auto variables. -O2 will simply optimise most of your code away.

Steve


Jose Maria wrote:

Hi,

What I think is happening is the next (I had the same problem using IAR for MSP430). When you call a function the compiler look for all the stack space you need inside the function and allocate in stack memory (if you optimize the compiler can reduce the amount of stack memory because “reuse” , sorry for my English, the space), no matter if you define differents scopes:

Void Function(void)

{

Unsigned int I;

{

Unsigned int j;

}

}

This will allocate 4 bytes in RAM (with no optimization selected).

So, in your code, all the memory you need is allocated, much more, I think that when you allocate memory in main the compiler define this memory as “global vars”, so you have this memory used always.

I think the solution for you is define a function to do the initial processing, and call it from the main function. This way the stack space is free after the function call, and you will have all the memory available when you call the ROM function:

typedef unsigned char uint8_t;

volatile uint8_t r1[20];

void auxiliary_function(void)

{

volatile uint8_t i = 0;

for (i=0;i<20;i++) {

r1[i] = i;

}

{

volatile uint8_t r2[20];

r2[19] = 0x34;

}

{

volatile uint8_t r3[50];

r3[49] = 45;

}

}

int main(void)

{

auxiliary_function();

//Start real program.

Boot_rom->start() ;

}

This way I think you will have all memory available at the moment you call Boot_rom->start();

So, I want to say that this is what I think you can do, and what I think is happening, If somebody tell you another solution, please believe the other because I am not a GCC expert.

Hope will be usefull.

Bye.



Reply via email to