diff --git a/arch/risc-v/src/common/espressif/esp_allocateheap.c b/arch/risc-v/src/common/espressif/esp_allocateheap.c index 981e6f705f8..c916b34828b 100644 --- a/arch/risc-v/src/common/espressif/esp_allocateheap.c +++ b/arch/risc-v/src/common/espressif/esp_allocateheap.c @@ -102,6 +102,21 @@ void up_allocate_heap(void **heap_start, size_t *heap_size) #if CONFIG_MM_REGIONS > 1 void riscv_addregion(void) { +#if defined(CONFIG_ESP32P4_SELECTS_REV_LESS_V3) + /* ESP32-P4 rev < v3 has non-contiguous SRAM: sram_low + sram_high. + * The primary heap is in sram_low. Add sram_high as a second region. + */ + + extern uint8_t _sram_high_heap_start[]; + extern uint8_t _sram_high_heap_end[]; + + size_t region_size = _sram_high_heap_end - _sram_high_heap_start; + + if (region_size > 0) + { + kumm_addregion(_sram_high_heap_start, region_size); + } +#endif } #endif diff --git a/boards/risc-v/esp32p4/common/scripts/esp32p4_sections.ld b/boards/risc-v/esp32p4/common/scripts/esp32p4_sections.ld index 5938164558c..1bf07cf4756 100644 --- a/boards/risc-v/esp32p4/common/scripts/esp32p4_sections.ld +++ b/boards/risc-v/esp32p4/common/scripts/esp32p4_sections.ld @@ -690,6 +690,10 @@ SECTIONS _bss_end_high = ABSOLUTE(.); } > sram_high + /* Heap region for sram_high: from end of bss to end of sram_high segment */ + _sram_high_heap_start = _bss_end_high; + _sram_high_heap_end = ORIGIN(sram_high) + LENGTH(sram_high); + /* DWARF 1 */ .debug 0 : { *(.debug) } .line 0 : { *(.line) }