Skip to content

Commit d567874

Browse files
committed
esp32p4: add sram_high as second heap region for rev < v3
On ESP32-P4 rev < v3, the 768KB HP L2MEM is split into two non-contiguous regions: sram_low and sram_high. Previously only sram_low was used for the heap, wasting 384KB of sram_high. Export _sram_high_heap_start and _sram_high_heap_end symbols from the linker script and add sram_high to the heap via kumm_addregion() in riscv_addregion() when MM_REGIONS > 1. Signed-off-by: lk <lk@xiaomi.com> Signed-off-by: likun17 <likun17@xiaomi.com>
1 parent 15c5753 commit d567874

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

arch/risc-v/src/common/espressif/esp_allocateheap.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ void up_allocate_heap(void **heap_start, size_t *heap_size)
102102
#if CONFIG_MM_REGIONS > 1
103103
void riscv_addregion(void)
104104
{
105+
#if defined(CONFIG_ESP32P4_SELECTS_REV_LESS_V3)
106+
/* ESP32-P4 rev < v3 has non-contiguous SRAM: sram_low + sram_high.
107+
* The primary heap is in sram_low. Add sram_high as a second region.
108+
*/
109+
110+
extern uint8_t _sram_high_heap_start[];
111+
extern uint8_t _sram_high_heap_end[];
112+
113+
size_t region_size = _sram_high_heap_end - _sram_high_heap_start;
114+
115+
if (region_size > 0)
116+
{
117+
kumm_addregion(_sram_high_heap_start, region_size);
118+
}
119+
#endif
105120
}
106121
#endif
107122

boards/risc-v/esp32p4/common/scripts/esp32p4_sections.ld

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,10 @@ SECTIONS
690690
_bss_end_high = ABSOLUTE(.);
691691
} > sram_high
692692

693+
/* Heap region for sram_high: from end of bss to end of sram_high segment */
694+
_sram_high_heap_start = _bss_end_high;
695+
_sram_high_heap_end = ORIGIN(sram_high) + LENGTH(sram_high);
696+
693697
/* DWARF 1 */
694698
.debug 0 : { *(.debug) }
695699
.line 0 : { *(.line) }

0 commit comments

Comments
 (0)