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.

MSP432E411Y: Primary heap usage

Guru 12155 points
Part Number: MSP432E411Y

Hi,

There is a description of priheap at the following URL.

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/883639/ccs-cc1352r-problem-getting-heaptrack-running/3271396?tisearch=e2e-sitesearch&keymatch=priheap#3271396

The post at this URL says "priheap is just the primary heap", but what is the primary heap? I would like to know how to use it.

I thought the heap area was sectioned by sysmem, but what is the difference between priheap and sysmem?

As far as the linker command file is concerned, it seems that the size set by HEAPSIZE is placed in the priheap section.

* ======== MSP432E411Y_BGAEVM.cmd ========
* Define the memory block start/length for the MSP432E411Y_BGAEVM M4
*/
--stack_size=1024 /* C stack is also used for ISR stack */

HEAPSIZE = 0x20000; /* Size of heap buffer used by HeapMem */

MEMORY
{
FLASH (RX) : origin = 0x00000000, length = 0x00100000
SRAM (RWX) : origin = 0x20000000, length = 0x00040000
}

/* Section allocation in memory */

SECTIONS
{
.text : > FLASH
.const : > FLASH
.rodata : > FLASH
.cinit : > FLASH
.pinit : > FLASH
.init_array : > FLASH

.TI.ramfunc : {} load=FLASH, run=SRAM, table(BINIT)
.data : > SRAM
.bss : > SRAM
.sysmem : > SRAM

/* Heap buffer used by HeapMem */
.priheap : {
__primary_heap_start__ = .;
. += HEAPSIZE;
__primary_heap_end__ = .;
} > SRAM align 8

.stack : > SRAM (HIGH)
}

========================================

Thanks,

Astro

  • Hi Astro,

      Please see below description about .sysmem regarding its use for heap memory. The .sysmem is mainly used for the C run-time memory pool used by malloc(). You can find details for .sysmem in https://www.ti.com/lit/pdf/spnu118 assembler user's guide. 

    The C/C++ language uses two uninitialized sections called .sysmem and .stack for the memory pool used
    by the malloc( ) functions and the run-time stacks, respectively. You can set the size of these by using the
    --heap_size or --stack_size option and specifying the size of the section as a 4-byte constant immediately
    after the option. If the options are not used, the default size of the heap is 2K bytes and the default size of
    the stack is 2K bytes.

      The C/C++ compiler uses an uninitialized section called .sysmem for the C run-time memory pool used by
    malloc(). You can set the size of this memory pool at link time by using the --heap_size option. The syntax
    for the --heap_size option is:
    --heap_size= size
    The size must be a constant. This example defines a 4K byte heap:
    armcl --run_linker --heap_size=0x1000 /* defines a 4k heap (.sysmem section)*/
    The linker creates the .sysmem section only if there is a .sysmem section in an input file.

    HeapMem is TI-RTOS's implementation for  managing the heap. Please refer to section 10 in this TI-RTOS kernel workshop about managing heap using HeapMem and it is basically similar to the standard C heap memory allocation using malloc(). There are other implementation of heap memory management such as HeapBuf and HeapMultiBuf which can be more efficient. 

    https://training.ti.com/sites/default/files/docs/TI_RTOS_Kernel_Workshop_Student_Guide_rev4.00.pdf