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

maldus
Posts: 83
Joined: Wed Jun 06, 2018 1:41 pm

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

Postby maldus » Fri Oct 20, 2023 1:06 pm

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?

ESP_Sprite
Posts: 9308
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Sun Oct 22, 2023 12:05 am

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.

Alberk
Posts: 52
Joined: Sat Jun 19, 2021 1:49 am

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

Postby Alberk » Sun Oct 22, 2023 3:10 am

Are you able to connect to Wifi with non PSRAM module?

maldus
Posts: 83
Joined: Wed Jun 06, 2018 1:41 pm

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

Postby maldus » Mon Oct 23, 2023 7:27 am

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.

maldus
Posts: 83
Joined: Wed Jun 06, 2018 1:41 pm

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

Postby maldus » Tue Oct 31, 2023 3:00 pm

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?

ESP_Sprite
Posts: 9308
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Wed Nov 01, 2023 10:43 am

No, sorry, it's mostly a compile-time thing.

Who is online

Users browsing this forum: No registered users and 141 guests