Displaying detailed reset cause info on the EM250 platform
This How-to describes the procedures to print last crash info of the system.
You can add the code below to your application in order to print a detail crash info for diagnosis. Here is an example of the output when the debugging code is included:
TX 000C1324> 20 B4 00 Last PC: 0xBF9E ResetCause: 3108 (PROTFLT) CrashInfo: FL C010 PC BF9E Event 3100 AH 8002 UX BF8F UY 6D88 IY 8000 IM 5F36 SS 0A86 IS 4000 OtherUY 2902 IntNest 0102 ProtFltOP 0000 ProtFltPC BF9D TrapNo FFFF Valid A11C Stack LWM: 00A8/0220 bytes (~29%)
If the reset reason is RESET_CSTACK, you can check whether this is due to call stack overflow by checking Stack LWM. If Stack LWM is close to 100%, it is very likely that that the call stack was full when the system crashed.
For other reset types, see How can I debug an unexpected reset on the EM250 platform? and What do the different reset types mean, and why do we get them?
In terms of interpreting the register dump produced by the PrintCrashInfo routine, meaningful registers are:
- FL - Status register; indicates system flags (such as Zero, Carry, or Overflow)
- PC - Program Counter; indicates last known location where code was executing
- Event - Type of Crash Event that occurred; see Crash Event enumerations described in hal/micro/xap2b/em250/pcb.h. For example, 0x3100 indicates a protection fault (RESET_PROTFLT) caused by attempting to de-reference a null pointer.
- AH - High word of AX register as captured during the crash; used as a general-purpose register by most instructions so may be easily overwritten during a crash.
- UX - Often contains the PC address to which the function would have returned, if not for the crash.
- UY - Stack pointer (to hold call stack data); should be within valid RAM range.
- IY - Should indicate 0x8000 for non-interrupt routines; other values indicate that the code was in an interrupt context during the crash.
- IM - Interrupt Mask; reflects state of INT_CFG at crash time
- SS - Scheduler Status - not used by stack
- IS - INT_FLAG state at time of crash
- OtherUY - Not used by stack
- IntNest - Interrupt nesting state; high byte is how many interrupts deep the code was when it crashed; low byte is the maximum interrupt nest depth observed across runtime
- ProtFltOP - If crash was a PROTFLT, this indicates the last operand (such as destination for a write) given to an instruction prior to the crash.
- ProtFltPC - If crash was a PROTFLT, this indicates the PC value (possibly offset by 1) that tried to execute, causing the protection fault.
- TrapNo - Last system call instruction executed (usually 0xFFFF)
- Valid - Fixed value of 0xA11C acts as signature to indicate integrity of this crash data. If the value differs from this, some of the crash info may be unreliable
Example code required:
Prerequisites to make this work:
- Define DEBUG in compiler symbols to get the right diagnostic.c functions
- Define $DEBUG in assembler symbols to get the right internal functions
- Define USE_PC_DIAGNOSTICS in compiler symbols to get this code to include (or remove the use of this symbol in the code below)
...If you prefer not to enable debug code with these extra symbols, it is also possible to make temporary changes to diagnostic.c to remove the "#if defined" check for the DEBUG symbol around these PCDiagnostics functions.
- ///
- #include "hal/micro/xap2b/em250/pcb.h"
- #include "hal/micro/xap2b/em250/diagnostic.h"
- extern void halInternalPrintCrashInfo (int8u port, crashInfo_t *ci);
- extern crashInfo_t *halInternalGetCrashInfo(void);
- ///
- int main(void)
- {
- EmberResetType reset;
- EmberStatus status;
- #if (defined USE_PC_DIAGNOSTICS)
- crashInfo_t *crashData;
- crashData = halInternalGetCrashInfo();
- #endif
- //Initialize the hal
- halInit();
- INTERRUPTS_ON(); // Safe to enable interrupts at this point
- // Determine the cause of the reset (powerup, etc).
- reset = halGetResetInfo();
- //Initialize the serial ports
- emberSerialInit(APP_SERIAL, APP_BAUD, PARITY_NONE, 1);
- #ifdef DEBUG
- emberDebugInit(DEBUG_SERIAL);
- #endif
- // Reset the watchdog before we do all of this printing
- halResetWatchdog();
- #if (defined USE_PC_DIAGNOSTICS)
- emberSerialPrintf(DEBUG_SERIAL, "Last PC: 0x%2X\r\n", halGetPCDiagnostics() );
- halStartPCDiagnostics();
- halInternalPrintCrashInfo(0, crashData);
- #endif
- // Other application code
- // ...
- }
- Login to post comments








