-
Notifications
You must be signed in to change notification settings - Fork 7.6k
High memory consumption on 2.0.0rc1 core #5474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I tested the sketch below and got about 343K free. void setup() {
Serial.begin(115200);
}
void loop() {
Serial.println((unsigned long)ESP.getFreeHeap());
delay(5000);
} |
This issue of additional memory use persists in recently-released 2.0.0 stable versus 1.0.6. In my case, the difference is enough to have 1.0.6 stashed alongside 2.0.0 in case one of our projects fails due to memory starvation. For example, consider the following sketch: This sketch compiles properly under 1.0.6 and 2.0.0. However, note the difference in memory use, especially after WiFi is set up: Under 1.0.6:
Under 2.0.0:
By switching SDK releases and doing nothing else, the free memory has decreased from 282076 to 226955 (an unexplained additional 55121 bytes), and the maximum allocatable block has decreased from 113792 to 65524 bytes. Why???? |
1.0.6 uses IDF 3.3 I guess this is the reason for a higher RAM consumption. |
Maybe, in the near future, on the final release of IDF 4.4 and respective rebase of Arduino Core to this IDF, it may improve. No promises.... |
there are many reasons why there is a different memory usage in recent IDF. This is in NO WAY connected to Arduino. Arduino's is mostly disabling some IRAM optimizations, because users have sketches with WiFi, BT and all kinds of other things that make compilation impossible. That change though actually gives you memory. Do you actually have memory issues? |
Maybe some additional IRAM optimization was overlooked?
Yes, I do have memory issues with some of my projects that were absent when compiled under 1.0.6. At least one of our projects (the firmware for the OpenVenti artificial respirator project) is unable to complete its OTA firmware update procedure due to insufficient RAM under 2.0.0, where the same source code worked successfully with 1.0.6. This has forced me to look for and remove RAM inefficiencies in the process, but the fact remains that 55Kb extra RAM use is currently a showstopper for updating to 2.0.0, at least for this project. |
Here is some additional data based on IDF example, examples/wifi/getting-started/station:
First, note that with the default sdkconfig, IDF 4.4-dev has about 7kB less heap at app_main than IDF release/3.3. See the note [1] below, though. These numbers include "IRAM" heap; if we compare only DRAM heap (MALLOC_CAP_DEFAULT), then v4.4-dev has 2kB more heap than 3.3 (277032 bytes free in v4.4-dev, 275824 free in release/v3.3) when this example starts up — see the table below. We can see that some RAM can be reclaimed by changing the configuration (sdkconfig) that arduino-esp32 is built with. The sdkconfig used in 2.0.0 results in 35kB higher RAM usage than the default sdkconfig (for the same IDF version). In 1.0.6 this was only 10kB higher. For the rest of the difference between 1.0.6 and 2.0.0 heap usage we should look at the startup heap size: 334340 vs 308455 (26kB difference). This might be due to higher static memory usage (.data, .bss) and/or higher heap usage. The issue might be on IDF side or Arduino-esp32 side, it is hard to say without investigating it in detail. For the static memory usage, Note 1: note that arduino-esp32 ESP.getFreeHeap() function returns the amount of internal DRAM and IRAM; the latter is not available via Here is the version of the table above, but this time showing only the DRAM heap (MALLOC_CAP_DEFAULT). Note that "Heap used" (difference) is the same as above, just the initial number in each row is less by the amount of free IRAM in the particular configuration:
Note 2: https://raw.githubusercontent.com/espressif/arduino-esp32/2.0.0/tools/sdk/esp32/sdkconfig |
@ale-trevizoli a) bin size of 632405 bytes
I created a repository with a new Arduino Core 2.0.0 that can be tested. In order to install it as a separated board for testing, please follow the instructions from
In case it works fine for a number of users, we will commit it for the next ESP32 Arduino release. |
Memory consumption is GREAT! ... but I have wifi issues using the My code worked fine on Arduino v1.0.6 and Arduino v2.0.0 master branch I have my own logging facility which is why there is additional log output below. environment
additional config// I use onEvent
WiFi.onEvent([&](arduino_event_id_t event, arduino_event_info_t info) { /* ... */ });
// I only use STA
WiFi.mode(WIFI_MODE_STA);
// I save wifi details elsewhere
WiFi.persistent(false);
// I manually reconnect in my loop
WiFi.setAutoReconnect(false);
// I make the initial connection later on by calling esp_wifi_connect();
WiFi.begin(ssid, password, 0 NULL, false); logs
|
|
Thanks for your reply, Update 1I've created a reproducible example which can be found here https://github.com/olicooper/arduino-v2-esp32-platformio/tree/wifi-test. The repo readme has more detail. Update 2I have recompiled the code with the v2.0.0 I've updated the log output with logs from the working v2.0.0 |
@olicooper, Could you please confirm it by executing:
Update:Nevermind, it is in the logs. |
I have now configured an old
Is there a WiFi configuration you are using that I can try to see if I can get it to connect? |
The logs are not consistent with code from repository. Here you have |
Yeah I kept noticing that static IP too, but I am not calling You'll notice that
arduino-esp32/libraries/WiFi/src/WiFiSTA.cpp Lines 211 to 215 in 77f1ebd
Also, In my code I call arduino-esp32/libraries/WiFi/src/WiFiSTA.cpp Lines 217 to 222 in 77f1ebd
I am happy to provide you with any information to help you figure it out, but please don't suggest that I am providing you with false/inaccurate information or that I am making simple configuration errors rather than this being a genuine bug report. I have a decent amount of experience with networking and I've spent a number of years coding embedded devices. I understand that there may be a lot of people using Arduino that configure their home projects incorrectly but that isn't everyone. I appreciate what you are doing for the community. Thank you for your support and understanding. Update 1After you mentioned using WiFi.config(IPAddress(192,168,1,8), IPAddress(192,168,1,1), IPAddress(255,255,255,0), IPAddress(192,168,1,1));
WiFi.begin(ssidStr.c_str(), passStr.c_str());
It seems to be a variation of Update 2I've isolated the problem... It seems that I am able to connect when security is not configured on the router or esp e.g.
Also, the output from
@SuGlider The |
@olicooper That is good diagnostic |
Good idea. I've tested with WPA2,WPA,WEP as these are the only options on the old router. I can't modify the new router as it is in active use. WPA and WPA2 are not working (
|
@olicooper |
Arduino v2.0.1 (v4.4-dev-3401-gb86fe0c66c / sha.77f1ebd)
Arduino v2.0.0 (v4.4-dev-2313-gc69f0ec32 / sha.44c1198)
Arduino v1.0.6 (v3.3.5-1-g85c43024c / sha.46d5afb) platform = https://github.com/platformio/platform-espressif32.git#v3.3.2
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#1.0.6
|
WPA/WPA2 demands at least 1 TX Cache Buffer. issue described in #5474 (comment)
@olicooper |
I added Arduino v1.0.6 (v3.3.5-1-g85c43024c) ==> Free memory: 213,900 bytes || Binary Size 692,190 bytes Comparing V2.0.0 with V2.0.1, this sketch has about 74K extra heap and takes about 90K less flash with the compiled binary. |
Really great work! It's working fine for me now 👍 |
on commit deacf43 sdkconfig modifications to build libraries with compile optimization to size (-Os) keep all the bootloaders with -Os and no boot messages changes max number of sockets from 10 to 16 disables LWIP "Experimental PPP and SLIP" because it adds about 60K to the binary size and it's not used in Arduino on commit a133257 sets WIFI LWIP to try first to allocate from SPIRAM on esp32 (this is esp32s2 default configuration) defines SPIRAM_MALLOC_ALWAYSINTERNAL to 4096 bytes on esp32 (same as default for esp32s2) disables SPIRAM_MALLOC_RESERVE_INTERNAL on both esp32 and esp32s2 to release more RAM to heap Related PRs in Arduino-ESP32: espressif/arduino-esp32#5789 espressif/arduino-esp32#5791 Related issue: espressif/arduino-esp32#5699 espressif/arduino-esp32#5474 espressif/arduino-esp32#5630 espressif/arduino-esp32#5751
) Summary Modifies WiFi lib to allow dynamic buffer allocation along with SPIRAM MALLOC enabled This gives more heap space to the users Related PR in Arduino Lib Builder: espressif/esp32-arduino-lib-builder#47 Impact WiFi will work the same as it was in version 1.0.6, restoring free heap. close #5630 close #5474 close #5699 close #5697
…pressif#5791) Summary Modifies WiFi lib to allow dynamic buffer allocation along with SPIRAM MALLOC enabled This gives more heap space to the users Related PR in Arduino Lib Builder: espressif/esp32-arduino-lib-builder#47 Impact WiFi will work the same as it was in version 1.0.6, restoring free heap. close espressif#5630 close espressif#5474 close espressif#5699 close espressif#5697
Hi.
I'm using esp32-dev board 4Mb Flash.
I have a system developed with Arduino IDE 1.8.5 and ESP32 core 1.0.6.
This system print on loop() - ESP.getFreeHeap() each 5 seconds, and show me ~302K free.
I exchange 1.0.6 to 2.0.0rc1 and I only compiled again and got ~265K free, difference of 37Kbytes.
What's can happening?
Thanks!
The text was updated successfully, but these errors were encountered: