This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

hard fault exception

I am generating optimsed code using simulink coder for LMS filter using stm32f4VG407 discovery board,KEIL MDK-ARM, but upon single conversion of signal through ADC , it is stopping at hardfault handler. fault report:
MM_FAULT_STAT:0x00
BUS_FAULT_STAT:0x04 i.e. IMPRECISERR IS HIGH
USG_FAULT_STAT:0x000
HARD_FAULT_STAT:0x4000000 i.e.FORCED IS HIGH
DBG_FAULT_STAT:0x00000001 i.e. HALTED IS HIGH

I am using Matlab 2013b & MDK_ARM 4.74
please help me how to get rid of this.

Parents
  • Debugging? If you get into a hard fault, you have to assume that you have too small stack, or the code for some reason do an out-of-bounds access or makes use of an invalid data pointer or maybe sees an invalid instruction because of an invalid code pointer.

    Debugging of available state in the trap handler can give you some ideas where it fails. Verifying stack size can also help. Standard, traditional code review can also be a good way to catch what possible error situations that might hit you.

Reply
  • Debugging? If you get into a hard fault, you have to assume that you have too small stack, or the code for some reason do an out-of-bounds access or makes use of an invalid data pointer or maybe sees an invalid instruction because of an invalid code pointer.

    Debugging of available state in the trap handler can give you some ideas where it fails. Verifying stack size can also help. Standard, traditional code review can also be a good way to catch what possible error situations that might hit you.

Children
  • since it is MATLAB generated code ,it should work on its own without much editing from user side....so I have no idea how to do it......
    Also I am not able to increase stack size by editing startup_stm32f4xx.s since it is locked
    Also code coverage tool option is not active....

    also since BFARVALID of Bus Fault status register is high so there is valid bus fault
    again IMPRECISERR is high i.e.a data bus error has occurred ,

    from "USING CORTEX-M3 AND CORTEX-M4 FAULT EXCEPTIONS" document:
    FORCED: Indicates a forced Hard Fault, generated by escalation of a fault with configurable priority that cannot be handled, either because of priority or because it is disabled

    FORCED of Hard Fault status register is high means :When this bit is set, the Hard Fault handler must read the other fault status registers to find the cause of the fault.

    So may be it is pointing to bus fault.

    please help me regarding this

  • So move a copy of startup_stm32f4xx.s into your project directory, and remove the read-only attribute.

    Review the code and processor registers at the fault location.

  • I am still struck in hard fault exception

    after running 36 times(i.e 36 adc conversions & hence 36 outputs at dac) the program is getting into hard fault exception from within this for loop:

     /* Update weights for the next input sample
         */
        j_0 = 0;
        for (j = (int32_T)*startIdx; j < wLen; j++) {
          prodMuErrX = accWtU * xBuf[j];
          prodMuErrX += mul_s32_s32_s32_sr30(leakFac, wBuf[j_0]);
          wBuf[j_0] = prodMuErrX;
          j_0++;
        }
    

    I even checked changing stack size but the number of conversions (i.e 36 ) was independent of change in stack size.

    Can somebody please help me regarding this?

  • Hello Satyajit Sahoo,

    maybe Application Note 209 (http://www.keil.com/appnotes/docs/apnt_209.asp) helps you examining the HardFault.

    Best Regards, Martin