Skip to main content
GFree.2
Associate
December 8, 2020
Question

How to parse raw stack data in hex (STM32F4)?

  • December 8, 2020
  • 9 replies
  • 2616 views

Hello,

I'd like to ask is there any information about parsing raw stack data?

I always save data from PSP stack when a HardFault happens. Here is an example:

20020200: 00000000 0A461285 00000F7F 00000000 00000000 0812CA7D 0812CA9A 20020210

20020220: <hex> <hex> <hex> <hex> <hex> <hex> <hex> <hex>

etc

As far as I understand it may be helpful to recover the end of the list of functions in the order they were called before a HF happened. Is there any resources about recording information on stack for STM32F4?

This topic has been closed for replies.

9 replies

KnarfB
Super User
December 8, 2020

What you are looking for is stack unwinding. This can be done with a little help of the gcc compiler. See https://github.com/red-rocket-computing/backtrace

Tesla DeLorean
Guru
December 8, 2020

Generally speaking you'd need a lot of debug data from the compiler/linker to make a much headway. The stack frame, register usage is not as orthogonal as say DOS x86 code.

ODD addresses in the 0x08000000 range are typically LR pushes to return targets, ie 0x0812CA7D is where in came from. This is usually the easiest way to pull out points of interest if you can't determine why the Hard Fault arrived where it did. Generally far easier to check-point the code with sanity checks and flow telemetry if this is a recurrent fault on the debugger.

For field analysis you're often better to use a pencil and a .MAP file, and a dump of the immediate stack, and instructions, along with the registers.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
GFree.2
GFree.2Author
Associate
December 8, 2020

Ok and is there any way to recognize ASM instruction codes in a stack frame?

KnarfB
Super User
December 8, 2020

Stack is in RAM, but code (instructions) are in Flash, usually. Stack contains data like local variables, saved register values, and exception/return addresses which point to code.

Read PM0214 Programming manual cited by Jan below or a good book on that topic (Joseph Yiu). Try stepping though sample code and watch what happend and how the stack is used.

waclawek.jan
Super User
December 8, 2020

> Is there any resources about recording information on stack for STM32F4?

0693W000006F2gXQAS.png In your case, PC is 0812CA9A , i.e. the faulting instruction will be at that address or a few addresses before that address (in case of imprecise fault).

JW

GFree.2
GFree.2Author
Associate
December 8, 2020

Thank you