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.

HeapMem out of memory when creating a Task

Other Parts Discussed in Thread: SYSBIOS

I'm attempting to dynamically create a new task on a C6674, however when I attempt to do so I get the following error:

[C66xx_0] ti.sysbios.heaps.HeapMem: line 294: out of memory: handle=0x10826d18, size=76
xdc.runtime.Error.raise: terminating execution

The C code I'm using to create the task is as follows:

Task_Handle backgroundTask;
backgroundTask = Task_create((Task_FuncPtr)BackgroundTask, NULL, NULL);
//if (backgroundTask == NULL) {
//	System_abort("Task create failed");
//}

System_printf("Starting SYSBIOS\n");
System_flush();
BIOS_start();

I examined the stack in the ROV, and saw the following:

which lead me to believe that the stack was not big enough, however expanding the BIOS.heapSize still resulted in a stack overflow.  Upon examining the memory at the stackBase location, I saw that the entire stack was cleared to 0x00000000 before the code even executes.  I saw elsewhere on E2E that the stack should be initialized to 0xBEBEBEBE.  While changing the linker file to set the .far section as NOINIT stopped the stack from being cleared to 0, the data there was only garbage and still not 0xBEBEBEBE.

I'm attempting to figure out why the stack isn't being properly initialized as I assume this is the reason behind not being able to create a task.  I've already verified that creating a new task works using the "Typical Project" for SYSBIOS and that the stack is properly initialized so it seems like whatever does the stack initialization isn't running in my code.  I was wondering if anyone could point me to where this init code is located so I can figure out how to get it to run.  I've also attached my .cfg file.2046.app.cfg

  • Keith,

    In your application, you are creating a task with default parameters values (a NULL value is being passed to params).  And the default task stack size for C6674 is 2048. But looks like this stack size is insufficient for the task function "BackgroundTask". Can you increase the task's stack size?

    Here is a code snippet for setting stack size when creating a task:

    Task_Handle taskHandle;
    Task_Params taskParams;
    Error_Block eb;
    Task_Params_init(&taskParams);
    taskParams.stackSize = 4096;    /*set your stack value*/
    taskHandle = Task_create((Task_FuncPtr)BackgroundTask, &taskParams, &eb);
    if (taskHandle == NULL) {
        System_abort("Task create failed");
    }

    Vikram

  • Vikram,

    Thanks for your quick response.  I can dial up the taskParams.stackSize to 32,768 and still get the same problem.  The error I am getting seems to indicate that the error is with the SYSBIOS heap being full rather than the Task heap.

  • Keith,

    In SYS/BIOS, heaps are system level only whereas the stacks are both system level and task level. When a Task is dynamically created (i.e. using Task_create()), memory is allocated on the heap for a Task object and the Task stack. So, when you dial up the taskParams.stackSize, a equivalent value should be dialed up on BIOS.heapSize if you are creating the Task dynamically.

    If you still see the same problem, please share your code so that I can debug it on my PC.

    Vikram
  • Vikram,

    I discovered that the problem I'm seeing is related to the RTS libraries, specifically the order with which the autogenerated linker.cmd and my custom linker file are linked.  When the autogenerated linker.cmd file is linked first the task starts correctly, but when my custom linker file is linked first it fails.  Upon examining these two files I noticed that both were including different versions of the RTS library.  The linked library sections are as follows:

    linker.cmd (Generated by Code Composer at compile time)

    -l"C:\Company\controller\dev\family\hardware\C6674\dsp0\Product\configPkg\package\cfg\app_pe66.oe66"
    -l"C:\ti\bios_mcsdk_02_01_02_06\bios_6_33_06_50\packages\ti\sysbios\lib\instrumented_e66\sysbios\sysbios.lib"
    -l"C:\ti\bios_mcsdk_02_01_02_06\xdctools_3_23_04_60\packages\ti\targets\rts6000\lib\ti.targets.rts6000.ae66"
    -l"C:\ti\bios_mcsdk_02_01_02_06\xdctools_3_23_04_60\packages\ti\targets\rts6000\lib\boot.ae66"

    link.cmd (userlinker file)

    ..\..\..\..\extern\ti\c6000\lib\mathlib.6674_elf.lib
    ..\..\..\..\extern\ti\c6000\lib\Company.Rts6600_elf.lib
    NANT_DIR_MCSDK2\pdk_C6678_1_1_2_6\packages\ti\csl\lib\ti.csl.ae66
    NANT_DIR_MCSDK2\pdk_C6678_1_1_2_6\packages\ti\drv\pcie\lib\ti.drv.pcie.ae66

    A note: Company.Rts6600_elf.lib is almost identical to the standard rts6600.lib but compiled with interrupt_threshold set to 1

    However, removing the linking of Company.Rts6600_elf.lib from my custom linker file causes the project to no longer link with the following error:

    <Linking>
    1>                                       undefined             first referenced                                                                                                     
    1>                                        symbol                   in file                                                                                                          
    1>                                       ---------             ----------------                                                                                                     
    1>                                       HOSTwrite             C:\Company\controller\dev\a3200\hardware\C6674\dsp0\Product\configPkg\package\cfg\app_pe66.oe66                    
    1>                                       __TI_decompress_none                                                                                                                       
    1>                                       __TI_decompress_rle24                                                                                                                      
    1>                                       __TI_zero_init                                                                                                                             
    1>                                       __c6xabi_divu         ./obj/commands.obj                                                                                                   
    1>                                       __c6xabi_divull       C:\ti\bios_mcsdk_02_01_02_06\bios_6_33_06_50\packages\ti\sysbios\lib\instrumented_e66\sysbios\sysbios.lib<BIOS.obj>  
    1>                                       __c6xabi_fixdlli      ./obj/commands.obj                                                                                                   
    1>                                       __c6xabi_fixdu        ./obj/pid.obj                                                                                                        
    1>                                       __c6xabi_fixfu        ./obj/pid.obj                                                                                                        
    1>                                       __c6xabi_fltllid      ./obj/commands.obj                                                                                                   
    1>                                       __c6xabi_nround       ./obj/commands.obj                                                                                                   
    1>                                       __c6xabi_pop_rts      ./obj/1394asynchronous.obj                                                                                           
    1>                                       __c6xabi_push_rts     ./obj/1394asynchronous.obj                                                                                           
    1>                                       __c6xabi_remu         C:\ti\bios_mcsdk_02_01_02_06\bios_6_33_06_50\packages\ti\sysbios\lib\instrumented_e66\sysbios\sysbios.lib<BIOS.obj>  
    1>                                       __c6xabi_roundf       ./obj/galvo.obj                                                                                                      
    1>                                       _args_main            C:\ti\bios_mcsdk_02_01_02_06\xdctools_3_23_04_60\packages\ti\targets\rts6000\lib\boot.ae66<boot.oe66>                
    1>                                       _nop                  C:\Company\controller\dev\a3200\hardware\C6674\dsp0\Product\configPkg\package\cfg\app_pe66.oe66                    
    1>                                       _register_lock        C:\Company\controller\dev\a3200\hardware\C6674\dsp0\Product\configPkg\package\cfg\app_pe66.oe66                    
    1>                                       _register_unlock      C:\Company\controller\dev\a3200\hardware\C6674\dsp0\Product\configPkg\package\cfg\app_pe66.oe66                    
    1>                                       abort                 C:\ti\bios_mcsdk_02_01_02_06\xdctools_3_23_04_60\packages\ti\targets\rts6000\lib\ti.targets.rts6000.ae66<System.oe66>
    1>                                       atexit                C:\ti\bios_mcsdk_02_01_02_06\xdctools_3_23_04_60\packages\ti\targets\rts6000\lib\ti.targets.rts6000.ae66<System.oe66>
    1>                                       exit                  C:\ti\bios_mcsdk_02_01_02_06\xdctools_3_23_04_60\packages\ti\targets\rts6000\lib\ti.targets.rts6000.ae66<System.oe66>
    1>                                       fmod                  ./obj/feedback.obj                                                                                                   
    1>                                       fmodf                 ./obj/statusItemsA3200.obj                                                                                           
    1>                                       memcpy                ./obj/1394asynchronous.obj                                                                                           
    1>                                       memset                ./obj/CrcFunctions.obj                                                                                               
    1>                                       modff                 ./obj/galvo.obj                                                                                                      
    1>EXEC : error #10234-D: unresolved symbols remain

    It seems like these functions aren't included in the default RTS library that came with XDC.  Is this correct?  If so, is there some way to specify which libraries are linked in the autogenerated linker.cmd.

  • Keith,

    I think at least some of those symbols should be in the RTS library. My guess is that the object files/library containing these symbols are placed after the rts library on the link line. Are you building using TI codegen? Can you add -x (or --reread_libs) to the link line?

    Vikram
  • Vikram,

    Adding the --reread_libs flag does not appear to work.  I can reproduce the working case my manually moving the linked libraries from the autogenerated linker file to my user linker file, which is linked after the .obj files.  However removing the linking of Company.Rts6600_elf.lib still causes the same undefined symbol errors.  Is it possible these functions were not included in this old version of the RTS library?  By looking in my xdc_tools target package, it looks like ti.targets.rts6000.ae66 is version 7.2.0B2 and Company.Rts6600_elf.lib is based on version 7.4.6.  I couldn't find any version history or release notes for these RTS lib versions, though.

  • Keith,

    I looked into this issue a little more and I think you are missing the C Standard RTS library "libc.a" on the link line. Can you please check?

    Vikram

  • Vikram,

    I can confirm that adding libc.a to the user linker file fixes the problem. Thank you!