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.

CCS/TMS320C6713B: how to determine the amount of stack and heap space required by the application and allocate it optimally?

Part Number: TMS320C6713B

Tool/software: Code Composer Studio

To All,

I am using the CCS Version: 5.5.0.00077. I have to optimize the size for the heap and stack.

Q1  After using call_graph tool, the maximum amount of stack is 2424. May I know how to setup stack size based on known information?

Q2  I have printed out the malloc total size:1056.

I allocated Heap size of 0x450 and execute the program in CCS, there was error in console:

TMS320C6713: Error: Illegal opcode at pc = 0x00028594 Illegal opcode (40b167e7) at pc = 0x00028598 Illegal opcode at pc = 0x00028598 

when I allocated Heap size of 0x500,there was sometimes error in console:

TMS320C6713: Error: *** Runtime error at PC = 00000030      Resource(s) D Unit/Read Port on side B in conflict in E1 phase. Ref SPRU189F Sec 3.7, Sec 4.5, Sec 7.2

Finally, I allocated Heap size of 0x550 and it was working.

May I know how to determine heap size to fit the heap requirement?

Thanks.

Betty Yeh

  • user5815234 said:
    Q1  After using call_graph tool, the maximum amount of stack is 2424. May I know how to setup stack size based on known information?

    In CCS, right click on the name of the project and select Show Build Settings.  The screen shot below shows how to access the settings for both heap and stack size.  Note this screen shot is from CCS 6.2.  But it is similar for CCS 5.5.

    The errors you show may be related to running out of heap. But maybe not.  It might be the case that the root cause error is present all the time, but only exposed when certain functions or data are at particular memory addresses.  By adding more heap, things move around in memory, and that may either hide or expose the problem.  So I recommend you make the effort to work out the root cause of these problem, instead of just guessing the problem is related to heap size.

    Be sure you always check the return value from malloc and similar functions.  When the allocation request cannot be met, NULL is returned.  Your code needs to explicitly check for NULL, then go into error recovery when that happens.

    user5815234 said:
    May I know how to determine heap size to fit the heap requirement?

    There is no static way to determine heap usage, like there is with stack.  It can only be determined at run time.  I'm not aware of any examples from TI on how you might determine max heap usage at run time.  Consider adding a counter that is incremented by the number of bytes allocated by each call to malloc.  Using the debugger, see how high it gets.  If you also call free to return memory to the heap, this counter method is not accurate.  But it might be good enough for your purposes.

    Thanks and regards,

    -George

  • Hello,

    to reduce stack(s) size(s):
    - recursion
    - interrupt nesting
    - functions nesting
    should be avoided.
    Regarding heap sizes:
    always check malloc(), object creation, etc. results and properly handle when allocation is impossible.
    Easy to say but now way to do the above steps when using 3rd party libs with no source code available, ex: security libs.

    There are no silver bullets.
  • Please let us know whether you have resolved the problem, and how you resolved it.

    Thanks and regards,

    -George

  • Since it has been a while, I presume you have resolved your problem.  I'd appreciate hearing how you resolved it.

    Thanks and regards,

    -George

  • I still try to find out the root cause of these problem and will keep monitor and check the return value from malloc and similar functions.
    I'll reply this post when resolve my problem.
    Thanks and regards