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.

How to Allocate Memory in External Memory(DDR3)

Other Parts Discussed in Thread: SYSBIOS

Hi,

  I am now debugging and validating an algorithm on the C674x-DSP in DM8168.  Since I have the Cortex-A8 bypassed, I have been able to connect and load a *.out program in the DSP.

  I managed to load data manually to the EXTERNAL MEMORY by using the "Load Memory" function of the XDS100v2 emualtor when I was debugging.  Although my program works well, it seems that I have never indicate my program that such an external block was being used inplicitly.  If there were some variables which allocated in the same address (where the data stay), my data would be ruined.  Thus, in order to avoid the potential data error, I want to create an Heap object which locates in External Memory (0x8000_0000 ~ 0x9FFF_FFFF), and manually load my data in that place.

  However, after adding a HeapMem Instance named "InHeap" in cfg file through the GUI in CCSv5, I add some code in main.c file:

main.c

...

    if (NULL == (inData = (XDAS_Int8 *)Memory_alloc(InHeap, TESTVECTOR_LEN, 0, &eb)))
    {
        System_printf("InData Alloc Error\n");
        System_exit(-2);
    }

...

It cast some error into the console:

'Building file: ../main.c'
'Invoking: C6000 Compiler'
"D:/TI/ccsv5/tools/compiler/c6000_7.4.2/bin/cl6x" -mv6740 --abi=eabi -g --include_path="D:/TI/ccsv5/tools/compiler/c6000_7.4.2/include" --include_path="G:/CCS_Workspace/xDM_Alg/naroah/g722enc" --display_error_number --diag_warning=225 --diag_wrap=off --preproc_with_compile --preproc_dependency="main.pp" --cmd_file="./configPkg/compiler.opt"  "../main.c"
"../main.c", line 56: warning #225-D: function declared implicitly
"../main.c", line 56: error #20: identifier "InHeap" is undefined
"../main.c", line 61: error #20: identifier "OutHeap" is undefined
"../main.c", line 107: warning #225-D: function declared implicitly
2 errors detected in the compilation of "../main.c".

