Skip to content
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

Remove SPI RAM requirement #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Remove SPI RAM requirement #8

wants to merge 3 commits into from

Conversation

ciniml
Copy link

@ciniml ciniml commented Dec 25, 2024

This PR adjusts the memory usage of the code and remove the requirement of SPI RAM.

  • Reduce the main task stack size from 16384 to 10240.

  • Configure ESP-IDF Wi-Fi driver to allocate TX buffer dynamically.

    • It reduces the maximum RAM usage.
  • Disable the SPI RAM by default.

  • Fix that stack buffer allocation fails and launching audio_publisher fails silently when SPI RAM is disabled.

I have checked with M5Stack CoreS3 SE with some modification for porting.
But I cannot check this code with Freenove ESP32-S3-WROOM and Sonatino, because I do not have them.
So please check this code with these boards if this code seems well.

@juberti-oai
Copy link

How much internal RAM does the M5Stack board have? I was unable to get the Sonatino to even connect when using only internal RAM.

@ciniml
Copy link
Author

ciniml commented Dec 28, 2024

How much internal RAM does the M5Stack board have

CoreS3 SE also uses ESP32-S3, so it have the same internal RAM size of Sonatino.

Do you mean that the modification in this PR did not work for Sonatino?

src/webrtc.cpp Outdated
#else // CONFIG_SPIRAM
constexpr size_t stack_size = 20000;
StackType_t *stack_memory = (StackType_t *)malloc(stack_size * sizeof(StackType_t));
#endif // CONFIG_SPIRAM
Copy link

@igrr igrr Dec 28, 2024

Choose a reason for hiding this comment

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

Just a few notes about this code from a passer-by:

CONFIG_SPIRAM=y is not a sufficient condition to be sure that we can allocate from SPIRAM. CONFIG_SPIRAM_IGNORE_NOTFOUND might be set, in which case the application will boot up and ignore the lack of SPI RAM. SPIRAM_USE_MEMMAP might also be set, in which case SPIRAM will initialized but won't be available for malloc or heap_caps_malloc.

We can use heap_caps_malloc_prefer, instead, and ask it to use SPIRAM and fall back to the internal RAM otherwise:

constexpr size_t stack_size = 20000;
StackType_t *stack_memory = (StackType_t *)heap_caps_malloc_prefer(
        20000 * sizeof(StackType_t), 2, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);

(we also don't need preprocessor conditions this way)

Another option is to use regular malloc and adjust CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL to a smaller value, so that large allocations get placed into SPIRAM automatically.

Copy link
Author

@ciniml ciniml Jan 9, 2025

Choose a reason for hiding this comment

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

Fixed to use heap_caps_malloc_prefer and removed CONFIG_SPIRAM ifdef block.
3e919b5

@ciniml
Copy link
Author

ciniml commented Jan 13, 2025

Rebased to upstream/main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants