Skip to Navigation
Home
  • Company
    • Quick Facts
    • Board of Directors
    • Management Team
    • Press Releases
    • News Coverage
    • Newsletter
    • Careers
    • Articles
    • Ember Chronology
    • Contact Us
  • Products
    • ZigBee Chips
    • ZigBee Software
    • ZigBee Development Tools
    • Documentation
  • Buy
    • Digi-Key (Online)
    • Distributors
  • Applications
    • AMI & AMR
    • Integrated Home Automation
    • Building Automation
    • Others
  • ZigBee
    • About ZigBee
    • Ember & ZigBee
    • ZigBee FAQ
    • Download Specifications
    • ZigBee Events
  • Partners
  • Support
    • Training
  • Events
Home

Displaying detailed reset cause info on the EM250 platform

Categories:
  • Software : Embedded
  • Tutorial
  • EM250

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.

  1. ///
  2. #include "hal/micro/xap2b/em250/pcb.h"
  3. #include "hal/micro/xap2b/em250/diagnostic.h"
  4. extern void halInternalPrintCrashInfo (int8u port, crashInfo_t *ci);
  5. extern crashInfo_t *halInternalGetCrashInfo(void);
  6. ///
  7.  
  8. int main(void)
  9. {
  10. EmberResetType reset;
  11. EmberStatus status;
  12. #if (defined USE_PC_DIAGNOSTICS)
  13. crashInfo_t *crashData;
  14. crashData = halInternalGetCrashInfo();
  15. #endif
  16.  
  17. //Initialize the hal
  18. halInit();
  19. INTERRUPTS_ON(); // Safe to enable interrupts at this point
  20.  
  21. // Determine the cause of the reset (powerup, etc).
  22. reset = halGetResetInfo();
  23.  
  24. //Initialize the serial ports
  25. emberSerialInit(APP_SERIAL, APP_BAUD, PARITY_NONE, 1);
  26. #ifdef DEBUG
  27. emberDebugInit(DEBUG_SERIAL);
  28. #endif
  29.  
  30. // Reset the watchdog before we do all of this printing
  31. halResetWatchdog();
  32. #if (defined USE_PC_DIAGNOSTICS)
  33. emberSerialPrintf(DEBUG_SERIAL, "Last PC: 0x%2X\r\n", halGetPCDiagnostics() );
  34. halStartPCDiagnostics();
  35. halInternalPrintCrashInfo(0, crashData);
  36. #endif
  37.  
  38. // Other application code
  39. // ...
  40. }

  • Login to post comments

Search

Primary links
  • Developer Blog
  • Documentation
    • Release Notes
  • Contributed Software
  • FAQs
  • Change Notifications
  • Training
Portal
  • My Account
  • Search
User login
  • Request new password

Company | Products | Buy | Applications | ZigBee | Partners | Support | Events | Contact Us

©2007-2008 Ember Corporation | All rights reserved | Privacy