Atmel CAVR-4 Manual De Usuario
![Atmel](https://files.manualsbrain.com/attachments/0369829915bda09f9c2e00fb805a7753579683b5/common/fit/150/50/8d2bf08978ec3e5bc63f4343ac5e91ce8d0e40045619fa520d910d64af8f/brand_logo.png)
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.
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.
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:
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
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:
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.
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.
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.