Reset codes

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
warren
Posts: 74
Joined: Tue Jul 12, 2016 5:47 pm

Reset codes

Post by warren » Tue Sep 13, 2016 5:07 am

The docs give a list of constants for machine.reset_cause()

http://docs.micropython.org/en/latest/e ... chine.html

Numerically these are:

Code: Select all

>>> import machine
>>> machine.PWRON_RESET
0
>>> machine.HARD_RESET
6
>>> machine.WDT_RESET
1
>>> machine.DEEPSLEEP_RESET
5
>>> machine.SOFT_RESET
4
I have a board that is returning a value of 2 for machine.reset_cause() - what cause is this?
Or did I miss a constant in the list?

User avatar
platforma
Posts: 258
Joined: Thu May 28, 2015 5:08 pm
Location: Japan

Re: Reset codes

Post by platforma » Tue Sep 13, 2016 10:21 am

I can see that machine.reset_cause() directly calls the function from the SDK. If you look in tools/sdk/include/user_interface.h. All the reasons in modmachine are mapped directly to this enum:

Code: Select all

typedef enum {
    REASON_DEFAULT_RST = 0,         /**< normal startup by power on */
        REASON_WDT_RST,             /**< hardware watch dog reset */
        REASON_EXCEPTION_RST,       /**< exception reset, GPIO status won't change */
        REASON_SOFT_WDT_RST,        /**< software watch dog reset, GPIO status won't change */
        REASON_SOFT_RESTART,        /**< software restart ,system_restart , GPIO status won't change */
        REASON_DEEP_SLEEP_AWAKE,    /**< wake up from deep-sleep */
        REASON_EXT_SYS_RST          /**< external system reset */
} rst_reason;
As you can see, we're missing REASON_EXCEPTION_RST, which would be the reset reason in your case. Perhaps we should add that to the esp8266/modmachine.c

warren
Posts: 74
Joined: Tue Jul 12, 2016 5:47 pm

Re: Reset codes

Post by warren » Tue Sep 13, 2016 11:24 am

platforma wrote:I can see that machine.reset_cause() directly calls the function from the SDK.<snip>As you can see, we're missing REASON_EXCEPTION_RST, which would be the reset reason in your case. Perhaps we should add that to the esp8266/modmachine.c
That is very, very helpful - thanks

markxr
Posts: 62
Joined: Wed Jun 01, 2016 3:41 pm

Re: Reset codes

Post by markxr » Tue Sep 13, 2016 4:17 pm

Yes, 2= crash :)

I've seen it multiple times.

Usually what I do is check the reset code, and try to start up more quickly if it was a crash, but put a delay for normal reset or power on, to give the user time to press ctrl-C

Post Reply