Add the crash_diag terminal command for diagnosing resets and crashes
Changes the fault handlers so that on a fault all the relevant registers (those dumped on the stack by the MCU and the fault information registers) are stored in a RAM struct (in the .noinit section) before resetting. Same with the Chibios halt, stores the pointer to the reason string before resetting.
On a bootup, the RAM struct is only initialized if Power On reset flag is set, and the reset flags are also stored in the struct.
This is all the possible information about why a reset could have occurred, which is then exposed via the crash_diag terminal command. Example output:
-> crash_diag
Reset flags: Reset Pin,Software
System crashed, registers:
r0: 0x00000000
r1: 0x080728a6
r2: 0x00000000
r3: 0x20000800
r12: 0x50000020
lr: 0x080145a5
pc: 0x080145a8
psr: 0x61000000
cfsr: 0x00010000
hfsr: 0x40000000
mmfar: 0xe000ed34
bfar: 0xe000ed38
afsr: 0x00000000
shcsr: 0x00000000
With this output and the firmware .elf file (and in case of a package crash the package .elf) it should be possible to find the causes of a lot of in-the-field crashes and resets in general.