ESP32-C6 causes connection issues & unexpected reboots when using WiFi + Deep Sleep
QuickJack opened this issue · comments
Board
Firebeetle 2 ESP32-C6
Device Description
Using the Deep Sleep example in Arduino IDE works perfectly. However, after adding code to also create a WiFi connection, the board fails to correctly establish a connection and reboots unexpectedly. A typical part of the log is shown under "Description".
Hardware Configuration
no
Version
v3.0.1
IDE Name
Arduino IDE 2 2.3.3-nightly-20240527
Operating System
Ubuntu 22.04
Flash frequency
80MHz
PSRAM enabled
yes
Upload speed
921600
Description
Adding a typical code snippet to connect to an existing WiFi AP causes reboots. At first boot the system always connects without issues. But the following boots following esp_deep_sleep_start() are causing issues. After an unexpected reboot, the RTC memory seems to be cleared. This can be seen by looking at the following log output:
21:40:00.476 -> Boot number: 1
21:40:00.476 -> Wakeup was not caused by deep sleep: 0
Normally, the number after "Boot number" should be incremented with each boot. However, after an unexpected reboot this is not the case. Counting restarts in this case.
In order to verify that this is not a power supply issue, I have checked it using a high quality USB-C cable together with a 65W power supply.
Sketch
/*
Simple Deep Sleep with Timer Wake Up
=====================================
ESP32 offers a deep sleep mode for effective power
saving as power is an important factor for IoT
applications. In this mode CPUs, most of the RAM,
and all the digital peripherals which are clocked
from APB_CLK are powered off. The only parts of
the chip which can still be powered on are:
RTC controller, RTC peripherals ,and RTC memories
This code displays the most basic deep sleep with
a timer to wake it up and how to store data in
RTC memory to use it over reboots
This code is under Public Domain License.
Author:
Pranav Cherukupalli <cherukupallip@gmail.com>
*/
#include <WiFi.h>
#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 10 /* Time ESP32 will go to sleep (in seconds) */
#define STA_SSID "MYSSID"
#define STA_PASS "MYPW"
RTC_DATA_ATTR int bootCount = 0;
/*
Method to print the reason by which ESP32
has been awaken from sleep
*/
void print_wakeup_reason() {
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch (wakeup_reason) {
case ESP_SLEEP_WAKEUP_EXT0: Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1: Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER: Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP: Serial.println("Wakeup caused by ULP program"); break;
default: Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break;
}
}
void setup() {
Serial.begin(115200);
delay(3000); //Take some time to open up the Serial Monitor
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
//Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));
//Print the wakeup reason for ESP32
print_wakeup_reason();
//WiFi test
WiFi.setTxPower(WIFI_POWER_MINUS_1dBm);
WiFi.begin(STA_SSID, STA_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
/*
First we configure the wake up source
We set our ESP32 to wake up every 5 seconds
*/
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + " Seconds");
/*
Next we decide what all peripherals to shut down/keep on
By default, ESP32 will automatically power down the peripherals
not needed by the wakeup source, but if you want to be a poweruser
this is for you. Read in detail at the API docs
http://esp-idf.readthedocs.io/en/latest/api-reference/system/deep_sleep.html
Left the line commented as an example of how to configure peripherals.
The line below turns off all RTC peripherals in deep sleep.
*/
//esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
//Serial.println("Configured all RTC Peripherals to be powered down in sleep");
/*
Now that we have setup a wake cause and if needed setup the
peripherals state in deep sleep, we can now start going to
deep sleep.
In the case that no wake up sources were provided but deep
sleep was started, it will sleep forever unless hardware
reset occurs.
*/
Serial.println("Going to sleep now");
Serial.flush();
digitalWrite(LED_BUILTIN, LOW);
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
void loop() {
//This is not going to be called
}
Debug Message
21:39:43.500 -> Boot number: 1
21:39:43.500 -> Wakeup was not caused by deep sleep: 0
21:39:43.500 -> [ 3708][W][WiFiGeneric.cpp:639] setTxPower(): Neither AP or STA has been started
21:39:43.500 -> [ 3725][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 9 - WIFI_READY
21:39:43.595 -> [ 3806][V][STA.cpp:184] _onStaEvent(): STA Started
21:39:43.595 -> [ 3807][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 11 - STA_START
21:39:43.595 -> [ 3808][V][STA.cpp:110] _onStaArduinoEvent(): Arduino STA Event: 11 - STA_START
21:39:44.086 -> ........[ 8173][V][STA.cpp:214] _onStaEvent(): STA Disconnected: SSID: MYSSID, BSSID: 34:81:c4:1c:4b:f3, Reason: 2
21:39:47.960 -> [ 8175][V][NetworkEvents.cpp:119] checkForEvent(): Network Event: 14 - STA_DISCONNECTED
21:39:47.960 -> [ 8175][V][STA.cpp:110] _onStaArduinoEvent(): Arduino STA Event: 14 - STA_DISCONNECTED
21:39:47.960 -> [ 8176][W][STA.cpp:135] _onStaArduinoEvent(): Reason: 2 - AUTH_EXPIRE
21:39:47.960 -> [ 8177][D][STA.cpp:153] _onStaArduinoEvent(): WiFi Reconnect Running
21:39:47.960 -> [ 8178][W][STA.cpp:533] disconnect(): STA already disconnected.
21:39:47.960 -> ESP-ROM:esp32c6-20220919
21:39:47.960 -> Build:Sep 19 2022
21:39:47.960 -> rst:0xc (SW_CPU),boot:0x8 (SPI_FAST_FLASH_BOOT)
21:39:47.960 -> Saved PC:0x4001975a
21:39:47.960 -> SPIWP:0xee
21:39:47.960 -> mode:DIO, clock div:2
21:39:47.960 -> load:0x4086c410,len:0xc64
21:39:47.960 -> load:0x4086e610,len:0x2730
21:39:47.960 -> load:0x40875728,len:0x594
21:39:47.960 -> entry 0x4086c410
21:39:48.376 -> [ 400][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x42009134
21:39:48.376 -> [ 412][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x420090f8
21:39:48.376 -> [ 423][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x420090bc
21:39:48.417 -> [ 434][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x42009080
21:39:48.417 -> [ 446][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x42009134
21:39:48.417 -> [ 457][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x420090f8
21:39:48.449 -> [ 468][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x420090bc
21:39:48.449 -> [ 480][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x42009080
21:39:48.449 -> [ 491][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type USB_DM (38) successfully set to 0x42005e9c
21:39:48.478 -> [ 503][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type USB_DP (39) successfully set to 0x42005e9c
21:39:48.478 -> [ 515][D][esp32-hal-cpu.c:271] setCpuFrequencyMhz(): PLL: 480 / 6 = 80 Mhz, APB: 40000000 Hz
21:39:48.510 -> [ 538][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 17 successfully set to type UART_RX (2) with bus 0x4080fac0
21:39:48.510 -> [ 549][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 16 successfully set to type UART_TX (3) with bus 0x4080fac0
21:39:48.547 -> [ 560][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 12 successfully set to type USB_DM (38) with bus 0x40812e14
21:39:48.547 -> [ 571][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 13 successfully set to type USB_DP (39) with bus 0x40812e14
21:39:48.547 -> =========== Before Setup Start ===========
21:39:48.547 -> Chip Info:
21:39:48.547 -> ------------------------------------------
21:39:48.547 -> Model : ESP32-C6
21:39:48.547 -> Package : 1
21:39:48.547 -> Revision : 1
21:39:48.547 -> Cores : 1
21:39:48.547 -> Frequency : 80 MHz
21:39:48.547 -> Embedded Flash : No
21:39:48.547 -> Embedded PSRAM : No
21:39:48.547 -> 2.4GHz WiFi : Yes
21:39:48.547 -> Classic BT : No
21:39:48.547 -> BT Low Energy : Yes
21:39:48.547 -> IEEE 802.15.4 : Yes
21:39:48.547 -> ------------------------------------------
21:39:48.547 -> INTERNAL Memory Info:
21:39:48.547 -> ------------------------------------------
21:39:48.547 -> Minimum Free Bytes: 406588 B ( 397.1 KB)
21:39:48.547 -> Largest Free Block: 385012 B ( 376.0 KB)
21:39:48.547 -> ------------------------------------------
21:39:48.547 -> Flash Info:
21:39:48.547 -> ------------------------------------------
21:39:48.547 -> Chip Size : 4194304 B (4 MB)
21:39:48.547 -> Block Size : 65536 B ( 64.0 KB)
21:39:48.547 -> Sector Size : 4096 B ( 4.0 KB)
21:39:48.547 -> Page Size : 256 B ( 0.2 KB)
21:39:48.547 -> Bus Speed : 40 MHz
21:39:48.547 -> Bus Mode : QIO
21:39:48.547 -> ------------------------------------------
21:39:48.547 -> Partitions Info:
21:39:48.547 -> ------------------------------------------
21:39:48.547 -> nvs : addr: 0x00009000, size: 20.0 KB, type: DATA, subtype: NVS
21:39:48.575 -> otadata : addr: 0x0000E000, size: 8.0 KB, type: DATA, subtype: OTA
21:39:48.575 -> app0 : addr: 0x00010000, size: 1280.0 KB, type: APP, subtype: OTA_0
21:39:48.575 -> app1 : addr: 0x00150000, size: 1280.0 KB, type: APP, subtype: OTA_1
21:39:48.575 -> spiffs : addr: 0x00290000, size: 1408.0 KB, type: DATA, subtype: SPIFFS
21:39:48.575 -> coredump : addr: 0x003F0000, size: 64.0 KB, type: DATA, subtype: COREDUMP
21:39:48.575 -> ------------------------------------------
21:39:48.575 -> Software Info:
21:39:48.575 -> ------------------------------------------
21:39:48.575 -> Compile Date/Time : Jun 20 2024 21:38:12
21:39:48.575 -> Compile Host OS : linux
21:39:48.575 -> ESP-IDF Version : v5.1.4-51-g442a798083-dirty
21:39:48.575 -> Arduino Version : 3.0.1
21:39:48.575 -> ------------------------------------------
21:39:48.575 -> Board Info:
21:39:48.575 -> ------------------------------------------
21:39:48.575 -> Arduino Board : DFROBOT_FIREBEETLE_2_ESP32C6
21:39:48.575 -> Arduino Variant : dfrobot_firebeetle2_esp32c6
21:39:48.575 -> Arduino FQBN : esp32:esp32:dfrobot_firebeetle2_esp32c6:UploadSpeed=921600,CDCOnBoot=cdc,CPUFreq=80,FlashFreq=80,FlashMode=qio,FlashSize=4M,PartitionScheme=default,DebugLevel=verbose,EraseFlash=none,JTAGAdapter=default,ZigbeeMode=default
21:39:48.575 -> ============ Before Setup End ============
21:39:48.673 -> [ 704][I][esp32-hal-periman.c:141] perimanSetPinBus(): Pin 12 already has type USB_DM (38) with bus 0x40812e14
21:39:48.673 -> [ 705][I][esp32-hal-periman.c:141] perimanSetPinBus(): Pin 13 already has type USB_DP (39) with bus 0x40812e14
21:39:51.793 -> [ 3706][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type GPIO (1) successfully set to 0x4200776c
21:39:51.793 -> [ 3707][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 15 successfully set to type GPIO (1) with bus 0x10
21:39:51.793 -> Boot number: 1
21:39:51.793 -> Wakeup was not caused by deep sleep: 0
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
You should be sure to disconnect and turn off the radio before deep sleep.
#include <WiFi.h>
#include <esp_wifi.h>
...
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
esp_wifi_deinit();
esp_deep_sleep_start();