Skip to content

Commit c5dc164

Browse files
committed
Add option to favor DRAM allocation over IRAM for 32-bit capable mem
1 parent fec8e98 commit c5dc164

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

components/heap/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ menu "Heap memory"
1313
help
1414
Enables heap tracing API.
1515

16+
config HEAP_PRIO_8BIT_RAM
17+
bool "Prioritize allocation of 8-bit access capable RAM"
18+
default n
19+
depends on !HEAP_DISABLE_IRAM
20+
help
21+
Set DRAM region ahead of IRAM region during initialization, so that allocations
22+
can be made against it first.
23+
1624
endmenu

components/heap/port/esp8266/esp_heap_init.c

+18
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ void heap_caps_init(void)
3939
extern char _bss_end;
4040
size_t heap_region_num = 0;
4141

42+
#if CONFIG_HEAP_PRIO_8BIT_RAM
43+
g_heap_region[heap_region_num].start_addr = (uint8_t *)&_bss_end;
44+
g_heap_region[heap_region_num].total_size = ((size_t)(0x40000000 - (uint32_t)&_bss_end));
45+
g_heap_region[heap_region_num].caps = MALLOC_CAP_8BIT | MALLOC_CAP_32BIT | MALLOC_CAP_DMA;
46+
heap_region_num++;
47+
48+
// CONFIG_HEAP_PRIO_8BIT_RAM is only available when CONFIG_HEAP_DISABLE_IRAM=n
49+
extern char _iram_end;
50+
const size_t iram_size = 0x40100000 + CONFIG_SOC_IRAM_SIZE - ((size_t)&_iram_end);
51+
52+
if (iram_size > HEAP_REGION_IRAM_MIN && iram_size < HEAP_REGION_IRAM_MAX) {
53+
g_heap_region[heap_region_num].start_addr = (uint8_t *)&_iram_end;
54+
g_heap_region[heap_region_num].total_size = iram_size;
55+
g_heap_region[heap_region_num].caps = MALLOC_CAP_32BIT | MALLOC_CAP_EXEC;
56+
heap_region_num++;
57+
}
58+
#else
4259
#ifndef CONFIG_HEAP_DISABLE_IRAM
4360
extern char _iram_end;
4461
const size_t iram_size = 0x40100000 + CONFIG_SOC_IRAM_SIZE - ((size_t)&_iram_end);
@@ -55,6 +72,7 @@ void heap_caps_init(void)
5572
g_heap_region[heap_region_num].total_size = ((size_t)(0x40000000 - (uint32_t)&_bss_end));
5673
g_heap_region[heap_region_num].caps = MALLOC_CAP_8BIT | MALLOC_CAP_32BIT | MALLOC_CAP_DMA;
5774
heap_region_num++;
75+
#endif
5876

5977
esp_heap_caps_init_region(g_heap_region, heap_region_num);
6078
}

0 commit comments

Comments
 (0)