Memory allocation Issue

Hi all!
When we used malloc of size 2**15 in C code, it does not allocate.

uint16_t *out = (uint16_t *)malloc(samples_size * sizeof(uint16_t));
if (!out) {
fprintf(stderr, "Memory allocation for out failed.\n");
exit(1);
}
unsigned int samples_size       = 1 << 15;

DTCM 256kb and also ITCM in our chip (ARM Cortex M7) is 256kb.

CM7_DTCMCR
x 0xE000EF94
0xE000EF94: 0x00000049

CM7_ITCMCR
x 0xE000EF90
0xE000EF90: 0x00000049

It seems that I cannot use all 256kb that I have in DTCM.
Can you give me insights through this?

Based on ARM support, I have to located this (via scatterloading region ARM_LIB_(STACK)HEAP), but I do not know how to do it?
Appreciate your kind support and assistance.

Parents
  • Hi again!

    I Went through the description and wrote this scatter file

    /* Define the entire 256 kB DTCM region */
    LR_DTCM 0x20000000 0x00040000 {

    /* Execution region for code and read-only data.
    Here we reserve 128 kB from 0x20000000 to 0x2001FFFF. */
    ER_DTCM 0x20000000 0x00020000 {
    *(InRoot$$Sections)
    *(.text*)
    *(.rodata*)
    *(.constdata*)
    *(.ARM.Collect*)
    *(+RO)
    }

    /* Execution region for read-write data.
    Here we reserve 32 kB from 0x20020000 to 0x20027FFF. */
    RW_DTCM 0x20020000 0x00008000 {
    *(.data*)
    *(.bss*)
    *(+RW)
    }

    /* Define the heap region for dynamic allocations.
    This reserve is 64 kB from 0x20028000 to 0x20037FFF. */
    ARM_LIB_HEAP 0x20028000 EMPTY 0x00010000 {
    /* Heap region: 64 kB available for malloc() */
    }

    /* Define the stack region.
    Here we reserve 32 kB from 0x20038000 to 0x2003FFFF. */
    ARM_LIB_STACK 0x20038000 EMPTY 0x00008000 {
    /* Stack region: 32 kB */
    }
    }

    Any suggestions if it is the right one to dedicate 64kB of 256kB from DTCM?

    Warm regards


Reply
  • Hi again!

    I Went through the description and wrote this scatter file

    /* Define the entire 256 kB DTCM region */
    LR_DTCM 0x20000000 0x00040000 {

    /* Execution region for code and read-only data.
    Here we reserve 128 kB from 0x20000000 to 0x2001FFFF. */
    ER_DTCM 0x20000000 0x00020000 {
    *(InRoot$$Sections)
    *(.text*)
    *(.rodata*)
    *(.constdata*)
    *(.ARM.Collect*)
    *(+RO)
    }

    /* Execution region for read-write data.
    Here we reserve 32 kB from 0x20020000 to 0x20027FFF. */
    RW_DTCM 0x20020000 0x00008000 {
    *(.data*)
    *(.bss*)
    *(+RW)
    }

    /* Define the heap region for dynamic allocations.
    This reserve is 64 kB from 0x20028000 to 0x20037FFF. */
    ARM_LIB_HEAP 0x20028000 EMPTY 0x00010000 {
    /* Heap region: 64 kB available for malloc() */
    }

    /* Define the stack region.
    Here we reserve 32 kB from 0x20038000 to 0x2003FFFF. */
    ARM_LIB_STACK 0x20038000 EMPTY 0x00008000 {
    /* Stack region: 32 kB */
    }
    }

    Any suggestions if it is the right one to dedicate 64kB of 256kB from DTCM?

    Warm regards


Children