how to differentiate brown out reset (BOR) and power-on-reset(POR)

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
User avatar
blackwendy21
Posts: 2
Joined: Wed Oct 02, 2019 1:04 am

how to differentiate brown out reset (BOR) and power-on-reset(POR)

Post by blackwendy21 » Mon Oct 14, 2019 5:46 am

Hi members,

I need to report a reset reason and am required to differentiate brown-out reset and power-on-reset.

machine.reset_cause() seems to return only
0: SOFT_RESET
1: PWRON_RESET
2: HARD_RESET
3: WDT_RESET
4: DEEPSLEEP_RESET

Is there any way to tell brown-out? :roll:

Any comments will be very helpful to me.

Thanks in advance.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: how to differentiate brown out reset (BOR) and power-on-reset(POR)

Post by jimmo » Wed Oct 16, 2019 2:35 am

This is not possible with the current firmware. This looks like possibly just an oversight in stm32/modmachine.c.

Code: Select all

        // get reset cause from RCC flags
        uint32_t state = RCC->RCC_SR;
        if (state & RCC_SR_IWDGRSTF || state & RCC_SR_WWDGRSTF) {
            reset_cause = PYB_RESET_WDT;
        } else if (state & RCC_SR_PORRSTF
            #if !defined(STM32F0)
            || state & RCC_SR_BORRSTF
            #endif
            ) {
            reset_cause = PYB_RESET_POWER_ON;
        } else if (state & RCC_SR_PINRSTF) {
            reset_cause = PYB_RESET_HARD;
        } else {
            // default is soft reset
            reset_cause = PYB_RESET_SOFT;
        }
So if BORRSTF is set, you'll get SOFT rather than POWER_ON for a BOR. I guess it would be easy enough to add another case for BORRSTF?

User avatar
blackwendy21
Posts: 2
Joined: Wed Oct 02, 2019 1:04 am

Re: how to differentiate brown out reset (BOR) and power-on-reset(POR)

Post by blackwendy21 » Wed Oct 16, 2019 4:35 am

Thank you so much, Jimmo.
I will try this.

Fortunately, my client agreed to eliminate brown-out reset cause reporting requirement because of non-portability when using this kind of hardware specific solution.

However, out of my curiosity I will try your suggestion later.

Once again thank you.

Kind Regards,
Wendy

Post Reply