Page 1 of 1

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

Posted: Mon Oct 14, 2019 5:46 am
by blackwendy21
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.

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

Posted: Wed Oct 16, 2019 2:35 am
by jimmo
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?

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

Posted: Wed Oct 16, 2019 4:35 am
by blackwendy21
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