2020-06-10 01:12 PM
There is a function called HardFault_Handler in the STM32 MCUs (full code below). This function I usually work with when debugging but am unsure how to use this for handling error. What is the correct protocol to handle errors in this function? If a fault has happened ideally I would like to clear the MCU ram and reset the MCU. However what if the handler code causes more faults. Is there a standard protocol for handling faults (not just HardFaults)?
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 */
}
}
Solved! Go to Solution.
2020-06-10 01:19 PM
You can technically return if you remediate the issue it faulted over, but that requires a very deep understanding of the CPU/ISA
What I normally do is output enough diagnostic information about registers, and perhaps a partial stack dump, so I can provide useful answers about the failure to the boss/customers rather than shrug my shoulders.
If you don't do anything complicated it shouldn't double-fault. Zeroing the imternal RAM using simple code (looping with internal registers, no function calls) should work fine.
2020-06-10 01:19 PM
You can technically return if you remediate the issue it faulted over, but that requires a very deep understanding of the CPU/ISA
What I normally do is output enough diagnostic information about registers, and perhaps a partial stack dump, so I can provide useful answers about the failure to the boss/customers rather than shrug my shoulders.
If you don't do anything complicated it shouldn't double-fault. Zeroing the imternal RAM using simple code (looping with internal registers, no function calls) should work fine.
2020-06-10 01:24 PM
2020-06-10 01:50 PM
That makes sense. What registers are useful for diagnostic info? For clearing RAM I can just memset to NULL for all vars?
Whether the app can continue would be determined on the nature of the failure. I would think in buffer overflow or peripheral failure the app cannot continue after fault.
Appreciate the support clive.