2021-05-06 03:52 AM
Is there a way to programmatically reset my STM32 program back to the beginning like when pressing the Hardware Reset Button ?
I would like to reset my program when a random hard-fault has occurred, if possible, i'd also like to store to flash the date/time and some user message when the hard-fault has occurred .
Thanks!
2021-05-06 04:25 AM
For the Reset:
possible
NVIC_SystemReset();
help you.
Steffen
2021-05-06 06:06 AM
You could try this:
Search for your hardfault handler in stm32xxxxit.c
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
store_to_flash_the datetime();
some_user_message_when_the_hardfault_has_occurred();
NVIC_SystemReset();
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
2021-05-06 08:53 PM
Yes, this is exactly what i was trying to search for! Thank You very much!
2021-05-06 11:47 PM
> I would like to reset my program when a random hard-fault has occurred, if possible, i'd also like to store to flash the date/time and some user message when the hard-fault has occurred .
You got something wrong here.
Hardfault do not occur randomly, but indicate a serious problem with your firmware.
Resetting it will only mask the problem.
"Randomness" suggests either a stack overflow or a race condition.
2021-05-06 11:52 PM
I'm totally aware of this, but for my situation instead of tracing the root cause, the most cost effective way is to reset the device.
the stack overflow/race condition is a bit tricky for me to debug since i'm inexperienced and the hardfault happens infrequently, so resetting the device seems to be optimal solution.
Thanks for your suggestion!
2021-05-07 12:49 AM
> ... the most cost effective way is to reset the device.
In my experience, such short-term thinking comes with dire consequences mid- or longterm.
2021-05-10 07:08 AM
there is a catch.... hardfault interruption handler gets called in response to many different events.
maybe the thing that broke its the very thing you need to use inside the hardfault handler..... so you endup in a very tight hardaulf handler loop.
And youre in very high priority interruption so systick and other forms of interrupt based stuff wont work