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.

DDR3 dynamic memory allocation

Other Parts Discussed in Thread: SYSBIOS

Hi,

First I apologize if there's other topic that answers my question, but I couldn't find it.

I'd like to know what I shoul do to allocate memory in C6678 DDR3 dynamically.

Searching the forum I found a way to do it statically creating a memory section in cmd file

SECTIONS
{
    multicore_data: load >> DDR3
}

and putting my array in this section in the C code:

int array[SIZE] = {0};
#pragma DATA_SECTION(array, "multicore_data");

It does work, but I want to do it using dynamic allocation and Memory_alloc which syntax is:

Ptr Memory_alloc(IHeap_Handle heap, SizeT size, SizeT align, Error_Block *eb);

So, how do I create this heap in the DDR3 memory? Is it possible or I can only use static arrays?

Thanks in advance.

  • I don't recognize that Memory_alloc call.  It is not part of the standard compiler RTS library.  Thus, my ability to help is limited.

    You need to determine the name of the section which contains the memory managed by that Memory_alloc function.  That will have to come from the vendor who supplies Memory_alloc.  Once you know that, you can allocate that section to DDR3 just as you did with the multicore_data section.

    Thanks and regards,

    -George

  • Hi George, thanks for your answer

    You're right it's not part of SYS/BIOS library, its header is:

    #include <xdc/runtime/Memory.h>

    So the work around that I found in other two topics (topic 1 and topic 2) in the forum was:

    In the cfg file insert this code:

    var SYSTEM_HEAPSIZE = 0x800; // Vary based on your requirement

    var NUMCORES = 2; // Vary based on your requirement

    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');

    var heapMemParams = new HeapMem.Params();

    heapMemParams.size = SYSTEM_HEAPSIZE; // Set previously

    heapMemParams.sectionName = "systemHeap";

    Program.global.heap0 = HeapMem.create(heapMemParams);

    Program.global.HEAPID = NUMCORES; // Set previously

    Program.sectMap["systemHeap"] = "DDR3"; // This maps it to DDR3

    Memory.defaultHeapInstance = Program.global.heap0; // Set the new heap as the default one, without this it probably won't work

    And in the C code:

    int *artest; 
    
    Error_Block eb; 
    
    Error_init(&eb); 
    
    artest = (int *) Memory_alloc(0, 16*sizeof(int), 32, &eb);

    One important thing is to set the new heap that has been created as the default heap, so you can pass 0 or NULL as the fisrt argument to the Memory_alloc call, if instead of that you try to pass the heap name like:

    artest = (int *) Memory_alloc(heap0, 1024*512*sizeof(int), 32, &eb);

    You will get the following error message:

    #169 argument of type "ti_sysbios_heaps_HeapMem_Handle" is incompatible with parameter of type "xdc_runtime_IHeap_Handle"

    Indicating what you said previously, it's not an RTS function.

    One more note: if you choose a large heap size (0x80000000) it will be allocated in DDR3 because it's the only memory with enough space, but if you use a heap size that can fit elsewhere you have to explicitly map it to DDR3 or it won't be allocated in DDR3.

    Best regards