esp_hal

Module psram

Source
Available on crate feature unstable only.
Expand description

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

§PSRAM “virtual peripheral” driver (ESP32)

§Overview

The PSRAM module provides support for accessing and controlling the Pseudo Static Random Access Memory (PSRAM) on the ESP32.

The PSRAM module enables users to interface with the PSRAM memory present on the ESP32 chip. PSRAM provides additional external memory to supplement the internal memory of the ESP32, allowing for increased storage capacity and improved performance in certain applications.

§Examples

§Quad PSRAM

This example shows how to use PSRAM as heap-memory via esp-alloc. You need an ESP32 with at least 2 MB of PSRAM memory. Notice that PSRAM example must be built in release mode!


// Initialize PSRAM and add it as a heap memory region
fn init_psram_heap(start: *mut u8, size: usize) {
    unsafe {
        esp_alloc::HEAP.add_region(esp_alloc::HeapRegion::new(
            start,
            size,
            esp_alloc::MemoryCapability::External.into(),
        ));
    }
}

// Initialize PSRAM and add it to the heap
let (start, size) = psram::init_psram(peripherals.PSRAM,
    psram::PsramConfig::default());

init_psram_heap(start, size);

let mut large_vec: Vec<u32> = Vec::with_capacity(500 * 1024 / 4);

for i in 0..(500 * 1024 / 4) {
    large_vec.push((i & 0xff) as u32);
}

let string = String::from("A string allocated in PSRAM");

Structs§

Enums§

Functions§

  • Returns the address and size of the available in external memory.