Internal RAM overflow issue in ESP32 S3

Hbking
Posts: 2
Joined: Tue Jun 17, 2025 12:41 pm

Internal RAM overflow issue in ESP32 S3

Postby Hbking » Tue Oct 28, 2025 9:49 am

Hi everyone,

We are using an ESP32-S3(16R8) module with ESP-IDF and FreeRTOS, and we are facing an internal RAM overflow issue when multiple subsystems are active simultaneously.

The system works absolutely fine when provisioning is stopped.

Our application includes:

1. AWS IoT (MQTT Communication) with EmbedTLS
Used for device shadows and other MQTT-based protocols with AWS IoT Core.

2. BLE Provisioning
Continuous BLE provisioning mode.
On deinitialization, it takes around 10 seconds to release resources (wifi_prov_mgr_disable_auto_stop(10000)).

3. OTA Over MQTT
OTA updates are fetched and applied through MQTT, parallel to the main state machine.

4. LVGL Touch Display
A simple graphical interface driven by LVGL (using internal RAM for buffers).

We are getting the following issue:

When all three components—BLE provisioning, OTA, and AWS IoT MQTT communication—are active at the same time, the system becomes unstable and eventually crashes due to internal RAM overflow.

I monitored heap usage, and it shows around 98% utilization when all modules are active. At this point, the system randomly throws allocation failures and resets unexpectedly.

Total internal heap: 261411 bytes
Available internal heap: 4575 bytes
Internal heap utilization: 98%
Available external (SPI RAM) heap: 3392488 bytes
Available heap (internal + external): 3396668 bytes
Available largest contiguous block in internal heap: 304 bytes
Minimum heap that has ever been available: 3377504 bytes

Whenever the device crashes, it shows the following:
E (1637611) esp-aes: Failed to allocate memory
E (1637611) esp-tls-mbedtls: read error :-0x0001:
E (1637612) transport_base: esp_tls_conn_read error, errno=Success
E (1637612) tls_freertos: Reading failed, errno= 0

Additional details:
- ESP-IDF version: 5.2.1
- FreeRTOS is used with standard task priorities and stack sizes.
- PSRAM is enabled
- Observed that this issue occurs mostly when an AWS connectivity issue occurs
- BLE provisioning appears to occupy a significant chunk of internal memory(Around 30kb).

My questions:

1. Is there any recommended way to optimize internal RAM usage when running BLE + MQTT + OTA + LVGL together?
2. Can some AWS IoT or BLE buffers be forced into PSRAM safely?
3. Is there a way to reduce the BLE provisioning RAM footprint, especially if it needs to run continuously?
4. Any known issues or configuration tweaks for this combination on ESP32-S3 (16R8)?

Any other suggestions, experiences, or best practices to manage memory efficiently in such a setup would be greatly appreciated.

Also sharing the sdkconfig of the project for your reference.

Thanks in advance!
Attachments
sdkconfig.txt
(3.25 KiB) Downloaded 27 times

nopnop2002
Posts: 347
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

Re: Internal RAM overflow issue in ESP32 S3

Postby nopnop2002 » Thu Nov 27, 2025 12:16 pm

Available external (SPI RAM) heap: 3392488 bytes
Available heap (internal + external): 3396668 bytes
When external RAM is enabled, external SPI RAM can be allocated using standard malloc calls, or via heap_caps_malloc(MALLOC_CAP_SPIRAM), depending on the configuration.

On ESP32 only external SPI RAM under 4 MiB in size can be allocated this way. To use the region above the 4 MiB limit, you can use the himem API.

https://docs.espressif.com/projects/esp ... himem.html

MicroController
Posts: 2661
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Internal RAM overflow issue in ESP32 S3

Postby MicroController » Sat Nov 29, 2025 8:39 am

LVGL can be a memory hog too. You may want to look into moving some or all of its allocations to PSRAM.

Who is online

Users browsing this forum: No registered users and 9 guests