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.

TM4C129XNCZAD: How to check memory usage & stack size

Part Number: TM4C129XNCZAD
Other Parts Discussed in Thread: EK-TM4C1294XL

First my apologies... I think this is such a basic question and I should know the answer already, but I don't.

How can I check memory usage?  I would like to know about general memory, where all my RAM variables are, and I would also like to know about the stack.  I'm having a very strange problem, and I don't think it has to do with variables passed into a function, but how do I know all that is working?

Thanks very much.

  • Hi,

      I will use an example to show where the variables are stored. I will use pwm_invert example in C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c1294xl\pwm_invert but you can pick any example. 

      If you look at the source code, you will find a global variable g_ui32SysClock. Where would this global variable reside? There are two ways to find the address of this variable. First method is view this global variable in the expression window. The second method is through the .map file. In the .map file, you will find all information about where in memory variables and functions are located. A map file is a table of symbols, their locations and their size. You can find the map file in the Debug directory of the project. See below where g_ui32SysClock is stored at the address 0x20000208.

     If you have local variables declared inside a function then they will be stored on the stack. The map file will tell where the stack is stored in the memory. Below is a snippet of the map file and the linker command file. As you can see the stack starts at 0x20000000. The __STACK_TOP is at 0x20000200. The size of the stack is 512 bytes which is equal to 0x200. The size of the stack is defined in the linker command file. 

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    ******************************************************************************
    TI ARM Linker PC v18.12.0
    ******************************************************************************
    >> Linked Tue Mar 5 08:35:22 2024
    OUTPUT FILE NAME: <pwm_invert.out>
    ENTRY POINT SYMBOL: "_c_int00_noargs" address: 00000c7d
    MEMORY CONFIGURATION
    name origin length used unused attr fill
    ---------------------- -------- --------- -------- -------- ---- --------
    FLASH 00000000 00100000 00000fde 000ff022 R X
    SRAM 20000000 00040000 00000209 0003fdf7 RW X
    SEGMENT ALLOCATION MAP
    run origin load origin length init length attrs members
    ---------- ----------- ---------- ----------- ----- -------
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    --retain=g_pfnVectors
    /* The following command line options are set as part of the CCS project. */
    /* If you are building using the command line, or for some reason want to */
    /* define them here, you can uncomment and modify these lines as needed. */
    /* If you are using CCS for building, it is probably better to make any such */
    /* modifications in your CCS project and leave this file alone. */
    /* */
    /* --heap_size=0 */
    /* --stack_size=256 */
    /* --library=rtsv7M3_T_le_eabi.lib */
    /* The starting address of the application. Normally the interrupt vectors */
    /* must be located at the beginning of the application. */
    #define APP_BASE 0x00000000
    #define RAM_BASE 0x20000000
    /* System memory map */
    MEMORY
    {
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

      

  • Thank you very, very much.  I will look at this in more detail soon.  Before I make a reply as to this resolving my issue, can you go just one step further and clarify specifically how I would know if I'm running out of room in RAM (too many variables, arrays, etc.)?

    I have more global variables than local variables, so I think I'm hardly using the stack.  Measuring stack depth at run time must be an entirely different subject.

  • Hi,

    how I would know if I'm running out of room in RAM (too many variables, arrays, etc.)?

      If you are running out of room in RAM (there is 256kB of RAM on this device) then you wouldn't be able to compile your project. During compile/link time, you would have seen an error message that says insufficient RAM. If you are talking about dynamic memory allocation using malloc then that is a different story. But malloc should fail during allocation because you will get a NULL pointer.

      Again, refer to the map file. The map file will tell you how much RAM is used. See below example. 

  • Should I be concerned about a stack usage of 1,444?   The line is showing yellow.

  • Please take a look at this thread answered by Ki about the inclusive stack. https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/980863/cc1312r-stack-usage-in-ccs-10

    Also check your .cmd file if you have allocated enough stack for it.