Hi,

I have issues with the following code:

extern "C" void app_main(void) {
ets_delay_us(10001000);
ets_printf("wakeup_cause=%d reset_reason=%d\n", esp_sleep_get_wakeup_cause(), esp_reset_reason());
esp_sleep_enable_timer_wakeup(500
1000);
esp_deep_sleep_start();

Most of the time it outputs a wakeup_cause 4 and a reset_reason 8, which is fine as it corresponds to a wake-up from deep sleep.
However from time to time, it (randomly?) outputs a wakeup_cause 0 and a reset_reason 1, corresponding to a power-on reset (see below).

The same code on an Arduino Nano ESP32 works just fine, I can see no poweron resets after wake-ups.

I am reading the text from "idf.py monitor". The code is built with EDF-IDF v5.1.4.

Do you know how to work around this?
Many thanks!

I (322) main_task: Calling app_main()
wakeup_cause=0 reset_reason=0
--- Error: read failed: [Errno 6] Device not configured
--- Waiting for the device to reconnect.
wakeup_cause=4 reset_reason=8
--- Error: read failed: [Errno 6] Device not configured
--- Waiting for the device to reconnect.
wakeup_cause=4 reset_reason=8
--- Error: read failed: [Errno 6] Device not configured
--- Waiting for the device to reconnect.
wakeup_cause=4 reset_reason=8
--- Error: read failed: [Errno 6] Device not configured
--- Waiting for the device to reconnect.
wakeup_cause=4 reset_reason=8
--- Error: read failed: [Errno 6] Device not configured
--- Waiting for the device to reconnect.
PROBLEM --> wakeup_cause=0 reset_reason=1
--- Error: read failed: [Errno 6] Device not configured
--- Waiting for the device to reconnect.

Hi @bfredo123, just wanted to know if you are calling the board init function? I'm just curious if the code you posted is just a snippet (there are other parts that you may want to show) or the entirety of the code that reliably reproduces the issue.

Also, can you share some details about what is connected to the board when this issue is observed (if there are), particularly if it's something with the QON pin?

Thank you for your answer! It's not a snippet, and I am not calling any other init function. Should I, and which one? (and why, as I am using low-level-enough functions instead of Arduino stuff).

BTW there has been some formatting issues in the code I sent, likely due to markdown stuff, here it is again?

extern "C" void app_main(void) {
  ets_delay_us(1000 * 1000);
  ets_printf("wakeup_cause=%d reset_reason=%d\n", esp_sleep_get_wakeup_cause(), esp_reset_reason());
  esp_sleep_enable_timer_wakeup(500*1000);
  esp_deep_sleep_start();
}

    bfredo123 The code is formatted ok now.

    The board init function from the SDK has to at least be called - it initializes the charger and fuel gauge IC (among some other things). Refer to this as an example: https://github.com/PowerFeather/powerfeather-sdk/blob/main/examples/supply_and_battery_info/main/supply_and_battery_info.cpp#L30

    This SDK is available on Espressif's component registry: https://components.espressif.com/components/powerfeather/powerfeather-sdk/versions/1.0.7

    Thank you so much! Can't wait to test it, likely in about 6 hours, will let you know the outcome!

    BTW, I have just had a look at the MainBoard::init function source code, I don't understand all what it does. In my specific case, can you please tell me why it actually helps to call it? (would it be a watchdog timer?).

    Thank you again!

      bfredo123 There seems to be a misunderstanding, the board init function was not necessarily a solution to the issue. I just wanted to know if the code you posted previously was a subset or in its entirety, due to the omission of the call to the board init function. But you have since then clarified that the code is in its entirety.

      Although, I've tried your code with nothing on the board connected, and encountered the issue you mentioned quite quickly. However, with the board init called, it's yet to appear. In my neck of the woods, it's almost midnight, so I'm going to let this run until tomorrow to check.

      But if this holds, apparently something in there prevents this - even I don't get it 🥲 I would have to analyze this more, but my guess is maybe it's maybe related to initialization of some pins persisting through deep sleep (???). Would have to figure it out tomorrow...

      Thank you so much for the update, appreciated! What surprises me, is that the board seems to have been designed with low-power and deep-sleep in mind as a priority, so I am surprised that you did not face that issue already, way before me. Hence my assumptions that I was doing something wrong. Good night! 🙂

      Just tried, it seems to fix the issue, thank you so much!
      Still interested in knowing the reason, it might help me avoiding other mistakes in the future.

      I am also keen on finding out why it prevents the issue 😀 In my testing, I've always called Board.init(), since having the blinking CHG is annoying, and initializing the board (and by extension, the charger IC) fixes that.

      Thx. Ah, I was actually wondering what was the meaning of the blinking led (USB power, no battery), and I checked the doc thoroughly without finding. Does it mean that Board.init has not been called?

      9 days later

      Apologies, not yet, as I have an upcoming test I'm preparing for 🤢
      Though my impression in the other thread is that it might not be related to this.