Brownout detection vs custom WDT usage

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
katzimsack
Posts: 1
Joined: Sun Jan 23, 2022 10:21 am

Brownout detection vs custom WDT usage

Post by katzimsack » Sun Jan 23, 2022 10:32 am

Hi,

I found viewtopic.php?t=7268&p=41350 to answer the question how to detect brownouts, but it opens another one:

If the right way to detect brownouts is to check the reset_cause() to be machine.WDT_RESET, then how can I differentiate brownouts from custom watchdog setups? In my case, I configured the watchdog to listen for pings from a timer function (capturing and uploading data points) . If it fails too often, the watchdog will restart the device. But I can't figure out if there was a brownout this way.

Did I miss something?

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: Brownout detection vs custom WDT usage

Post by marcidy » Sun Jan 23, 2022 7:45 pm

From MicroPython, a brownout reset can be detected using machine.reset_cause() (which will return machine.WDT_RESET for a brownout).
I don't believe this is true anymore for detecting a brownout, it's reported as a PWRON cause, not a WDT_RESET cause.

Code: Select all

  STATIC mp_obj_t machine_reset_cause(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
      if (is_soft_reset) {
          return MP_OBJ_NEW_SMALL_INT(MP_SOFT_RESET);
      }
      switch (esp_reset_reason()) {
          case ESP_RST_POWERON:
          case ESP_RST_BROWNOUT:
              return MP_OBJ_NEW_SMALL_INT(MP_PWRON_RESET);
              break;
  
          case ESP_RST_INT_WDT:
          case ESP_RST_TASK_WDT:
          case ESP_RST_WDT:
              return MP_OBJ_NEW_SMALL_INT(MP_WDT_RESET);
              break;
  
          case ESP_RST_DEEPSLEEP:
              return MP_OBJ_NEW_SMALL_INT(MP_DEEPSLEEP_RESET);
              break;
  
          case ESP_RST_SW:
          case ESP_RST_PANIC:
          case ESP_RST_EXT: // Comment in ESP-IDF: "For ESP32, ESP_RST_EXT is never returned"
              return MP_OBJ_NEW_SMALL_INT(MP_HARD_RESET);
              break;
  
          case ESP_RST_SDIO:
          case ESP_RST_UNKNOWN:
          default:
              return MP_OBJ_NEW_SMALL_INT(0);
              break;
      }
  }
Note here:

Code: Select all

          case ESP_RST_POWERON:
          case ESP_RST_BROWNOUT:
              return MP_OBJ_NEW_SMALL_INT(MP_PWRON_RESET);
              break;
Brownout is merged with PWRON.

You can inspect the reset cause register explicitly if you need to know it was a brownout. I cover how to do this here: viewtopic.php?f=18&t=10751

Post Reply