Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 8 FirstFirst 1 2 3 4 ... LastLast
Results 26 to 50 of 199

Thread: Re-enable bootloader interrupts after a hard fault [Teensy 4.1]

  1. #26
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,225
    Quote Originally Posted by PaulStoffregen View Post
    One more thing. The LED blink is just for testing. It's intended to be removed before 1.54-beta11.
    Finally found the thread that you posted to. Sorry. Anyway with the incorporation of the latest PR, addition details is printed:
    Code:
    CrashReport ... Hello World
      length: 9
      IPSR: 3
      CFSR: 82
    	(DACCVIOL) Data Access Violation
    	(MMARVALID) Accessed Address: 0x0 (nullptr)
      HTSR: 40000000
    	(FORCED) Forced Hard Fault
      MMFAR: 0
      BFAR: 0
      return address: C4
      XPSR: 61000000
      crc: A57C5478
    test 0
    test 1
    test 2
    test 3
    test 4
    @Paul - I kind of like the quick blinking LED on hardfault.

  2. #27
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,492
    Odd - got cores from github with latest updates.

    Compiled for T_4.1 - Code below - and I see this when the code starts? NO LED BLINKING.
    Code:
    T:\tCode\FAULT_HANDLER\CrashReport\CrashReport.ino Jun 20 2021 14:03:51
    CrashReport ... Hello World
      length: 1603229661
      IPSR: 8550A1D7
      CFSR: EA331821
    	(IACCVIOL) Instruction Access Violation
    	(UNSTKERR) Bus Fault on unstacking for a return from exception
    	(UNDEFINSTR) Undefined instruction
      HTSR: 981CDC4
      MMFAR: ADBB03C8
      BFAR: 25AF9987
      return address: 192DBE35
      XPSR: CC7C13FD
      crc: 30C95A1C
    Code compiles with no warnings or errors ...

    The code with simple startup and nothing going on ... until user send Serial data ... in fact commenting that out to be sure and it still only coming up with above message?
    Code:
    #include <crashreport.h>
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(115200);
      while (!Serial && millis() < 4000 );
      Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
      Serial.print(CrashReport);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      if ( Serial.available()) {
        //uint32_t *y = 0; y[0] = 5;
      }
    
    }

  3. #28
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,225
    Quote Originally Posted by defragster View Post
    Odd - got cores from github with latest updates.

    Compiled for T_4.1 - Code below - and I see this when the code starts? NO LED BLINKING.
    Code:
    T:\tCode\FAULT_HANDLER\CrashReport\CrashReport.ino Jun 20 2021 14:03:51
    CrashReport ... Hello World
      length: 1603229661
      IPSR: 8550A1D7
      CFSR: EA331821
    	(IACCVIOL) Instruction Access Violation
    	(UNSTKERR) Bus Fault on unstacking for a return from exception
    	(UNDEFINSTR) Undefined instruction
      HTSR: 981CDC4
      MMFAR: ADBB03C8
      BFAR: 25AF9987
      return address: 192DBE35
      XPSR: CC7C13FD
      crc: 30C95A1C
    Code compiles with no warnings or errors ...

    The code with simple startup and nothing going on ... until user send Serial data ... in fact commenting that out to be sure and it still only coming up with above message?
    Code:
    #include <crashreport.h>
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(115200);
      while (!Serial && millis() < 4000 );
      Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
      Serial.print(CrashReport);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      if ( Serial.available()) {
        //uint32_t *y = 0; y[0] = 5;
      }
    
    }
    @defragster - check your email Work still in progress.

  4. #29
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,492
    Quote Originally Posted by mjs513 View Post
    @defragster - check your email Work still in progress.
    Doing that ... and github ... not finding update for CrashReport.clear()

  5. #30
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,225
    Quote Originally Posted by defragster View Post
    Doing that ... and github ... not finding update for CrashReport.clear()
    Not added added yet. Not that fast in adding stuff.

  6. #31
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,492
    Quote Originally Posted by mjs513 View Post
    Not added added yet. Not that fast in adding stuff.
    Misread that as ADDED ... but I never crashed and it is picking up as already crashed and won't clear to run my code - and it isn't blinking - just stalled - does take Auto Upload so not hung ...

  7. #32
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,497
    Quote Originally Posted by defragster View Post
    NO LED BLINKING.
    Yup. I committed automatic reboot after 8 seconds, which also removed the LED blinking and made some changes to prevent possible nested interrupts. Looks like that commit was pushed to github only minutes before you pulled the latest code.

    https://github.com/PaulStoffregen/co...afba10526b6118

  8. #33
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,492
    Prior almost 30 mins back I got - latest was just simple stuff - got that too and same result on a T_4.1 after 15 sec Restore:
    Code:
    T:\tCode\FAULT_HANDLER\CrashReport\CrashReport.ino Jun 20 2021 14:20:20
    CrashReport ... Hello World
      length: 1603229661
      IPSR: 8540A1D7
      CFSR: E8331A21
    	(IACCVIOL) Instruction Access Violation
    	(PRECISERR) Data bus error(address in BFAR)
    	(UNDEFINSTR) Undefined instruction
      HTSR: 909CDC4
      MMFAR: ADAB03D8
      BFAR: 25AF9983
      return address: 192DBE35
      XPSR: CC7C33FD
      crc: 30C91A04

  9. #34
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,497
    Quote Originally Posted by defragster View Post
    CrashReport ... Hello World
    length: 1603229661
    Yup, the code still needs quite a lot of work, like checking the length and crc...

  10. #35
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,492
    Okay - added more informative code that is working as expected . Still unlcear why there was a fault reported after 15 sec Restore - except perhaps wihtout CRC check it sees a fault everywhere?

    Code:
    #include <crashreport.h>
    
    void setup() {
      pinMode( LED_BUILTIN, OUTPUT );
      digitalWrite( LED_BUILTIN, 1 );
      Serial.begin(115200);
      while (!Serial && millis() < 4000 );
      Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
      Serial.print(CrashReport);
      //CrashReport.clear();
      delay ( 100 );
      digitalWrite( LED_BUILTIN, 0 );
      delay ( 1000 );
      digitalWrite( LED_BUILTIN, 1 );
    }
    
    void loop() {
      if ( Serial.available()) {
        digitalWrite( LED_BUILTIN, 0 );
        Serial.println("It's your fault!\n");
        delay ( 50 );
        uint32_t *y = 0; y[0] = 5;
      }
      delay ( 10 );
      digitalWrite( LED_BUILTIN, 0 );
      delay ( 50 );
      digitalWrite( LED_BUILTIN, 1 );
    }
    Note(d) : this is now optional >> #include <crashreport.h>
    Last edited by defragster; 06-20-2021 at 09:53 PM.

  11. #36
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,225
    @PaulStoffregen - @defragster.

    I made some changes to the CrashReport to add clear and to print if crash report is not available but don't like what I did for clear. Really should clear the fault registers but not sure quite how to implement that - should clear on reset but not sure they are. Anyway other issue is that since the latest changes were made the first time the fault occurs the info->len is some huge number but still have a fault when it should be 9. So it throws off my test.

    On first tunring power on after loading the sketch
    Code:
    D:\Users\Merli\Documents\Arduino\CrashRepot_example\CrashRepot_example.ino Jun 20 2021 20:18:41
    Crash Report not Available
    Hitting the return key shows:
    Code:
    It's your fault!
    On auto restart after failure you see:
    Code:
    D:\Users\Merli\Documents\Arduino\CrashRepot_example\CrashRepot_example.ino Jun 20 2021 20:18:41
    CrashReport ... Hello World
      length: 9
      IPSR: 3
      CFSR: 82
    	(DACCVIOL) Data Access Violation
    	(MMARVALID) Accessed Address: 0x0 (nullptr)
      HTSR: 40000000
    	(FORCED) Forced Hard Fault
      MMFAR: 0
      BFAR: 0
      return address: C4
      XPSR: 61000000
      crc: A55C7678
    and with the return:
    Code:
    It's your fault!
    EDIT: with the clear function - doesn't clear until you power off and on again.

    The changes I made are in my fork of the repository: https://github.com/mjs513/cores. Basically not really working. Ok off to other things again. To be honest. Think the struct needs to be reinitialized on restart as opposed from the sketch.

  12. #37
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,492
    Cool - I see your git work.

    Will give it a look ...

  13. #38
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,492
    @mjs513 - the end of .clear() needs to commit the cache to RAM from cache ... below.

    It would be nice to have the sketch know when a fault happened? - see below ...

    Tested at the end of : size_t CrashReportClass:rintTo(Print& p) const with just these two set to zero and that also stopped the Crash repeat notice. Zero of the rest isn't needed
    Code:
        info->cfsr = 0;
        info->len = 0;
        arm_dcache_flush_delete(info, sizeof(*info));
    Code:
    void CrashReportClass::clear()
    {
      struct arm_fault_info_struct *info = (struct arm_fault_info_struct *)0x2027FF80;
      
      info->len = 0;
      info->ipsr  = 0;
      info->cfsr  = 0;
      info->hfsr  = 0;
      info->mmfar = 0;
      info->bfar  = 0;
      info->ret = 0;
      info->xpsr  = 0;
      //info->crc = 0;
      arm_dcache_flush_delete(info, sizeof(*info));
    }
    I get this using code below - of course the .h also needs void changed to bool to match. And I took the "Crash Report not Available" out.
    All was right after upload, then I hit Enter, it showed the Fault, then I did a RESET and the fault was cleared::
    Code:
    T:\tCode\FAULT_HANDLER\CrashReport\CrashReport.ino Jun 20 2021 22:13:15
     millis() now 1147
    It's your fault!
    
    
    T:\tCode\FAULT_HANDLER\CrashReport\CrashReport.ino Jun 20 2021 22:13:15
     millis() now 1075
    CrashReport ... Hello World
      length: 9
      IPSR: 3
      CFSR: 82
    	(DACCVIOL) Data Access Violation
    	(MMARVALID) Accessed Address: 0x0 (nullptr)
      HTSR: 40000000
    	(FORCED) Forced Hard Fault
      MMFAR: 0
      BFAR: 0
      return address: C4
      XPSR: 610E0000
      crc: 31E91A1E
    
    	RECOVERED from Crash !
    T:\tCode\FAULT_HANDLER\CrashReport\CrashReport.ino Jun 20 2021 22:13:15
     millis() now 1056
    Here is the updated sketch - LED a bit less annoying:
    Code:
    void setup() {
      pinMode( LED_BUILTIN, OUTPUT );
      digitalWrite( LED_BUILTIN, 1 );
      Serial.begin(115200);
      while (!Serial && millis() < 4000 );
      Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
      Serial.printf(" millis() now %u\n", millis() );
      Serial.print(CrashReport);
      if ( CrashReport.clear() ) {
        Serial.print("\n\tRECOVERED from Crash !");
      }
      delay ( 100 );
      digitalWrite( LED_BUILTIN, 0 );
      delay ( 1000 );
      digitalWrite( LED_BUILTIN, 1 );
    }
    
    void loop() {
      if ( Serial.available()) {
        digitalWrite( LED_BUILTIN, 0 );
        Serial.println("It's your fault!\n");
        delay ( 50 );
        uint32_t *y = 0; y[0] = 5;
      }
      delay ( 3 );
      digitalWrite( LED_BUILTIN, 0 );
      delay ( 40 );
      digitalWrite( LED_BUILTIN, 1 );
    }
    Here is a possible .clear() version - still no CRC check.
    Code:
    bool CrashReportClass::clear()
    {
      struct arm_fault_info_struct *info = (struct arm_fault_info_struct *)0x2027FF80;
      
      if( info->len == 9 ) {    //if I add in CRC it gives me headaches
        info->len = 0;
        info->cfsr  = 0;
        arm_dcache_flush_delete(info, sizeof(*info));
        return true; // Crash was cleared
      }
      else
        return false; // Crash not present to be cleared
    }

  14. #39
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,492
    @Paul ... Made three PR's:
    Code:
    https://github.com/PaulStoffregen/cores/pull/569
    https://github.com/PaulStoffregen/cores/pull/568
    https://github.com/PaulStoffregen/cores/pull/567
    > one is startup.c to pass the crc
    > one is the header for .clear() to return bool
    > one is .cpp class edits to act on valid CRC, .clear() to test CRC and report false with no CRC match and true when crc shows fault and clear the fault and not print anything.

    CRC issue was PJRC's - in startup.c the crc as calculated was not put into the info struct:
    Code:
    	info->crc = crc;
    	arm_dcache_flush_delete(info, sizeof(*info));
    Then the complete CRC tested solution is:
    Code:
    #include <Arduino.h>
    #include <CrashReport.h>
    
    /* Crash report info stored in the top 128 bytes of OCRAM (at 0x2027FF80)
    struct arm_fault_info_struct {
            uint32_t len;
            uint32_t ipsr;
            uint32_t cfsr;
            uint32_t hfsr;
            uint32_t mmfar;
            uint32_t bfar;
            uint32_t ret;
            uint32_t xpsr;
            uint32_t crc;
    }; */
    extern unsigned long _ebss;
    
    size_t CrashReportClass::printTo(Print& p) const
    {
      struct arm_fault_info_struct *info = (struct arm_fault_info_struct *)0x2027FF80;
      uint32_t i, crc;
      const uint32_t *pp, *end;
      crc = 0xFFFFFFFF;
      pp = (uint32_t *)info;
      end = pp + (sizeof(*info) / 4 - 1);
      while (pp < end) {
        crc ^= *pp++;
        for (i=0; i < 32; i++) crc = (crc >> 1) ^ (crc & 1)*0xEDB88320;
      }
    
      if( info->crc == crc ) {
        p.println("CrashReport ... Hello World");
        p.print("  length: ");
        p.println(info->len);
        p.print("  IPSR: ");
        p.println(info->ipsr, HEX);
    
        uint32_t _CFSR = info->cfsr;
        if (_CFSR > 0) {
          p.print("  CFSR: ");
          p.println(info->cfsr, HEX);
          if ((_CFSR & 0xff) > 0) {
          //Memory Management Faults
          if ((_CFSR & 1) == 1) {
            p.println("\t(IACCVIOL) Instruction Access Violation");
          } else  if (((_CFSR & (0x02)) >> 1) == 1) {
            p.println("\t(DACCVIOL) Data Access Violation");
          } else if (((_CFSR & (0x08)) >> 3) == 1) {
            p.println("\t(MUNSTKERR) MemMange Fault on Unstacking");
          } else if (((_CFSR & (0x10)) >> 4) == 1) {
            p.println("\t(MSTKERR) MemMange Fault on stacking");
          } else if (((_CFSR & (0x20)) >> 5) == 1) {
            p.println("\t(MLSPERR) MemMange Fault on FP Lazy State");
          }
          if (((_CFSR & (0x80)) >> 7) == 1) {
            p.print("\t(MMARVALID) Accessed Address: 0x");
            p.print(info->mmfar, HEX);
            if (info->mmfar < 32) p.print(" (nullptr)");
            if ((info->mmfar >= (uint32_t)&_ebss) && (info->mmfar < (uint32_t)&_ebss + 32))
            p.print(" (Stack problem)\n\tCheck for stack overflows, array bounds, etc.");
            p.println();
          }
          }
          //Bus Fault Status Register BFSR
          if (((_CFSR & 0x100) >> 8) == 1) {
          p.println("\t(IBUSERR) Instruction Bus Error");
          } else  if (((_CFSR & (0x200)) >> 9) == 1) {
          p.println("\t(PRECISERR) Data bus error(address in BFAR)");
          } else if (((_CFSR & (0x400)) >> 10) == 1) {
          p.println("\t(IMPRECISERR) Data bus error but address not related to instruction");
          } else if (((_CFSR & (0x800)) >> 11) == 1) {
          p.println("\t(UNSTKERR) Bus Fault on unstacking for a return from exception");
          } else if (((_CFSR & (0x1000)) >> 12) == 1) {
          p.println("\t(STKERR) Bus Fault on stacking for exception entry");
          } else if (((_CFSR & (0x2000)) >> 13) == 1) {
          p.println("\t(LSPERR) Bus Fault on FP lazy state preservation");
          }
          if (((_CFSR & (0x8000)) >> 15) == 1) {
          p.print("\t(BFARVALID) Accessed Address: 0x");
          p.println(info->bfar, HEX);
          }
          //Usage Fault Status Register UFSR
          if (((_CFSR & 0x10000) >> 16) == 1) {
          p.println("\t(UNDEFINSTR) Undefined instruction");
          } else  if (((_CFSR & (0x20000)) >> 17) == 1) {
          p.println("\t(INVSTATE) Instruction makes illegal use of EPSR)");
          } else if (((_CFSR & (0x40000)) >> 18) == 1) {
          p.println("\t(INVPC) Usage fault: invalid EXC_RETURN");
          } else if (((_CFSR & (0x80000)) >> 19) == 1) {
          p.println("\t(NOCP) No Coprocessor");
          } else if (((_CFSR & (0x1000000)) >> 24) == 1) {
          p.println("\t(UNALIGNED) Unaligned access UsageFault");
          } else if (((_CFSR & (0x2000000)) >> 25) == 1) {
          p.println("\t(DIVBYZERO) Divide by zero");
          }
        }
    
        uint32_t _HFSR = info->hfsr;
        if (_HFSR > 0) {
          p.print("  HTSR: ");
          p.println(info->hfsr, HEX);
          //Memory Management Faults
          if (((_HFSR & (0x02)) >> 1) == 1) {
          p.println("\t(VECTTBL) Bus Fault on Vec Table Read");
          } else if (((_HFSR & (0x40000000)) >> 30) == 1) {
           p.println("\t(FORCED) Forced Hard Fault");
          } else if (((_HFSR & (0x80000000)) >> 31) == 31) {
           p.println("\t(DEBUGEVT) Reserved for Debug");
          }
        }
    
        p.print("  MMFAR: ");
        p.println(info->mmfar, HEX);
        p.print("  BFAR: ");
        p.println(info->bfar, HEX);
        p.print("  return address: ");
        p.println(info->ret, HEX);
        p.print("  XPSR: ");
        p.println(info->xpsr, HEX);
        p.print("  crc: ");
        p.println(info->crc, HEX);
      } else {
        // p.println("Crash Report not Available");
      }
      return 1;
    }
    
    bool CrashReportClass::clear()
    {
      struct arm_fault_info_struct *info = (struct arm_fault_info_struct *)0x2027FF80;
      uint32_t i, crc;
      const uint32_t *pp, *end;
      crc = 0xFFFFFFFF;
      pp = (uint32_t *)info;
      end = pp + (sizeof(*info) / 4 - 1);
      while (pp < end) {
        crc ^= *pp++;
        for (i=0; i < 32; i++) crc = (crc >> 1) ^ (crc & 1)*0xEDB88320;
      }
    
      if( info->crc == crc ) {
        info->len = 0;
        info->cfsr  = 0;
        arm_dcache_flush_delete(info, sizeof(*info));
        return true; // Crash was cleared
      }
      else
        return false; // Crash not present to be cleared
    }
    
    CrashReportClass CrashReport;

  15. #40
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,492
    Updated to test another couple of faults - linked page has other notes on debugging.

    Frank had to enable and handle the divide by zero case? So #4 is ignored.

    Code:
    // Found a couple of Faults to force here :: https://interrupt.memfault.com/blog/cortex-m-fault-debug
    int illegal_instruction_execution(void) {
      int (*bad_instruction)(void) = (void *)0xE0000000;
      return bad_instruction();
    }
    
    void setup() {
      pinMode( LED_BUILTIN, OUTPUT );
      digitalWrite( LED_BUILTIN, 1 );
      Serial.begin(115200);
      while (!Serial && millis() < 4000 );
      Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
      Serial.printf(" millis() now %u\n", millis() );
      Serial.print(CrashReport);
      if ( CrashReport.clear() ) {
        Serial.print("\n\tRECOVERED from Crash !");
      }
      delay ( 100 );
      digitalWrite( LED_BUILTIN, 0 );
      delay ( 1000 );
      digitalWrite( LED_BUILTIN, 1 );
    }
    
    void loop() {
      if ( Serial.available()) {
        char cc = Serial.read();
        digitalWrite( LED_BUILTIN, 0 );
        Serial.println("\nIt's your fault!\n");
        delay ( 50 );
        if ( cc == '0' ) {
          illegal_instruction_execution();
        }
        else if ( cc == '1' ) { // Bad Address Read
          uint32_t ff = *(volatile uint32_t *)0xbadcafe;
          Serial.print(ff);
        }
        else if ( cc == '2' ) { // Coprocessor Fault - turn off FPU
          __asm volatile(
            "ldr r0, =0xE000ED88 \n"
            "mov r1, #0 \n"
            "str r1, [r0] \n"
            "dsb \n"
            "vmov r0, s0 \n"
          );
        }
        else if ( cc == '3' ) { // bad_addr_double_word_write
          volatile uint64_t *buf = (volatile uint64_t *)0x30000000;
          *buf = 0x1122334455667788;
        }
        else if ( cc == '4' ) { // Divide by Zero (not enabled?)
          cc = cc - '4';
          cc /= cc;
        }
        else if ( cc == '5' ) {
        }
        else if ( cc == '6' ) {
        }
        else { // default fault on Serial with no other fault ... from 'Enter'
          uint32_t *y = 0; y[0] = 5;
        }
      }
      delay ( 3 );
      digitalWrite( LED_BUILTIN, 0 );
      delay ( 40 );
      digitalWrite( LED_BUILTIN, 1 );
    }

  16. #41
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,225
    @defragster
    Good catch on the missing info->crc in startup.c. Completely missed it - should have caught it. Now for the fun part. I copied and pasted your changes in my copy of CrashReport.cpp and .h and used the following sketch.
    Code:
    #include <CrashReport.h>
    
    void setup() {
      pinMode( LED_BUILTIN, OUTPUT );
      digitalWrite( LED_BUILTIN, 1 );
      Serial.begin(115200);
      while (!Serial && millis() < 4000 );
      Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
      Serial.print(CrashReport);
      if ( CrashReport.clear() ) {
        Serial.print("\n\tRECOVERED from Crash !");
      }
    
      delay ( 100 );
      digitalWrite( LED_BUILTIN, 0 );
      delay ( 1000 );
      digitalWrite( LED_BUILTIN, 1 );
    }
    
    void loop() {
      if ( Serial.available()) {
        digitalWrite( LED_BUILTIN, 0 );
        Serial.println("It's your fault!\n");
        delay ( 50 );
        uint32_t *y = 0; y[0] = 5;
      }
      delay ( 10 );
      digitalWrite( LED_BUILTIN, 0 );
      delay ( 50 );
      digitalWrite( LED_BUILTIN, 1 );
    }
    Nothing fancy. I loaded it to the T4.1 and on fresh load received:
    First message to SerMon
    Code:
    D:\Users\Merli\Documents\Arduino\CrashRepot_example\CrashRepot_example.ino Jun 21 2021 05:24:57
    then nothing till I hit return:
    Code:
    D:\Users\Merli\Documents\Arduino\CrashRepot_example\CrashRepot_example.ino Jun 21 2021 05:24:57
    It's your fault!
    but no fault report. On restart since there is a fault present it will print the crash report:
    Code:
    D:\Users\Merli\Documents\Arduino\CrashRepot_example\CrashRepot_example.ino Jun 21 2021 05:24:57
    CrashReport ... Hello World
      length: 9
      IPSR: 3
      CFSR: 82
    	(DACCVIOL) Data Access Violation
    	(MMARVALID) Accessed Address: 0x0 (nullptr)
      HTSR: 40000000
    	(FORCED) Forced Hard Fault
      MMFAR: 0
      BFAR: 0
      return address: C4
      XPSR: 61000000
      crc: FB78D819
    
    	RECOVERED from Crash
    So something else is going on as I mentioned first time failure at len > 9 by a lot as I mentioned before. The fixes do clear the issue if you remove the fault and reload.

    A couple of other comments. Don't think you need to test on clear so to print no crash present or recovered. If there is no fault present you don't really want to tell the user he recovered from a crash. That should be done automatically by the crash report as we had it before with the print from the crashreport. Just an extra coding for the user.

    Second. Think you should clear the whole structure not just CFSR and HFSR. Just my 2 cents.

  17. #42
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,497
    I merged all the pending pull requests, even though the indenting is a little messed up.

    I'm not understanding why clear() is so complicated. What purpose does that serve?

  18. #43
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,225
    Quote Originally Posted by PaulStoffregen View Post
    I merged all the pending pull requests, even though the indenting is a little messed up.

    I'm not understanding why clear() is so complicated. What purpose does that serve?
    Don't think it does. This works just as well with @defragsters fix:
    Code:
    void CrashReportClass::clear()
    {
      struct arm_fault_info_struct *info = (struct arm_fault_info_struct *)0x2027FF80;
      
      info->len = 0;
      info->ipsr  = 0;
      info->cfsr  = 0;
      info->hfsr  = 0;
      info->mmfar = 0;
      info->bfar  = 0;
      info->ret = 0;
      info->xpsr  = 0;
      info->crc = 0;
      arm_dcache_flush_delete(info, sizeof(*info));
    }
    Sure there is an easier way to reset the struct then it would be simpler.

  19. #44
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,497
    Do you have any other changes pending? I'd like to get everything merged before I make large changes...

  20. #45
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,225
    Quote Originally Posted by PaulStoffregen View Post
    Do you have any other changes pending? I'd like to get everything merged before I make large changes...
    Just submitted a PR changing to the simplified clear and putting the print. Gives another approach I guess - works both ways. As I mentioned - can't figure out why on first fault not dumping the report?
    https://github.com/PaulStoffregen/cores/pull/570

    EDIT: Got really stuck yesterday on the missing CRC and the not using the flush_delete otherwise might have gotten further on the list. Sorry

  21. #46
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,225
    @PaulStoffregen

    Was looking SRC_SRSR, but will the resets even trigger the fault handler? or will a reset handler be required?

  22. #47
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,497
    I'm adding code right now to print messages based on SRC_SRSR....

  23. #48
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,225
    Quote Originally Posted by PaulStoffregen View Post
    I'm adding code right now to print messages based on SRC_SRSR....
    Got it - was begining to take a look at it but guess you are back into the thick of it agaim

  24. #49
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,219
    Hi all, Sorry I have been distracted.

    It will be great to have the ability to find out what happened.
    Code:
    void setup() {
      pinMode( LED_BUILTIN, OUTPUT );
      digitalWrite( LED_BUILTIN, 1 );
      Serial.begin(115200);
      while (!Serial && millis() < 4000 );
      Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
      Serial.print(CrashReport);
      if ( CrashReport.clear() ) {
        Serial.print("\n\tRECOVERED from Crash !");
      }
    I keep wondering with this crash report if it feels like every run of your program expects to crash... Sorry I am not clear here...

    Wondering if there should be some bool/boolean that you can ask if it crashed...
    Not sure if it should be operator like:
    Code:
    void setup() {
      pinMode( LED_BUILTIN, OUTPUT );
      digitalWrite( LED_BUILTIN, 1 );
      Serial.begin(115200);
      while (!Serial && millis() < 4000 );
      Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
      if (CrashReport) {
        Serial.print(CrashReport);
        if ( CrashReport.clear() ) {
          Serial.print("\n\tRECOVERED from Crash !");
        }
      }
    Or some method...

  25. #50
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,497
    Quote Originally Posted by KurtE View Post
    Wondering if there should be some bool/boolean that you can ask if it crashed...
    That's a good point. Added.

    https://github.com/PaulStoffregen/co...5b8606efc53ddd

    The clear() function no longer returns anything. Think of it as "delete".



    Quote Originally Posted by mjs513 View Post
    Got it - was begining to take a look at it but guess you are back into the thick of it again
    I'm going to take a break, until at least late tonight. Now's the perfect time to pull the latest from github and jump in if you'd like to make changes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •