esp-rs / esp-hal

no_std Hardware Abstraction Layers for ESP32 microcontrollers
https://docs.esp-rs.org/esp-hal/
Apache License 2.0
640 stars 178 forks source link

Add PSRAM support #455

Closed teotwaki closed 1 year ago

teotwaki commented 1 year ago

Hi,

I was wondering if there was any support for PSRAM, and if so, if anyone would have an example on how to use it. I'm already using the global allocator, however I believe I only have access to the 300k of on-board RAM.

Thanks!

bjoernQ commented 1 year ago

Short answer: it's not there quite yet

Previously (in the first attempt on a HAL for ESP32) we relied on the bootloader to setup PSRAM but here we need to implement those things on our side

Secondly, we need to teach esp-alloc about the additional RAM to use it as heap memory.

teotwaki commented 1 year ago

Would it help to have a blurb somewhere in the documentation mentioning this? Is there anything else that we could do to help with?

bjoernQ commented 1 year ago

A good start might be to port e.g. https://github.com/apache/nuttx/blob/master/arch/xtensa/src/esp32/esp32_spiram.c , starting with esp_spiram_init which might require more code ported (like https://github.com/apache/nuttx/blob/master/arch/xtensa/src/esp32/esp32_psram.c )

And then do the same for ESP32-S2 and ESP32-S3.

Depending on which code base you are more familiar with, looking at this functionality in esp-idf might or might not be a better option.

When all that works PSRAM should be accessible via usual read and writes to the memory region.

If that is done adapting esp-alloc to always allocate in PSRAM should be trivial - having a way to allocate from both internal RAM and PSRAM at the same time via esp-alloc seems tricky currently and might be something to figure out later.

I'm not sure if this should be noted somewhere in the documentation currently since in general, we document what is support - not what is not yet supported. Also, with this we now have an issue for it

bjoernQ commented 1 year ago

https://github.com/esp-rs/esp-hal/pull/493 added basic PSRAM support for ESP32-S2

Support for other targets will follow

bjoernQ commented 1 year ago

506 adds basic PSRAM support for ESP32

bjoernQ commented 1 year ago

517 adds basic PSRAM support for ESP32-S3

bjoernQ commented 1 year ago

Closing as complete