While developing a lot of projects (In Arduino IDE) for ESP32 one common issue I am facing is termination of program execution on unhandled exceptions. There are various exception I get. For example: stack canary watchpoint triggered (looptask), invoke_abort, etc. I have no idea how to handle them, hence I prefer to restart the ESP manually.

Is there any way where I can restart the ESP32 automatically on all unhandled or unfortunate exceptions other than handling the exceptions ?

  • I know little of the ESP32's internals, but would using the watchdog timer work for this? Or maybe changing the panic routine so that it resets the MCU?
    – ocrdu
    Commented Jan 13, 2021 at 13:57
  • @ocrdu hi . can u guide me with sample code for changing the panic routine so that it resets the MCU.
    – Androing
    Commented Jan 13, 2021 at 14:10
  • No, sorry, I have never done that on an ESP32. Sounds googlable, though. Watchdog not an option?
    – ocrdu
    Commented Jan 13, 2021 at 14:17
  • 3
    it should reboot whenever something blows up, I never see one just crashed out, so you must have changed something. don't disable the watchdog, fix the issues instead.
    – dandavis
    Commented Jan 13, 2021 at 19:13
  • 1
    Well, why not correct your application to never throw exceptions? That would be the only serious way to solve the issue. (Exceptions prove the rule, for example a remote application with high reliability requirements, but low quality. However, any restart should lead to an enhanced version.) Commented Jan 15, 2021 at 7:56

1 Answer 1


I don't know if I understand your question well, but if what you want to do is reset MCU programmatically, watchdog is good solution. The orther way is connect IO port and reset port by using wire, and send a signal(send LOW or HIGH voltage to reset port) to reset port.

Or use asm code.

  • Hi. watchdog is not only getting triggered.
    – Androing
    Commented Jan 15, 2021 at 16:22

Your Answer

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

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