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.

How to increase stack size on ARM gcc toolchain?

Hi,

this probably a dumb question but how can I increase the stack size using ARM gcc? The target mcu linker file has no such section and neither has the startup_gcc.c.

  • Hi Greg,

    Tried to look for it and it seems much less intuitive in the GCC compiler!
    But maybe it's this, in the startup file:

    //*****************************************************************************
    //
    // Reserve space for the system stack.
    //
    //*****************************************************************************
    static uint32_t pui32Stack[128];

    That's has the default size of 512bytes, so maybe it's that? Try it out, it should give the stack size in the .map later. Can't really test it, I don't feel like configuring a project linker and build in GCC (that's like the part I hate the most about starting a project).
  • Hi,

    There are two possible scenarios, depending how do you use the gcc toolchain:

    a) if used from CCS, then the same place of Project Properties specify the stack size, to be taken into account.

    b) if used stand alone, without CCS, then a good  place to specify it is the linker file (this also manages the heap area). Since you do not find out such thing, I presume you use the CCS, so the previous case would be better. If b) is really your case, then a linker file (a good one) you may find out inside CMSIS package.

    Take into account - if you just have problem(s) with stack, then, in CCS, there is a hidden variable _stack generated by the compiler and you may add it to the watch window in debugger to tell you where the stack is. The only problem is I do not know if this is also generated if gcc is used.

    Petrei

  • Hi Luis,

    I was experimenting with that variable (although in my startup file it was declared as unsigned long xyz[64]) but not much changed. I have to use a big wavetable (I'm doing DCT) and I need an at least 512 float long buffer. I was able to build and run the project on CCS, with modified stack size obviously thus the code should be fine (no optimisation levels selected, etc.). My gcc code just stucks when entering the function which requests a local 512 float buffer even if I place an immediate return line as first line in the function. I need to do more research on this, I guess.
  • Hi Petrei!

    I tested my project on CCS toolchain with modified stack size and it was OK. My problem is that I prefer GCC+text editor environment with makefiles. Now I understand that I have to find a more detailed linker file as the one which was provided by TI doesn't have any stack definition in it. Anyway, I'm wondering what is the default stack size then?
  • JustGreg said:
    Anyway, I'm wondering what is the default stack size then?

    It depends upon how the run-time start up code initialises the stack pointer.

    When a Tiva example project is created in CCS 6.1 using the GNU v4.8.4 compiler the <device>_startup_ccs_gcc.c source file added to the project has the following which allocates space for the stack, and sets the initial stack pointer:

    //*****************************************************************************
    //
    // Reserve space for the system stack.
    //
    //*****************************************************************************
    static uint32_t pui32Stack[128];
    
    
    //*****************************************************************************
    //
    // The vector table.  Note that the proper constructs must be placed on this to
    // ensure that it ends up at physical address 0x0000.0000 or at the start of
    // the program if located at a start address other than 0.
    //
    //*****************************************************************************
    __attribute__ ((section(".intvecs")))
    void (* const g_pfnVectors[])(void) =
    {
        (void (*)(void))((uint32_t)pui32Stack + sizeof(pui32Stack)),
                                                // The initial stack pointer

    This means the size of the pui32Stack array, which is 128 32-bit words or 512 bytes, is the size of the stack. The vector table entry sets the initial stack pointer to the end of the pui32Stack array. The ResetISR function which is in the same <device>_startup_ccs_gcc.c source file doesn't adjust the stack pointer before calling main.