pub fn psram_split(
psram: PSRAM<'static>,
reserve: usize,
) -> Result<PsramSplit, PsramSplitError>Expand description
Map the board’s external PSRAM, carve a private region off the base, and register the remainder with the global heap.
The deliberate-global-exposure counterpart of psram_map (which makes
the whole region private and touches the global heap not at all). Reach for
psram_split only once you’ve decided that some of PSRAM should be
reachable by the checked psram_box / psram_vec helpers — that
decision then applies to the whole crate graph’s plain allocations, not
just yours, once internal DRAM runs out (see the module docs).
reservecarves that many bytes private from the base and registers the remainder globally.reserve == 0is the maximal-exposure case: an emptyPsramSplit::privateslice and all PSRAM registered globally. Sound (a zero-length slice grants access to nothing) but rarely what you want — preferpsram_mapif you don’t need any global exposure at all.- The private region is carved from the base, so
PsramSplit::privatestarts at the (large-aligned) PSRAM mapping base — aligned for LVGL’s TLSF with no math; esp-alloc aligns the remainder’s base internally. - This primitive controls placement (the private/global split). The PSRAM
hardware mapping uses the default [
esp_hal::psram] config, which auto-detects size — the board-correct choice for both boards. Apsram_split_with(config)variant is a non-breaking addition if a consumer ever needs a customPsramConfig(a fixedPsramSize, say); no current one does.
Call once, after [esp_hal::init], instead of psram_map: taking
PSRAM<'static> by value makes the once-only mapping a type-level
guarantee, so the two cannot both run.
§Caveats handed back to the caller
- No atomics in the private region. The checked
psram_box/psram_veccannot guard a foreign allocator, so keepingAtomic*out of whatever is placed here is the caller’s responsibility (holds for LVGL whileLV_USE_OSisLV_OS_NONE). SeePsramSafe. - DMA. The ESP32 (Fire27) cannot DMA to/from PSRAM at all; the ESP32-S3
can but slowly. A foreign allocator must not place DMA’d buffers here. See
assert_dma_capable/dma_buffer.
§Errors
PsramSplitError::NotMapped if PSRAM does not map; PsramSplitError::TooSmall
if it maps smaller than reserve.