Skip to content

Use PSRAM to reduce heap usage percentage on ESP32 with PSRAM#8891

Merged
thebentern merged 5 commits into
meshtastic:developfrom
samm-git:use_psram
Dec 10, 2025
Merged

Use PSRAM to reduce heap usage percentage on ESP32 with PSRAM#8891
thebentern merged 5 commits into
meshtastic:developfrom
samm-git:use_psram

Conversation

@samm-git

@samm-git samm-git commented Dec 7, 2025

Copy link
Copy Markdown
Contributor

Hi, this is my first PR for the meshtastic project. It is here to address #8732. After applying this patch, I reduced heap consumption from 89% to 55% and saw significant improvements in stability. I am using LilyGo T-Beam device.

🤝 Attestations

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card
    • Other (please specify below)

@thebentern

Copy link
Copy Markdown
Contributor

Will this cause conflicts with S&F @caveman99?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables PSRAM utilization on ESP32 boards to reduce heap memory usage from 89% to 55%, improving stability on devices like the LilyGo T-Beam. The changes configure ESP32's memory allocator to use external PSRAM for larger allocations and switch packet pool allocation from static to dynamic on PSRAM-equipped boards.

  • Configures ESP32 heap allocator to use PSRAM for allocations ≥256 bytes
  • Switches packet memory pool from static to dynamic allocation on boards with PSRAM

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/main.cpp Adds PSRAM initialization call to enable external memory usage for heap allocations on ESP32 boards with PSRAM
src/mesh/Router.cpp Extends dynamic packet pool allocation logic to include boards with PSRAM, not just STM32WL

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main.cpp Outdated
Comment thread src/mesh/Router.cpp Outdated
@samm-git

samm-git commented Dec 7, 2025

Copy link
Copy Markdown
Contributor Author

It should not conflict with S & F but i can test it. S&F uses ps_malloc, which always tells to use PSRAM for the allocation. As after my patch PSRAM is only 1% busy it should not significantly reduce amount of memory available for s&f

@thebentern

Copy link
Copy Markdown
Contributor

It should not conflict with S & F but i can test it. S&F uses ps_malloc, which always tells to use PSRAM for the allocation. As after my patch PSRAM is only 1% busy it should not significantly reduce amount of memory available for s&f

That was my thought as well. Thanks for testing :-)

@thebentern thebentern added the enhancement New feature or request label Dec 7, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main.cpp Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@thebentern thebentern merged commit 5910cc2 into meshtastic:develop Dec 10, 2025
78 checks passed
scobert969 pushed a commit to zeropt/meshtastic-firmware that referenced this pull request Dec 22, 2025
…stic#8891)

* Use PSRAM for malloc > 256bytes to get more heap memory

* Use dynamic allocator on boards with PSRAM to free more heap

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Move heap_caps_malloc_extmem_enable() to the top of the init

* Update src/main.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
jeek pushed a commit to jeek/Meshtastic-Exploiteers-Hacker-Pager that referenced this pull request Jun 30, 2026
…stic#8891)

* Use PSRAM for malloc > 256bytes to get more heap memory

* Use dynamic allocator on boards with PSRAM to free more heap

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Move heap_caps_malloc_extmem_enable() to the top of the init

* Update src/main.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants