Find the stack start address in runtime. cortexM4 processor

22 Views Asked by At

I want to create a hardfault handler that saves data to the internal flash and then reset the MCU. I want to save not only the core registers and the system control registers, but also the stack of the violating task.

The question is how do I find the start address of the stack of current task. For the end address I can obviously use the SP register, but how do I find the start address?

I'm using FreeRTOS, so technically I can "hack" the OS and go to the Task control block. But I'm wandering if there is another way to do so.

I tried callstack unwinding (unwind till I reach the main), but it both seems overly complicated, and I'm not sure how I know when the callstack reach main (the return address that is stored in the stack is not the address of the start of main, it's an address somewhere inside the function's body)

0

There are 0 best solutions below