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.

Malloc fails in simple DSP program on C674x simulator

Guru 10685 points
Other Parts Discussed in Thread: SYSBIOS

I've written a simple DSP program which uses malloc to allocate 320x240x3 = 230,400 bytes.

The call to malloc keeps failing. I'm using the C674x simulator in CCS 5 to test my program. I think the problem is the way my simulator is configured. Please could someone give me tips on how to "give" main memory to the simulator? My CPU is a DM8168 but I'm just trying to simulate something running on the C674x core.

Here's the code causing the problem:

#include <stdio.h>
#include <stdlib.h>

#define OUTPUT_WIDTH    320
#define OUTPUT_HEIGHT    240

/*
 * hello.c
 */
void main(void) {
    char* buf = malloc(OUTPUT_WIDTH*OUTPUT_HEIGHT*3);
    int x, y;

    if(!buf)
    {
        printf("Problem allocating buffer.\n");
        return;
    }

}

Thanks,

Ralph

  • Is this a pure C program.i.e. Does not use sysbios/xdc. If so the heap size (from which malloc allocates) should be specified in the linker options of your project:

    The following Linker options can be specified following the -z
    option.  Linking is only enabled if -z is used and -c is not:

    Basic Options:
      -o,--output_file=file        Specify output file name
      -m,--map_file=file           Input and output sections listed into <file>
      --heap_size,-heap,--heap=size
                                   Heap size for C/C++ dynamic memory allocation


  • (Sorry, I accidentally verified your answer a bit soon...)

    Thanks for the reply. Yes, it's a pure C program, no BIOS.

    I went to project properties and under C6000 linker->basic options I set the heap size to 0x3200000 (50MB) and then the project no longer compiled:

    #10099-D run placement fails for object    DM8168.cmd    /testpattern    line 78    C/C++ Problem

    The error appears to come from my DM8168.cmd file:

    MEMORY
    {
    #ifndef DSP_CORE  /* ARM memory map */

        L3OCMC0:      o = 0x40300000  l = 0x00040000  /* 256kB L3 OCMC SRAM */
        L3OCMC1:      o = 0x40400000  l = 0x00040000  /* 256kB L3 OCMC SRAM */
        DSPSHL2RAM:   o = 0x40800000  l = 0x00040000  /* 256kB Shared DSP L2 RAM */
        DSPSHL1PRAM:  o = 0x40E00000  l = 0x00008000  /* 32kB Shared DSP L1 Program RAM */
        DSPSHL1DRAM:  o = 0x40F00000  l = 0x00008000  /* 32kB Shared DSP L1 Data RAM */
        DDR0:         o = 0x80000000  l = 0x40000000  /* 1GB external DDR Bank 0 */
        DDR1:         o = 0xC0000000  l = 0x40000000  /* 1GB external DDR Bank 1 */

    #else             /* DSP memory map */

        HDVICP0:      o = 0x00400000  l = 0x00040000  /* 256kB HDVICP0 UMAP1 */
        HDVICP1:      o = 0x00500000  l = 0x00040000  /* 256kB HDVICP1 UMAP1 */
        DSPL2RAM:     o = 0x00800000  l = 0x00040000  /* 256kB DSP L2 RAM */
        DSPL1PRAM:    o = 0x00E00000  l = 0x00008000  /* 32kB DSP L1 Program RAM */
        DSPL1DRAM:    o = 0x00F00000  l = 0x00008000  /* 32kB DSP L1 Data RAM */

    #endif
    }

    SECTIONS
    {
    #ifndef DSP_CORE   /* ARM memory map */

        .text          >  L3OCMC0
        .stack         >  L3OCMC0
        .bss           >  L3OCMC0
        .cio           >  L3OCMC0
        .const         >  L3OCMC0
        .data          >  L3OCMC0
        .switch        >  L3OCMC0
        .sysmem        >  L3OCMC0
        .far           >  L3OCMC0
        .args          >  L3OCMC0
        .ppinfo        >  L3OCMC0
        .ppdata        >  L3OCMC0
     
        /* TI-ABI or COFF sections */
        .pinit         >  L3OCMC0
        .cinit         >  L3OCMC0
     
        /* EABI sections */
        .binit         >  L3OCMC0
        .init_array    >  L3OCMC0
        .neardata      >  L3OCMC0
        .fardata       >  L3OCMC0
        .rodata        >  L3OCMC0
        .c6xabi.exidx  >  L3OCMC0
        .c6xabi.extab  >  L3OCMC0

    #else              /* DSP memory map */

        .text          >  DSPL2RAM
        .stack         >  DSPL2RAM
        .bss           >  DSPL2RAM
        .cio           >  DSPL2RAM
        .const         >  DSPL2RAM
        .data          >  DSPL2RAM
        .switch        >  DSPL2RAM
        .sysmem        >  DSPL2RAM         /*problem line*/
        .far           >  DSPL2RAM
        .args          >  DSPL2RAM
        .ppinfo        >  DSPL2RAM
        .ppdata        >  DSPL2RAM
     
        /* TI-ABI or COFF sections */
        .pinit         >  DSPL2RAM
        .cinit         >  DSPL2RAM
     
        /* EABI sections */
        .binit         >  DSPL2RAM
        .init_array    >  DSPL2RAM
        .neardata      >  DSPL2RAM
        .fardata       >  DSPL2RAM
        .rodata        >  DSPL2RAM
        .c6xabi.exidx  >  DSPL2RAM
        .c6xabi.extab  >  DSPL2RAM

    #endif
    }

    The error in the help says that "this indicates that the device has insufficient physical memory" however I'm using a simulator so how can this be? Do I need to increase .sysmem or change the memory section that it refers to?

    Thanks,

    Ralph

  • On the 8168 DSP L2 RAM is limited to 256K (as you have correctly set in your linker cmd file). You can redirect the .sysmem to DDR instead of L2SRAM as DDR is 2G and can fit a 50MB heap.

  • I had to make sure the "DDR0" section got included by the DSP then I was able to include it in the DSP's memory map and it now all works.

    Thanks for your help.
    Ralph