>> Compilation failure
gmake: *** [main.obj] Error 1
gmake: Target `all' not remade because of errors.


The "implicitly declared function" was "Memory_alloc()", and "InHeap" is the Heapname I defined in the cfg file.

I don't know how to use the HeapMemory API properly.  Besides, I don't know which head file I should include, either.


Could you help me dealing with this problem? 


Naroah

Aug/13/2013

  • Hi Naroah,

    What kind of data are you refering to ? Is it some input that the algorithm uses that you need manually load ?

    In order to use Memory_alloc() in your application, you need to include <xdc/runtime/Memory.h> header file. Here's a link to the Xdctools cdoc that mentions the header name: http://rtsc.eclipse.org/cdoc-tip/index.html#xdc/runtime/Memory.html

    I would recommend using HeapMem_alloc() instead of Memory_alloc() to avoid casting  "InHeap" from HeapMem_handle to xdc_runtime_IHeap_Handle for use with Memory_alloc(). To use HeapMem APIs include <ti/sysbios/heaps/HeapMem.h> header file. HeapMem cdoc is available here: http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/bios/sysbios/6_35_03_47/exports/bios_6_35_03_47/docs/cdoc/index.html

    In order to fix the undefined error for "InHeap", include <xdc/cfg/global.h> in your application. Alternately, you could add an "extern HeapMem_Handle InHeap" to your app.

    Best,

    Ashish

  • Hi, Ashish

      Thank you for your reply!  It helps me so much.  Since I modified my program as what you suggest, it could be built perfectly:

    #include <xdc/runtime/Memory.h>
    #include <xdc/cfg/global.h>
    #include <ti/sysbios/heaps/HeapMem.h>

         if (NULL == (inData = ( XDAS_Int8 *)HeapMem_alloc(InHeap, TESTVECTOR_LEN, 0, &eb)))
        {
           System_printf( "InData Alloc Error\n");
           System_exit(-2);
        }
        if(NULL == ( outData= ( XDAS_Int8 *)HeapMem_alloc(OutHeap, TESTVECTOR_LEN / 4, 0, &eb)))
        {
           System_printf( "OutData Alloc Error\n");
           System_exit(-2);
        }

    // Processing
    ...

         if(NULL != inData)
                  HeapMem_free(InHeap, inData, TESTVECTOR_LEN);
        if(NULL != outData )
           HeapMem_free(OutHeap, outData, TESTVECTOR_LEN / 4);


     Just as you say, I decide to load data manually.  It is the input data that my algorithm tends to use.

     Although I could successfully build this project, the program still failed to alloc memory:

    ti.sysbios.heaps.HeapMem: line 307: out of memory: handle=0x8b040900, size=120800
    InData Alloc Error

      Noticing that I have set the HeapMem size in cfg file, I don't know what to do.

      I want to allocate a piece of memory whose size is 120800 Bytes at 0x9000_0000.  How could I modify my cfg file or source file to achieve this goal?

      I am sincerely looking forward to your reply.

    Naroah

    Aug/14/2013

  • Hi Naroah,

    I think there is a bug in the HeapMem_alloc() implementation that causes an out of memory error if you pass align = 0 to HeapMem_alloc(). I am trying to confirm this with the engineer who owns this module and will update when I hear back. For now, can you change the alignment field in the HeapMem_alloc() call to 2 (or some power of 2) and try ?

    You also need the place the HeapMem buffer at 0x90000000. To do this first create a new section ".myHeap" that is loaded at 0x90000000 by adding the following code to your cfg Script:

    Program.sectMap[".myHeap"] = new Program.SectionSpec();
    Program.sectMap[".myHeap"].loadAddress = 0x90000000;
    Program.sectMap[".myHeap"].runAddress = 0x90000000;

    Next, you need to set "Memory Section" under HeapMem Buffer Placement to ".myHeap".

    Best,

    Ashish

  • Hi Ashish,

      Thank you very much!  That's exactly what I needed!

      After changing the parameter of "alignment" from '0' to '2', the program works!  Referring to the "Variables: Watch Window", I find everything goes well:

      Further more, I followed your insturctions and changed the cfg file, indicating the Section Name in HeapMem Tab.  Rebuilding and reloading the program, I have got my goal achieved!  The inData and outData pointers get the right values as below:

       One more question remains.  Although I could succeffully have my program built, the compiler/linker still cast some warning onto the console:

    <Linking>
    "./configPkg/linker.cmd", line 157: warning #10083-D: LOAD placement ignored for ".InHeapMap":  object is uninitialized
    "./configPkg/linker.cmd", line 158: warning #10083-D: LOAD placement ignored for ".OutHeapMap":  object is uninitialized
    "./configPkg/linker.cmd", line 157: warning #10096-D: specified address lies outside memory map
    'Finished building target: TestG722Enc.out'

      It seems that these two section of memory should be initialized before being used.  I think I need to add additional lines in the cfg file to enable this feature.  But I don't know what to do.  How to get these warning settled?

      Thank you for your reply again.

      I am waiting for your approaching reply~  o^_^o

    Naroah

    Aug/15/2013

  • Hi Naroah,

    The easiest way to get rid of the warning is to get rid of the load placement. Delete this line from your *.cfg script:

    Program.sectMap[".myHeap"].loadAddress = 0x90000000;

    Since you are still specifying the run address, I believe the linker will make the load address same as the run address. Another option is to change the section type to NOINIT. I havent tested this but I feel this might fix the warning too.

    Program.sectMap[".myHeap"].type = NOINIT;

    You might want to post a question on the C6x compilers forum asking why the above warning gets generated.

    Best,
    Ashish

  • Ashish,

      Thank you for your help.  I would like to raise another post in C6x compilers forum and try to get this problem sloved.

      Here is the link:

    http://e2e.ti.com/support/development_tools/compiler/f/343/t/284926.aspx

      Thank you for your reply and precious help all the same.

    Naroah

    Aug/17/2013

     

  • Hi Naroah,

    Glad to help you. I think you should share the generated linker.cmd file in your C6x compiler forum's post. The compiler team are not very familiar with XDC scripts and would better understand the linker.cmd file. I have shown where to find the linker.cmd file using an example project:

    If you build with Release profile, the linker.cmd file will be in the Release/configPkg directory.

    Best,

    Ashish