Hi
I need to change the stack size of a MSP430 project.
Is there a parameter in the CCS Studio for the MSP430 GNU GCC to change the stack size?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi
I need to change the stack size of a MSP430 project.
Is there a parameter in the CCS Studio for the MSP430 GNU GCC to change the stack size?
It is not calculated, as said before it is just the RAM that is left over by the variables and possibly the Heap (if used).
Because the Heap is dynamic by nature you'd have to find the remaining stack space during runtime, eg. by using "stack painting" before "main()".
E.g. from http://stackoverflow.com/questions/389219/how-to-determine-maximum-stack-usage
Jack Ganssle says more than just that. I think that was just his intro one-liner. From his book, 2nd edition, p. 250: "Since few programmers have a reasonable way to determine maximum stack requirements, always assume your estimates will be incorrect. For each stack in the system, make sure the initialization code fills the entire amount of memory allocated to the stack with the value 0x55. Later, when debugging, you can view the stack and detect stack overflows by seeing no blocks of 0x55 in that region..." – Craig McQueen Nov 18 '09 at 23:51
I personally use this code snippet:
#include <stdint.h>
// import GCC symbols
extern uint8_t __noinit_end; // end of data, as defined in linker script
extern uint8_t __stack; // start of stack, defined by the init code
#define STACK_INIT_VAL 0xAA
/********************************************************************
*
* AUTO INITIALIZATION of stack with default value
*
*******************************************************************/
void stackInit(void) __attribute__ ((naked));
void stackInit(void) __attribute__ ((used));
void stackInit(void) __attribute__ ((section (".crt_0050stack_init")));
void stackInit(void)
{
register uint8_t *stack = &__noinit_end;
/* write default value to whole stack space */
do {
*(stack++) = STACK_INIT_VAL;
} while (stack <= &__stack);
}
Hi!
Nick de Smith said:I tried using the above code in CSS 7 with the TI compiler, and __noinit_end and __stack are undefined...
This is for GCC only!
For the TI compiler please have a look into the .cmd linker script and the .map file created.
AFAIK you might need to use "_stack" instead of "__noinit_end" and "__STACK_END" instead of "__stack", but I haven't tried.
Nick de Smith said:Also, why use the specific section: ".crt_0050stack_init"
Anyone got any more thoughts on this?
This section, when using GCC, is used to include this code very early during system startup, way before main() executes.
Referring to [PDF] MSP430 Optimizing C/C++ Compiler User's Guide - Texas Instruments, section 6.9 "System Initialization", you might need to change this into "_c_int01". Check the .map file created before and afterwards.
You might as well change the "void stackInit(void) __attribute__ ((naked));" line into a FUNC_IS_PURE pragma - see 5.11.13 in said manual.