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.

sys bios - iheap and dynamic memory allocation

Other Parts Discussed in Thread: TMS320F28335, SYSBIOS

Hey,

 

I am facing issues in dynamic memory allocation on TMS320F28335 platform, using SYS BIOS (Compiler Ver: TI v6.2.0)

I have alligned my .sysmem and .esysmem to the required memory zones as -

 

.sysmem

: > TEST_ZONE1 | TEST_ZONE2 PAGE = 1

/* heap */

.esysmem : > TEST_ZONE1 | TEST_ZONE2

PAGE = 1 /* far heap */

 

And both my test zones (1,2) are mapped to the external memory zone - xintf zone 7

****************************************************************************************

When i use -

buffPtr = Memory_valloc(NULL ,totalLen_u16,0,0, NULL);

the ccs help says if the 1st arg is NULL, it should take the default heap.

It never assigns the buffPtr to test zones, but the ptr still lies in my internal memory -

my local ptrs sit in the - .stack section and global ptrs sit in the .bss and .ebss sections that are mapped to internal memory.

****************************************************************************************

When i use -

buffPtr = Memory_valloc(TEST_ZONE1,totalLen_u16,0,0, NULL);

It throws error saying the TEST_ZONE1 is not compatible with the iheap_Handle.

****************************************************************************************

No type-castings work, niether am i able to create a similar heap.

 

Please assist me in mapping my dynamically allocated buffers to external memory - i.e. to the test zones.

