This is an automated email from the ASF dual-hosted git repository.

simbit18 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit b606180da92b78de47dfe2e90c6687cf64755b01
Author: likun17 <[email protected]>
AuthorDate: Wed Mar 18 19:39:01 2026 +0800

    boards/risc-v/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: likun17 <[email protected]>
---
 arch/risc-v/src/common/espressif/esp_allocateheap.c      | 15 +++++++++++++++
 boards/risc-v/esp32p4/common/scripts/esp32p4_sections.ld |  4 ++++
 2 files changed, 19 insertions(+)

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) }

Reply via email to