Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed the week of November 23.

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: Enabling optimizer level 0 causes stack overflow on C2000

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

Dear TI support team,

When enabling optimizer level 0 on CPU1 of F28379D C2000 chip, I encounter a stack overflow. When disabling the optimizer, the stack usage is at ~5% of a 2K stack. When enabling the optimizer, stack usage jumps to ~104% resulting in an ITRAP. I fill the stack with pattern "A5A5" and I noticed that only the first few bytes of the stack are utilized, and then the SP (stack pointer) jumps down to near the end of the stack and starts utilizing the end of the stack, such that there is a large region of unused stack as noted by "A5A5".

I already ruled out static inline functions on my side, although C2000ware uses static inline functions so maybe the stack context frame is large and leaves a large memory region of stack unused?

Using the Stack Usage window I can see the stack usage of every function and nothing sticks out to me as concerning.

I set a hardware watchpoint for the end of the stack and I keep hitting the SCIB RX interrupt. However, I don't think it is the SCI B RX interrupt that is causing issues by itself since I have two modes that utilize SCI B RX interrupt, one of the modes causes stack overflow, and the other mode does not. The mode that causes stack overflow is more math/cpu intensive so I'm wondering if something is causing an overflow, but it's just weird to me that the stack pointer would skip such a large region of stack memory and utilize something near the end of the stack.

Any pointers on how to figure out the root cause would be great.

Thanks!

  • Hi Nigel,

    Let me check into this issue, i will get back.

    Thanks

    Aswin

  • Hi Nigel,

    Does any of your function use a large array or structure? 
    The compiler often generates a large local frame for functions with many local variables or complex math expressions, especially when optimization is Level 0. When a function starts, the compiler doesn't push variables one by one. It subtracts a constant value from the SP to reserve space for all local variables at once. This is probably the reason why the SP is skipping a large region. 

    Best Regards

    Siddharth

  • Hi Siddharth, on CPU1 there is a big ISR that has many function calls underneath, but no arrays bigger than 100 chars. This is what I found in SPRU514T Optimizing Compiler Guide where it seems that XAR2 may be used instead of SP:



    If your team doesn't think this is concerning to investigate and we can safely assume that optimizer level 0 is the root cause, then I suppose there's not much else I can do other than increasing the stack size.

  • Hi Nigel 

    Pls share the project if possible, to narrow dowm on the issue. 

    You can step through the disassembly and see if any function is incrementing the SP (For e,g.  ADDB SP, #num.) 

    Best Regards

    Siddharth