Content originally posted in LPCWare by whitecoe on Wed Feb 01 04:22:51 MST 2012
So you are hand modifying the stack pointer in a function that has local data (ie it is on the stack). Sounds like a recipe for disaster!
Try setting a breakpoint just before you change the stack pointer, then look at the values in the registers and the actual instructions in memory.
What I imagine is happening is that the code is trying to access that local data after you modify the stack pointer (and which the compiler doesn't really know you have changed), and that stack access for accessing the local data is being made beyond the end of the RAM - triggering a hard fault.
HTH!