Is it possible to get the state of the uC without being connected to it at the moment of crash?
Is it possible to get the state of the uC without being connected to it at the moment of crash?
That rather depends by what you mean by crash. If you're going to your error handler or ending up in the hardfault handler, then yes you just implement an error handler or hardfault handler which finds the stack, gets the registers and dumps the last state of them to
If you have a loop-forever error handler, you may not even need to save state, you can connect to the chip whilst it's busy-looping and read the state right from where it left off.
If you're going to write state to flash then you don't want to use ANY of the library code, just write the registers to clear the pages you want and write them again to dump the data.
There's quite a few online - it's usually a bit of assembler jumping to a piece of C. All it's really doing is figuring out which stack was in-use at the time of the fault and pulling the registers from there in order. Google ARM Hardfault Handler to start with. They all need a bit of customization but the principal is simple.
Connect. Break. See where you are. With JLink from the command line that's as easy as typing halt
followed by regs
. A full IDE debugger will do a little better but the principle is the same.
Could you go into the second part a bit more? How exactly do I "connect"? Just starting a new debug session restarts the processor.