# Recovering from run time errors on stm32l0

I have the independent watch dog running and I get rare resets for unknown reasons.

How can I catch these errors and do a controlled reset. I want to store some things in EEPROM and then restart the application.

Unplugging the device however, the device needs to forget everything it knows. So I only want to restore EEPROM if an error occured.

void HardFault_Handler(void){
EEPROM_save_ram();
}

void Reset_Handler(void){
EEPROM_restore_ram();
}


Is there a bit that shows me if its a warm restart? A watchdog reset? or just a normal cold start?

• You do not want to do something like this in the hardfault handler! A hardfault gets raised if something is really wrong and at that point you can't be sure that you're RAM content is valid, or even if the stack is still usable. Sep 20 '16 at 9:43
• @erebos Yes you make a valid point Sep 21 '16 at 7:42