2022-12-14 10:29 PM
hi,
I am getting hardware fault in stm and i found why it is happening .
Now i want to rewrite the below function like clear the Int abd executing next instruction of stack.
can i do like that .if possible is there any source code available for that.
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
please help me on this.
thanks,
kathiravan
2022-12-14 11:18 PM
Assuming you mean a Hard Fault and not a “hardware fault�?, then the solution needs to start with an understanding of what a hard fault actually is.
A hard fault occurs when the arm processor has concluded that it is impossible to resume execution after the fault. This could be because it could not save the state onto the stack, or hit a different fault while trying to execute an exception-handler.
Most-likely this is caused by a software error, but one which occurs so rarely that it might be worth trying to record the circumstances to give a clue as to what’s gone wrong and how to correct the code in future. But often the best you can do in the field is reset the processor and start afresh without requiring the user to disconnect the battery!
2022-12-15 12:40 AM
thanks .will do that
2022-12-15 01:54 AM
The Hard Fault Handler can return, you can modify the stack and registers such that it can retry or advance. You'll need to inspect and decode the instruction, or facilitate a structured except model, ie try/catch
Simpler to understand why it fails and check for that condition and behave appropriately without causing the fault. ie sanity check pointer for NULL or illegal address prior to use.