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.

CCS/TM4C129ENCPDT: How to control stack size

Part Number: TM4C129ENCPDT

Tool/software: Code Composer Studio

We're trying to figure out how to control the size of our stack.

We are using CCSv7 version 7.1.0.00016 and building our project with two different compiler toolchains: ti-cgt-arm_16.9.3.LTS and gcc-arm-none-eabi-4_9-2015q3.

Evidently our project was created with a default stack size of 512 bytes. Suppose we wish to increase that to 4096.

For the TI linker, we changed the setting "Set C system stack size (--stack_size, -stack)" as shown in the screenshot to 4096. However, that doesn't appear to be the end of the story. Our project contains the linker command file tm4c129encpdt.cmd, and it contains the line "__STACK_TOP = __stack + 512;" It appears CCS copied this file into our project from C:\ti\ccsv7\ccs_base\arm\include\tm4c129encpdt.cmd, because the two files are identical, and both contain this line. It appears that changing the project's linker setting from 512 to 4096 does not automatically update this file. __STACK_TOP is used in the 0th entry of the vector table in the startup c file.

For the GCC linker, there doesn't appear to be any project setting for stack size. In this case, we have a linker command file tm4c129encpdt.lds and our startup file tm4c129encpdt_startup_gcc.c. The linker command file doesn't appear to deal with the stack size at all, whereas the startup c file contains the line "static uint32_t pui32Stack[128];" and, for the vector table, calculates the initial stack pointer using sizeof().

So our questions are:

(1) For the TI linker, are we required to update the stack size in two places: the project settings and the __STACK_TOP line in the linker command file? Are there additional places to update?

(2) For the GCC compiler/linker, is it enough to update the "static uint32_t pui32Stack[128];" line? Are there additional places to update?

(3) With either option, how can we verify definitively that the stack size is, indeed, set correctly?

  • I forgot to mention that we are not using TI RTOS. We are just using TivaWare at this point.

    Another question: is the __STACK_TOP line in the linker command file the same as the one referenced in the C startup file? It seems a little strange that a C file would recognize a symbol declared in a linker file.
  • Hello,
    There is a related thread in the TM4C forums:
    e2e.ti.com/.../428953

    Hope this helps
    ki
  • Sorry, I neglected to address the questions regarding the TI compiler:

    twelve12pm said:
    (1) For the TI linker, are we required to update the stack size in two places: the project settings and the __STACK_TOP line in the linker command file? Are there additional places to update?

    Yes, I believe you are right. It is also mentioned in the below thread:

    https://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/413930/1476356#1476356

    ki

  • Yes the thread you linked mentions the same thing. It seems the stack size must be updated in two places, which would cause problems if they are out of sync. But perhaps there's a way to simplify this. For the TI linker, it seems the linker creates a special variable __STACK_SIZE based on the --stack-size parameter it receives, and I think that instead of using the hard-coded number, you can use this __STACK_SIZE. So then the setting would only have to be updated in one place. Of course, I only **THINK** that might be the case. Currently I have not tried yet. Right now the program runs when compiled with the TI toolchain.

    But I'm having a big problem with the GCC build configuration. It seems that no matter what stack size I give (which is specified in the line "static uint32_t pui32Stack[128];" of the C startup file, unless I missed something) the program goes into FaultISR the first time a function returns. Which leads me to believe that something is messed up with the stack. So far the NVIC registers suggest it's crashing because of an instruction bus error. I really think it's trying to return from the function to some garbage address. I thought to look what SP (stack pointer) is when the program first starts and arrives at main(). When compiled with TI, it was 0x20000E30; when compiled with GCC, it was 0x20001358, a significantly larger number. I'm not sure why that is. Shouldn't there be some directive that places the stack at a specific location? Because it seems that just declaring pui32Stack[128] will just put the stack in any "random" place, and it could change from one build to the next. I saw nothing, anywhere, that tells it where to be.