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.

TMS320F28379D: Stack Usage: Unused functions being included.

Part Number: TMS320F28379D

I am using the "Stack Usage" tool in CCS to get an idea of what parts of the code are taking up most space. I include a header file which, amongst other things, defines Park and Inverse Park transform functions which are not called by my current code. The sine and cosine operations within those are showing very large stack usage.

Question 1: Does the Stack Usage function show the stack usage of functions whether they are included in the final executable or not? If not, why might these unused functions be showing in my stack usage?

Question 2: Since I am using an F28379D with floating point support enabled, is it normal that the sine and cosine functions should use 636 bytes of stack each? Technical brief SPRY288B suggests as an example that a Park transform could take as little as 13 CPU cycles. I realise my implementation using sine and cosine from math.h may not be as efficient, but such large stack usage is making me suspect that a long and complex approximation is being done and there may be a problem. 

void control_ab_to_dq (comp_num * p_ab,
                       float * p_theta,
                       dq_quantity * p_dq)
{
    p_dq->d = p_ab->real*cos(*p_theta) + p_ab->imag*sin(*p_theta);
    p_dq->q = p_ab->real*-sin(*p_theta) + p_ab->imag*cos(*p_theta);

    return;
}

  • You might refer to the "TMS320C28x Optimizing C/C++ Compiler User's Guide" (SPRU514) to use the Trigonometric Math Unit (TMU) that only needs a few CPU cycles for trigonometric functions.

    Also, you might refer to the  C28x Optimization Guide on writing optimized code for the C28x CPU as the link below.

    https://software-dl.ti.com/C2000/docs/optimization_guide/index.html

  • Thanks Yanming. Table 7-8 was very useful as it lists the compiler intrinsics to make sure that the TMU is used. I had assumed that the compiler would use the TMU by default as long as it was enabled in the build settings. This has resolved my original issue as the execution is now much faster. I see it also includes instructionf for multiplying and dividing by 2*pi so I will make use of those too.

    On a similar note, divf32() divides one float by another. May I ask, if I simply use the "/" operator to divide one float by another, what happens? Clearly the code works fine but does this lead to a less efficient computation than if I were to replace all my "/"s with the divf32() function?

  • Does the Stack Usage function show the stack usage of functions whether they are included in the final executable or not?

    If the function is not optimized out, then stack usage is shown for it.  Try building with higher levels of optimization.  If a function is optimized away, perhaps by being inlined everywhere it is called, then no stack usage is shown for it.

    Thanks and regards,

    -George