feat(esp_psram): add esp_psram_ptr_is_no_enc() helper

Drivers that allocate from the unencrypted PSRAM carve-out via
MALLOC_CAP_SPIRAM_NO_ENC currently have no way to verify after the fact
which pool a buffer came from. This is particularly relevant for callers
using heap_caps_malloc_prefer(MALLOC_CAP_SPIRAM_NO_ENC, MALLOC_CAP_SPIRAM),
where a silent fallback to encrypted PSRAM would still pass the typical
esp_ptr_external_ram() check.

Expose esp_psram_ptr_is_no_enc() in the public esp_psram.h header. It
performs a range check against the carve-out's virtual-address window and
returns false when PSRAM is not initialized or CONFIG_SPIRAM_ENC_EXEMPT is
disabled, so callers do not need to guard the call site with #if.

Also reference the helper from the External RAM documentation alongside
the heap_caps_malloc(MALLOC_CAP_SPIRAM_NO_ENC) usage example.
This commit is contained in:
Mahavir Jain
2026-05-21 20:54:31 +05:30
parent 5c28d2a597
commit ef7192fc73
3 changed files with 35 additions and 0 deletions
@@ -618,6 +618,21 @@ bool IRAM_ATTR esp_psram_check_ptr_addr(const void *p)
return false;
}
bool IRAM_ATTR esp_psram_ptr_is_no_enc(const void *p)
{
#if CONFIG_SPIRAM_ENC_EXEMPT
if (!s_psram_ctx.is_initialised) {
return false;
}
return ((intptr_t)p >= s_psram_ctx.mapped_regions[PSRAM_MEM_ENC_EXEMPT].vaddr_start &&
(intptr_t)p < s_psram_ctx.mapped_regions[PSRAM_MEM_ENC_EXEMPT].vaddr_end);
#else
(void)p;
return false;
#endif
}
esp_err_t esp_psram_extram_reserve_dma_pool(size_t size)
{
if (size == 0) {