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\$
  • \$\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 '16 at 9:43
  • \$\begingroup\$ @erebos Yes you make a valid point \$\endgroup\$ – Flying Swissman Sep 21 '16 at 7:42
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\$
  • \$\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\$ – Flying Swissman Sep 20 '16 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 '16 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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