Memory Usage

Q

Is there the possibility on having an memory usage overview?

A

The usage of defined memory in GCC may be visualized with several methods. However, their correctness depends highly on your application.

In the linker script is the definition of available hardware memory areas. Into those areas, the sections containing code and variables, the program memory is stored.

Program memory created by the compiler usually consists out of the sections ".text", ".rodata", ".data" and ".bss". The sections ".heap" and ".stack" are user defined.

This directly shows, that the dynamic (user) program memory inside heap and stack area cannot be measured during compile- and link-time because they are user defined.

However, for the program memory it is possible to visualize this after link-time with a linker option or with the gcc toolchain.

A Linker flag (>~ gcc 4.9.3)

To display the RAM and Flash usage in netX Studio, simply add line 15 into the Targets folder wscript:

    bld.program(
        target="netx90_app_iflash",
        name="netx90_app_iflash",
        description="Host Example using NXHX90-JTAG as Host",
        displaygroup="Targets",
        toolchain="gccarmemb",
        platform="netx90",
        source=sources,
        includes=includes,
        defines=defines,
        use=uses,
        stlib=['m', 'c', 'nosys'],
        linkerscript=["Linker/netx90_app_iflash.ld"],
        features=["group_lib"],
        linkflags=["-Wl,--print-memory-usage"], //############################ This line has to be added
        netx_type='netx90_rev0',
        cxxflags="-std=c++11",
    )

A Postbuild Toolchain method (<=gcc 4.9.3))

To display the RAM and Flash usage in netX Studio, you have to modify the main wscript:

At its beginning with

import os
from waflib.Context import STDOUT, BOTH
import subprocess

and around the build function with

def prebuild(bld):
   print os.listdir(os.getcwd() + "\\build\\" + bld.get_conditions())
   print 'before the build is started'
 
def postbuild(bld):
   print 'after the build is complete'
   print os.listdir(os.getcwd() + "\\build\\" + bld.get_conditions())
   for root, dirs, files in os.walk(os.getcwd() + "\\build\\" + bld.get_conditions() + "\\Targets\\"):
       for file in files:
           if file.endswith(".elf"):
               cmd = [bld.all_envs["toolchain_gccarmemb"].get_flat('OBJDUMP').replace("objdump","size"), root + os.sep + file,"-Bxt"]
               result = bld.cmd_and_log(cmd, output = BOTH, quiet=STDOUT)
               print result[0]

def build(bld):
   bld.add_pre_fun(prebuild)
   bld.add_post_fun(postbuild)
   bld.autorecurse()

You will then receive this command line output in the build console:

   text	   data	    bss	    dec	    hex	filename

0x31ef4	  0xa54	 0x1e48	 214928	  34790	C:\Users\user\Desktop\project\build\debug\Targets\NXHX90-JTAG\netx90_app_iflash.elf

0x31ef4	  0xa54	 0x1e48	 214928	  34790	(TOTALS)