AnsweredAssumed Answered

How did I get here? (unwinding the stack)

Question asked by Barta.Hank on Feb 2, 2016
Latest reply on Feb 3, 2016 by Jacobs.Carl.001
Hi folks,
I'd like to implement some checks in the SysTick handler that will help to determine what code was executing when the SysTick interrupt fired. (What I'm actually doing is counting ticks since last IWDG service and logging information on what was executing when IWDG reset is imminent.) 

I can look at the link register (LR, via __get_LR() in the IAR toolkit) but I'm not sure where to go from there. The problem is that the immediate return address may be deep in some library and I really need to work my way back up (down?) the call stack to see where this was called from my application. It might be one or several calls deep.

I've tried looking at the stack and can see the same value there as is stored in LR but past that point I am unable to relate the callstack displayed by the debugger with other values I see on the stack.

To be honest I'm not even certain what direction the stack builds in. (Yes... one of those stinkin' C programmers who hasn't done any assembler coding since the 8080 and PDP-11 were popular. ;) )

Any pointers to information I need to walk/unwind the callstack (or better yet, example code in C :D ) would be most welcome.