0
\$\begingroup\$

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?

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$
    – erebos
    Sep 20, 2016 at 9:43
  • \$\begingroup\$ @erebos Yes you make a valid point \$\endgroup\$ Sep 21, 2016 at 7:42

1 Answer 1

1
\$\begingroup\$

Yes there is normally a bit that will show you power-on/reset cause (have you checked the datasheet?).

One way to catch the errors might be to configure watchdog as interrupt instead of reset (not sure about STM32F0, but I have used this on similar chips).

As for saving and restoring RAM to/from EEPROM - it might be easier to just dump RAM contents in the reset handler (before CRT clears .bss and copies .data sections).

\$\endgroup\$
2
  • \$\begingroup\$ I've found out how to see the reset cause. When is the reset handler called exactly? At the very beginning of a power on? \$\endgroup\$ Sep 20, 2016 at 10:00
  • \$\begingroup\$ Reset handler is called when ROM bootloader hands over control to "user" code. That would be the entry code in your code. You can pretty much treat it as "the first code that's executed" after power on. \$\endgroup\$
    – domen
    Sep 20, 2016 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.