6 Replies Latest reply on Nov 2, 2018 11:39 AM by will.flanery

    What is __cy_stack_limit()?  It appears at bottom of Call Stack after HardFault.

    will.flanery

      I’m getting a HardFault that I’ve been fighting all week with no success. 

       

      The problem seems to be stack corruption, but I haven’t been able to find the culprit.  The timing is random, but usually happens within an hour, sometimes immediately on startup.  This makes me think it has something to do with an interrupt.   I’ve tried using some tricks to preserve the stack after a hard fault by implementing an assembly/C hardfault handler.  This hasn’t provided much useful information. 

       

      A strange thing I notice is that the stack trace after the crash almost always has __cy_stack_limit() at the bottom (see attached image), but the stack is not overflowing and my stack pointer is at a very reasonable place.  I even made a function to clear RAM on startup so I can see wherever data has been written.   I’m only using about half my stack space (unless something is writing all zeros).  FYI, the code that's crashing is emWin.  I have also noticed that one variable, stored in a register, that should hold the string length, seems to have been overwritten by a value that would be a valid stack address.  I'm not sure if this is a cause or effect of the crash.  This function will run correctly thousands of times without crashing, but it does seem to be related to the crash.  But, I digress... the real question I'm trying to answer is about __cy_stack_limit() because it seems like an important clue.

       

      A google search doesn’t find much about __cy_stack_limit(), and I can’t find it in the source code. I'm guessing it's a fault vector triggered by the stack pointer register exceeding a value, but I haven't found it in the PSoC5LP documentation.  If I'm right about that, I would still need to know exactly what could trigger it, considering there's no evidence of stack overflow.

       

      Can anyone find any documentation about what __cy_stack_limit() means?

       

      Thanks!

      -Will