Also how should i create the iHeap.

  • Hi Arpan,

    You can place the SYS/BIOS system heap by adding the following lines of code to your *.cfg file:

    var BIOS = xdc.useModule('ti.sysbios.BIOS');
    BIOS.heapSize = <heap size in bytes>;
    BIOS.heapSection = ".esysmem";

    The above assumes that there is an output section called ".esysmem" in your linker script that is placed in the desired memory segment.

    (Please read section 6.7.2 in the SYS/BIOS user guide for more info on how dynamic memory allocation works - http://www.ti.com/lit/ug/spruex3m/spruex3m.pdf)


    Best,

    Ashish

  • Thank you Ashish for your response. I was doing the same earlier that would end me with an exception just after the code is flashed using the JTAG - it goes to an unreacheable loop.

     

    C$L1:
    3085b7:   6F00        SB           C$L1, UNC
    exit:

     

    When i goive the memroy segment name here it runs fine (for some time) -

    BIOS.heapSection =

    "TEST_ZONE1";

    BIOS.heapSize = 4096;

    BIOS.heapTrackEnabled =

    false;

     

    But soon it again goes to the unreacheable loop. trying to identify what is going wrong. Some memory placements are going wrong in my linker file.

     

    Can you just cross verify -

     

    /* BIOS Data Sections */

    .args : > FLASH_ZONE PAGE = 0

    .stack : > MSARAM | L03SARAM PAGE = 1

    /* BIOS Stac Section */

    .gblinit : > FLASH_ZONE PAGE = 0

    /* DSP/BIOS Init Tables */

    .trcdata : > L47SARAM PAGE = 1

    /* TRC Initial Value */

    .sysdata : > L03SARAM PAGE = 1

    /* BIOS Kernel State */

    .*obj : > L03SARAM PAGE = 1

    /* BIOS Conf Section */

    /* BIOS Code Sections */

    .bios : > FLASH_ZONE PAGE = 0

    /* BIOS Code Section */

    .sysinit : > FLASH_ZONE PAGE = 0

    /* Startup Code Section */

    .rtdx_text : > FLASH_ZONE PAGE = 0

    /* RTDX Text Segment */

    .hwi : > L03SARAM PAGE = 1

    /* Function Stub Memory */

    .hwi_vec : > PIEVECT PAGE = 0

    /* Interrupt Service Table Memory */

    /* Compiler Sections: Allocate uninitalized data sections */

    .text : > FLASH_ZONE PAGE = 0

    /* Text Section */

    .

    switch : > FLASH_ZONE PAGE = 0

    /* Switch Jump Tables */

    .bss : > MSARAM | L47SARAM | TEST_ZONE1 PAGE = 1

    /* C Variable Section */

    .ebss : > MSARAM | L47SARAM | TEST_ZONE1 PAGE = 1

    /* global and static variables */

    /* .cinit : > FLASH_ZONE PAGE = 0 /* Data Initialization Section */

    .pinit : > FLASH_ZONE PAGE = 0

    /* C Function Initialization Table */

    .econst : > FLASH_ZONE PAGE = 0

    /* Constant Section */

    .

    const : > FLASH_ZONE PAGE = 0

    /* Constant Section */

    .printf : > FLASH_ZONE PAGE = 0

    /* Constant Section */

    .data : > MSARAM | L47SARAM PAGE = 1

    /* Data Section */

    .cio : > MSARAM | L47SARAM PAGE = 1

    /* Data Section */

    .sysmem : > TEST_ZONE1 | TEST_ZONE2 PAGE = 1

    /* heap */

    .esysmem : > TEST_ZONE1 | TEST_ZONE2 PAGE = 1

    /* far heap */

    .sysHeap : > TEST_ZONE1 | TEST_ZONE2 PAGE = 1

    /* system heap */

     

    /* Load Addresses */

    .bios : > FLASH_ZONE PAGE = 0

    /* BIOS Code Section */

    .sysinit : > FLASH_ZONE PAGE = 0

    /* Startup Code Section */

    .gblinit : > FLASH_ZONE PAGE = 0

    /* DSP/BIOS Init Tables */

    .trcdata : > FLASH_ZONE PAGE = 0

    /* TRC Initial Value */

    .text : > FLASH_ZONE PAGE = 0

    /* Text Section */

    .

    switch : > FLASH_ZONE PAGE = 0

    /* Switch Jump Tables */

    /*.cinit : > FLASH_ZONE PAGE = 0 /* Data Initialization Section */

    .cinit : > L47SARAM PAGE = 1

    /* Data Initialization Section */

    .pinit : > FLASH_ZONE PAGE = 0

    /* C Function Initialization Table */

    .econst : > FLASH_ZONE PAGE = 0

    /* Constant Section */

    .

    const : > FLASH_ZONE PAGE = 0

    /* Constant Section */

    .printf : > FLASH_ZONE PAGE = 0

    /* Constant Section */

    .data : > FLASH_ZONE PAGE = 0

    /* Data Section */

    .rtdx_text : > FLASH_ZONE PAGE = 0

    /* RTDX Text Segment */

  • Hi Arpan,

    What is the memory range you are specifying for TEST_ZONE1/2 ? The memory addresses should be < 0x10000 if you are placing the heap buffer in TEST_ZONE1/2 as the system heap will be used to allocate the stacks (C28 has a 16-bit SP and hence the stack pointer can only reference addresses 0-0xFFFF).

    Best,

    Ashish

  • Hi Ashish,

     

    TestZones are my external memory mapped memory segments [xintf zone 7: from0x20 0000 to 0x23 0000]

    That's where i intend to keep my dynamically allocated buffers.

     

  • Hi Arpan,

    I think a better option for you is to leave the system heap as is and create a separate heap for your buffers. You can for example create a heap managed by HeapMem module and place it in XINTF Zone 7. This can be done at runtime or at build time in your *.cfg script. I have shown an example of how to create a heap at build time:

    *.cfg code

    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
    var heapMemParams = new HeapMem.Params;
    heapMemParams.size = <size bytes>;
    
    heapMemParams.align = <desired alignment>;
    heapMemParams.sectionName = ".myHeapMemSect";
    Program.global.myBufferHeap = HeapMem.create(heapMemParams);
    

    Using the new heap in *.c code:

    #include <xdc/runtime/IHeap.h>
    #include <xdc/runtime/Memory.h>
    #include <ti/sysbios/heaps/HeapMem.h>
    
    #include <xdc/cfg/global.h>
    
    func()
    {
        IHeap_Handle heap = HeapBuf_Handle_upCast(myBufferHeap);
        Memory_alloc(heap, BUFSIZE, 0, NULL);
    }

    Best,

    Ashish

  • Ashish,

     

    Thank alot for your input. This helped.

    I'm using a customised heam memory now. Great..

     

    Further to identify the memory stats, i m using -

    Memory_getStats(testMem_iheap, (xdc_runtime_Memory_Stats *)&dynMemSts);

     

    it gives me correct total size parameter, but the other two params for the free mem and largest free mem size are corrupted.

    Can yu provide any inputs..?

  • Hi Arpan,

    I need some more background about how your application is using Memory_getStats() before I can help you. Also, how did you determine that the free mem and largest free size fields being returned by Memory_getStats() are corrupted ?

    Best,
    Ashish

  • I came to that conclusion as i am getting this output information from the memory status call -

     

    totalSize = 0X0001 0000 - correct as per my configuration
    totalFreeSize = 0x486E 0720 - corrupted
    largestFreeSize = 0x486E 0720 - corrupted

    Which doesnt seem to be logical.

     

    Let me know your inputs on this.

  • Hi Arpan,

    The total free size is computed by traversing a linked list of all free blocks. If the linked list somehow got corrupted it might be possible that some garbage value is returned. You may want to debug this a little more. Can you try putting a breakpoint at ti_sysbios_heaps_HeapMem_getStats__E symbol (This function will be called internally by Memory_getStat) in the disassembly window and step through the total free size computation code ? While you step through the code, you can check if the free block head pointers are valid or not.

    Also, it might be helpful to look at the detailed ROV view for HeapMem module.

    Best,

    Ashish

  • Dear Ashish,

     

    Sorry for the delay in updates.

    I tried doing that, i am gertting error log in the ROV window which says - Corrupted free list header next ptr (0xbcc88165) at freeList entry 0x200100

     

    Also i am unable to get my xintf interrupt. Do you think this might be linked..?

  • Hi Arpan,

    You might want to use HeapTrack module to debug the heap free list corruption. Please read Section 6.8.4 of the user guide for more info on how to setup and use HeapTrack: http://www.ti.com/lit/ug/spruex3m/spruex3m.pdf (Section 6.8.4 Heap Track)

    cdoc for HeapTrack module: http://downloads.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/sysbios/6_37_01_24/exports/bios_6_37_01_24/docs/cdoc/index.html#ti/sysbios/heaps/HeapTrack.html


    Its hard to say if the heap problem is related to the xintf interrupt not being triggered. Can you also check if any of the task or hwi stacks have overflowed ? You can check task stack status from Task ROV view "detailed" tab and system stack status from Hwi ROV view "module" tab.

    Best,

    Ashish

  • No Ashish,

     

    I dont see any stac corruption in tasks or HWI module.

    Actually same things are working for me on DSP bios, on migrating to sys bios i m facing this issue. xintf is nt generating the interrupt at all. with same hardware.

     

     i think might have issue in my .cfg or .cmd file itself. trying to identify.