Page 1 of 1

Excessive internal memory allocation for WiFi when PSRAM is enabled but not present

Posted: Fri Oct 20, 2023 1:06 pm
by maldus
Hello everyone,
I have an ongoing project that targets ESP32S2 modules. Most of them are equipped with internal PSRAM, but some are not.
I would like to publish a firmware update that leverages on PSRAM to add more functions. This update is targeted to all devices, but those who don't have PSRAM should just cut out the most RAM-intensive functions.

I planned to do this via the CONFIG_SPIRAM_IGNORE_NOTFOUND. The issue is that devices without a PSRAM require a disproportionate amount of internal RAM to initialize the WiFi.

By inspecting the amount of free RAM I can see that, when no PSRAM is either present or enabled, the amount of free RAM goes from 129992 bytes to 77404 bytes when invoking `esp_wifi_init` (default configuration). However, if I enable the PSRAM and instruct the processor to ignore it if not present the same functions uses twice as much RAM (from 126288 bytes to 19172 bytes).

The only options modified between the two cases are CONFIG_ESP32S2_SPIRAM_SUPPORT and CONFIG_SPIRAM_IGNORE_NOTFOUND.

Why the difference in required RAM when the PSRAM is enabled but not present?

Re: Excessive internal memory allocation for WiFi when PSRAM is enabled but not present

Posted: Sun Oct 22, 2023 12:05 am
by ESP_Sprite
PSRAM has some quirks that make it different from internal memory: e.g. it 'disappears' when the cache is disabled, which happens e.g. when flash is being written to and DMA'ing to and from it works a bit different. For that reason, a bunch of stuff needs to be put in IRAM where without PSRAM, it could stay in flash memory. That uses up some RAM.

Re: Excessive internal memory allocation for WiFi when PSRAM is enabled but not present

Posted: Sun Oct 22, 2023 3:10 am
by Alberk
Are you able to connect to Wifi with non PSRAM module?

Re: Excessive internal memory allocation for WiFi when PSRAM is enabled but not present

Posted: Mon Oct 23, 2023 7:27 am
by maldus
ESP_Sprite wrote: PSRAM has some quirks that make it different from internal memory: e.g. it 'disappears' when the cache is disabled, which happens e.g. when flash is being written to and DMA'ing to and from it works a bit different. For that reason, a bunch of stuff needs to be put in IRAM where without PSRAM, it could stay in flash memory. That uses up some RAM.
Thank you @ESP_Sprite for the clarification. Does this mean that in order to support PSRAM I must be ready to allocate about 60KB more RAM in order to use WiFi, no matter what? I didn't even tick the option to try and allocate the WiFi stack on PSRAM. I would be happy with just using PSRAM for my application's needs and only if present.
Alberk wrote: Are you able to connect to Wifi with non PSRAM module?
Yes.

Re: Excessive internal memory allocation for WiFi when PSRAM is enabled but not present

Posted: Tue Oct 31, 2023 3:00 pm
by maldus
I have made some experiments but found no way to avoid the RAM expense if the SPI chip isn't present.
Isn't it possible at all to only enable it if found?

Re: Excessive internal memory allocation for WiFi when PSRAM is enabled but not present

Posted: Wed Nov 01, 2023 10:43 am
by ESP_Sprite
No, sorry, it's mostly a compile-time thing.