HardFault Interrupt

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HardFault Interrupt

2,877 Views
maksim_lipskiy
Contributor III

Hello! I  use FRDM-K64F board.

An interrupt "HardFault_IRQn" occurs when used uart.

How to understand, because of what occurs this interrupt and fix error?

Thanks

9 Replies

1,770 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Maksim,

You can refer the method in Debugging ARM Cortex-M Hard Faults with GDB Custom Command.

Hope that help.

Best Regards,

Robin

0 Kudos

1,770 Views
egoodii
Senior Contributor III

Add a hard-fault handler that gives details to you about the event.

0 Kudos

1,770 Views
mjbcswitzerland
Specialist V

Hi

Most hard faults when accessing peripherals are due to the fact that the clock to the peripheral has not been enabled.

Check that the UART's clock is gated in the corresponding SIM_SCGCx register.

Regards

Mark

1,770 Views
maksim_lipskiy
Contributor III

Thank You Mark!
I check SIM_SCGC1 register (because i'm use UART4) in  HardFault handler. 
UART4 Clock Enable  SIM_SCGC1 = 0x00000400;

0 Kudos

1,770 Views
mjbcswitzerland
Specialist V

Hi

That means that the UART4 is being clocked and the hard fault must be due to another reason than a UART peripheral access.

I find the following easily identifies such problems:

1. Use a hard fault handler that doesn't do anything - just returns

2. Set a break point in the hard fault handler (or with disabled watchdog just pause the debugger when it is firing).

3. Using disassemble mode, single step out of the hard fault handler. This will return to the instruction that causes the fault and if you step further it will repeat the error and go back into the fault handler.
Usually it is obvîous what is wrong when the bad instruction is seen.

Regards

Mark

For FRDM-K64F see: http://www.utasker.com/kinetis/FRDM-K64F.html

0 Kudos

1,770 Views
maksim_lipskiy
Contributor III

If that's what happened to step out of the Hardfault interrupt handler:
hardfault_debug.jpg

0 Kudos

1,770 Views
mjbcswitzerland
Specialist V

Hi

If this is accurate, it is showing that the hard fault is due to your code trying to run in the memory area 0x79aff020, which is invalid. Why the code is trying to run from there will be due to a problem such as using a bad pointer to jump to, trying to handle an interrupt which has an invalid/random interrupt vector or returnîng from a sub-routine where the stack has been corrupted (and the return address overwritten with random data).

You will need to study your code to work out where the failure start from (if the error is consistent you can simply step through the normal operation until it fails) or use proven code to save needing to do such excercises.

Regards

Mark

0 Kudos

1,770 Views
maksim_lipskiy
Contributor III

Thank you very much for your answer. I
I set a slight delay after the function sending data for UART and  hardfault inerrupt ceased !!!

0 Kudos

1,770 Views
maksim_lipskiy
Contributor III

Thank you.
Now I will test.

0 Kudos