Skip to content

esp32/main: Support SPRAM allocated using malloc #8219

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

Closed
wants to merge 1 commit into from

Conversation

mocleiri
Copy link
Contributor

@mocleiri mocleiri commented Jan 28, 2022

Integrating with the esp32-camera for example requires that ESP32 SPRAM be allocatable using the esp-idf
capabilities aware allocation functions. In the case of esp32-camera its for the framebuffer.

Detect when CONFIG_SPIRAM_USE_MALLOC is in use and use the standard automatic configuration of leaving 1/2
of the SPRAM available to other FreeRTOS tasks.

My original thought was to allow the board config to control how much the micropython heap was reduced but I've read some of the other related issues and pull requests and it seems that an algorithm/heuristic is the preferred approach.

Here I just add a new no-op block that will in the case the esp32 is configured to allocate psram using malloc to skip past the normal MMAP allocation strategy and use the non-psram allocation strategy.

I've used this patch locally to build a firmware for esp32-cam-mb and m5-timer-camera:
https://github.com/mocleiri/tensorflow-micropython-examples/tree/feature/59-integrate-esp32-camera-acquisition
mocleiri/tensorflow-micropython-examples#59

--
This patch adds this case into the logic added here: 23b1a4e for non spram heap sizing.

Related:
#7214 (except that our case is when the other idf modules in use need to use the idf capabilities allocation functions where malloc can allocate them parts of psram)

This change allows the same heap allocation rules to be used when using
malloc regardless if the board has SPRAM or normal RAM.

Integrating with the esp32-camera for example requires that ESP32 SPRAM
be allocatable using the esp-idf capabilities aware allocation functions.

In the case of esp32-camera its for the framebuffer.

Detect when CONFIG_SPIRAM_USE_MALLOC is in use and use the standard
automatic configuration of leaving 1/2 of the SPRAM available to other
FreeRTOS tasks.
@mocleiri
Copy link
Contributor Author

I need help with how to fix the code formatting failure.

My commit changes 4 lines in ports/esp32/main.c but it looks like the code formatter check is failing inside other files I didn't touch.

@dpgeorge
Copy link
Member

dpgeorge commented Feb 2, 2022

I need help with how to fix the code formatting failure.

You can ignore those errors, they are from a new version of Black.

Here I just add a new no-op block that will in the case the esp32 is configured to allocate psram using malloc to skip past the normal MMAP allocation strategy and use the non-psram allocation strategy.

Sounds like a good approach!

@dpgeorge
Copy link
Member

dpgeorge commented Feb 2, 2022

Merged in eae2e35

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

Successfully merging this pull request may close these issues.

2 participants