Description
Hardware:
Board: ESP32 Dev Module
Core Installation version: 1.0.6 , 2.0.0
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Fedora 34 x86_64
Description:
When testing many of my Arduino-ESP32 project with 2.0.0 versus 1.0.6, I notice that both required binary space and RAM use are consistently larger in 2.0.0 versus 1.0.6. This introduces the risk that projects that previously worked comfortably within allocated app partition and RAM space under 1.0.6, will now require extra partition space, risking overflows, and/or crashes because of insufficient ram. Nothing has been changed except the version of SDK (1.0.6 versus 2.0.0).
Sketch: (leave the backquotes for code formatting)
#include "WiFi.h"
#if CONFIG_IDF_TARGET_ESP32
//#define WIFI_PIN GPIO_NUM_4
#define WIFI_PIN GPIO_NUM_27
#elif CONFIG_IDF_TARGET_ESP32S2
#define WIFI_PIN GPIO_NUM_14
#endif
void reportMemoryUse(const char * label)
{
Serial.printf("MEMORY USE AT %s: %u total, %u free, %u max.alloc\r\n",
label, ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMaxAllocHeap());
}
void setup()
{
Serial.begin(115200);
#ifdef WIFI_PIN
pinMode(WIFI_PIN, OUTPUT);
digitalWrite(WIFI_PIN, LOW);
#endif
reportMemoryUse("setup() before WiFi setup");
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("Setup done");
reportMemoryUse("setup() after WiFi setup");
}
void loop()
{
Serial.println("scan start");
// WiFi.scanNetworks will return the number of networks found
#ifdef WIFI_PIN
digitalWrite(WIFI_PIN, HIGH);
#endif
int n = WiFi.scanNetworks();
#ifdef WIFI_PIN
digitalWrite(WIFI_PIN, LOW);
#endif
Serial.println("scan done");
if (n == 0) {
Serial.println("no networks found");
} else {
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i) {
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
delay(10);
}
}
Serial.println("");
reportMemoryUse("after WiFi scan");
// Wait a bit before scanning again
delay(3000);
}
Debug Messages:
Under 1.0.6, this sketch compiles into a 638608-byte binary, and shows the following output:
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4
MEMORY USE AT setup() before WiFi setup: 360808 total, 334340 free, 113792 max.alloc
Setup done
MEMORY USE AT setup() after WiFi setup: 359568 total, 283652 free, 113792 max.alloc
scan start
scan done
12 networks found
(redacted)
MEMORY USE AT after WiFi scan: 359484 total, 282476 free, 113792 max.alloc
scan start
scan done
17 networks found
(redacted)
MEMORY USE AT after WiFi scan: 359484 total, 282076 free, 113792 max.alloc
Under 2.0.0, the exact same sketch compiles into a 724912-byte binary (86304 bytes larger), and shows the following output:
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1240
load:0x40078000,len:13012
load:0x40080400,len:3648
entry 0x400805f8
MEMORY USE AT setup() before WiFi setup: 366171 total, 308455 free, 65524 max.alloc
Setup done
MEMORY USE AT setup() after WiFi setup: 364203 total, 228051 free, 65524 max.alloc
scan start
scan done
14 networks found
(redacted)
MEMORY USE AT after WiFi scan: 364179 total, 226875 free, 65524 max.alloc
scan start
scan done
13 networks found
(redacted)
MEMORY USE AT after WiFi scan: 364179 total, 226955 free, 65524 max.alloc
The sketch now sees 226955 bytes of free RAM (versus 282076 bytes under 1.0.6), an unexplained 55121-byte increase.
This is worrying because some of our projects using ESP32 boards (with no PSRAM) are already having trouble running OTA updates via their web interface under 2.0.0, as apparently a 4096-byte malloc() inside the Updater object now fails where it previously succeded with 1.0.6.