SPMU373A March 2021 – August 2022 TM4C1230C3PM , TM4C1230D5PM , TM4C1230E6PM , TM4C1230H6PM , TM4C1231C3PM , TM4C1231D5PM , TM4C1231D5PZ , TM4C1231E6PM , TM4C1231E6PZ , TM4C1231H6PGE , TM4C1231H6PM , TM4C1231H6PZ , TM4C1232C3PM , TM4C1232D5PM , TM4C1232E6PM , TM4C1232H6PM , TM4C1233C3PM , TM4C1233D5PM , TM4C1233D5PZ , TM4C1233E6PM , TM4C1233E6PZ , TM4C1233H6PGE , TM4C1233H6PM , TM4C1233H6PZ , TM4C1236D5PM , TM4C1236E6PM , TM4C1236H6PM , TM4C1237D5PM , TM4C1237D5PZ , TM4C1237E6PM , TM4C1237E6PZ , TM4C1237H6PGE , TM4C1237H6PM , TM4C1237H6PZ , TM4C123AE6PM , TM4C123AH6PM , TM4C123BE6PM , TM4C123BE6PZ , TM4C123BH6PGE , TM4C123BH6PM , TM4C123BH6PZ , TM4C123BH6ZRB , TM4C123FE6PM , TM4C123FH6PM , TM4C123GE6PM , TM4C123GE6PZ , TM4C123GH6PGE , TM4C123GH6PM , TM4C123GH6PZ , TM4C123GH6ZRB , TM4C123GH6ZXR , TM4C1290NCPDT , TM4C1290NCZAD , TM4C1292NCPDT , TM4C1292NCZAD , TM4C1294KCPDT , TM4C1294NCPDT , TM4C1294NCZAD , TM4C1297NCZAD , TM4C1299KCZAD , TM4C1299NCZAD , TM4C129CNCPDT , TM4C129CNCZAD , TM4C129DNCPDT , TM4C129DNCZAD , TM4C129EKCPDT , TM4C129ENCPDT , TM4C129ENCZAD , TM4C129LNCZAD , TM4C129XKCZAD , TM4C129XNCZAD
Ensuring there is sufficient stack size for a program is an important consideration to ensure that programs are not susceptible to stack overflow. The program stack exists in RAM memory and is used to store information like current register values and return addresses during program execution. A stack overflow is a programming error where the stack pointer exceeds the allocated space for the program stack. When that occurs, it is possible for data read back by the stack to have been overwritten by the application and the corrupted data would then cause a program crash.
In order to adjust the stack settings for a Code Composer Studio project, open the Project Properties and go to Build → ARM Linker → Basic Options. Towards the bottom of the list there is a box to ‘Set C system stack size’ (Figure 8-1). In order to ensure the memory is aligned, always use a multiple of 4 bytes for the stack setting.
Another location to modify the stack size is within the linker command file (.cmd) for the project. On the bottom of the file there should be a line item for __STACK_TOP and the numerical value that follows can be edited to adjust the stack size.
__STACK_TOP = __stack + 512;
For programs that use dynamic memory allocation such as malloc and when using dynamically created tasks within an RTOS, heap memory needs to be allocated as well. Heap is a separate section of memory that is reserved in order to support dynamic memory allocation. The heap setting for a Code Composer Studio project can be found directly above the stack option, ‘Heap size for C/C++ dynamic memory allocation’. This will typically be set to zero by default in TivaWare examples.