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.

TI Stellaris EKK-LM4F232 memory overlap issue (heap and stack)

I am facing a problem in an application (MDK4.23) I have written for my LM4F232 board.

I have a function which defines a struct variable. This function(parent) in turn calls another function(child) within which a malloc is being done. For some reason the mallc ed memory and the address of the struct variable are close to each other.

So when I initialize my malloced memory I in turn lose the contents of the struct variable from the parent function (which calls the child).

Does anyone have any idea why this happens. Is there something I am not taking care off in my scatter file which is causing this.

I think stack and heap are sometimes allocated on a single block of memory with half being used by each and each of the memories growing outwards. Does anyone know how to allocate this stack/heap memory using the scatter file. A sample scatter file for the same would be much appreciated.

My present scatter file is this :

LR_IROM 0x00000000 0x00040000
{
    ;
    ; Specify the Execution Address of the code and the size.
    ;
    ER_IROM 0x00000000 0x00040000
    {
        *.o (RESET, +First)
        * (InRoot$$Sections, +RO)
    }

    ;
    ; Specify the Execution Address of the data area.
    ;
    RW_IRAM 0x20000000 0x00008000
    {
        ;
        ; Uncomment the following line in order to use IntRegister().
        ;
        ;* (vtable, +First)
        * (+RW, +ZI)
    }
}

Thanks.

  • Most likely you aren't setting up a large enough stack for your program.  The default stack in most of the example projects is really small.  Structs declared in functions will be on the stack, and you will rapidly run out of stack space if you do this a lot.

  • Thanks it seems to be working alright now.

    I wasn't sure where to look for the STACK and HEAP sizes. I was under the impression it would have to be set via the scatter file. The sizes however were being set in the startup file.