Atmel CAVR-4 Manual De Usuario

Descargar
Página de 323
CAVR-4
42
Data segments
AVR® IAR C/C++ Compiler
Reference Guide
If external SRAM is available it is possible to place the stack there. However, the 
external memory is slower than the internal stack so moving it to external memory will 
decrease the performance.
Allocating a memory area for the stack is done differently when you use the command 
line interface compared to when you use the IAR Embedded Workbench IDE.
Data stack size allocation in IAR Embedded Workbench
Select Project>Options. In the General Options category, click the System page.
Add the required stack size in the Data stack text box.
Data stack size allocation from the command line
The size of the 
CSTACK
 segment is defined in the linker command file. 
The default linker file sets up a constant representing the size of the stack, at the 
beginning of the linker file:
-D_CSTACK_SIZE=size
Specify an appropriate size for your application. Note that the size is written 
hexadecimally without the 
0x
 notation. 
Placement of data stack segment
Further down in the linker file, the actual stack segment is defined in the memory area 
available for the stack:
-Z(DATA)CSTACK+_CSTACK_SIZE=60-25F
Note: This range does not specify the size of the stack; it specifies the range of the 
available memory.
Stack size considerations
The compiler uses the internal data stack, 
CSTACK
, for a variety of user program 
operations, and the required stack size depends heavily on the details of these 
operations. If the given stack size is too large, RAM will be wasted. If the given stack 
size is too small, there are two things that can happen, depending on where in memory 
you have located your stack. Both alternatives are likely to result in application failure. 
Either variable storage will be overwritten, leading to undefined behavior, or the stack 
will fall outside of the memory area, leading to an abnormal termination of your 
application. Because the second alternative is easier to detect, you should consider 
placing your stack so that it grows towards the end of the memory.