Merge branch 'change/change_regdma_malloc_caps_v6.1' into 'release/v6.1'

change(esp_hw_support): change regdma malloc caps to allow getting memory in the DMA pool (v6.1)

See merge request espressif/esp-idf!50257
This commit is contained in:
Jiang Jiang Jian
2026-07-16 10:44:21 +08:00
9 changed files with 39 additions and 29 deletions
@@ -421,7 +421,10 @@ inline static bool esp_stack_ptr_is_sane(uint32_t sp)
|| esp_stack_ptr_in_extram(sp)
#endif
#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
|| esp_ptr_in_rtc_dram_fast((void*) sp)
|| (esp_ptr_in_rtc_dram_fast((void *)sp) && ((sp & 0xF) == 0))
#endif
#if SOC_MEM_SPM_SUPPORTED
|| (esp_ptr_in_spm((void *)sp) && ((sp & 0xF) == 0))
#endif
;
}
+1 -1
View File
@@ -124,7 +124,7 @@ config SPIRAM_MALLOC_RESERVE_INTERNAL
that the internal memory is entirely filled up. This causes allocations that are specifically done in
internal memory, for example the stack for new tasks or memory to service DMA or have memory that's
also available when SPI cache is down, to fail. This option reserves a pool specifically for requests
like that; the memory in this pool is not given out when a normal malloc() is called.
like that; a normal malloc() can fall back to the pool only after all other internal are exhausted.
Set this to 0 to disable this feature.
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -37,6 +37,11 @@ esp_err_t esp_psram_extram_add_to_heap_allocator(void);
/**
* @brief Reserve a pool of internal memory for specific DMA/internal allocations
*
* Carves out @p size bytes from the regular internal heaps and registers the
* region as separate heap pool with new priority-based caps: medium priority for
* MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL, and low priority for MALLOC_CAP_DEFAULT.
* malloc() uses the pool only after other internal heaps are exhausted.
*
* @param size Size of reserved pool in bytes
*
* @return
@@ -661,7 +661,7 @@ esp_err_t esp_psram_extram_reserve_dma_pool(size_t size)
return ESP_ERR_NO_MEM;
}
uint32_t caps[] = {0, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL, MALLOC_CAP_8BIT | MALLOC_CAP_32BIT};
uint32_t caps[] = {0, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL, MALLOC_CAP_DEFAULT | MALLOC_CAP_8BIT | MALLOC_CAP_32BIT};
esp_err_t e = heap_caps_add_region_with_caps(caps, (intptr_t)dma_heap, (intptr_t)dma_heap + next_size - 1);
if (e != ESP_OK) {
return e;
@@ -228,6 +228,9 @@ static inline bool esp_core_dump_task_stack_end_is_sane(uint32_t sp)
#endif
#if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
|| esp_ptr_in_rtc_dram_fast((void*) sp)
#endif
#if SOC_MEM_SPM_SUPPORTED
|| esp_ptr_in_spm((void *)sp)
#endif
;
}
@@ -312,7 +315,11 @@ bool esp_core_dump_mem_seg_is_sane(uint32_t addr, uint32_t sz)
|| (esp_ptr_in_rtc_slow((void *)addr) && esp_ptr_in_rtc_slow((void *)(addr + sz - 1)))
|| (esp_ptr_in_rtc_dram_fast((void *)addr) && esp_ptr_in_rtc_dram_fast((void *)(addr + sz - 1)))
|| (esp_ptr_external_ram((void *)addr) && esp_ptr_external_ram((void *)(addr + sz - 1)))
|| (esp_ptr_in_iram((void *)addr) && esp_ptr_in_iram((void *)(addr + sz - 1)));
|| (esp_ptr_in_iram((void *)addr) && esp_ptr_in_iram((void *)(addr + sz - 1)))
#if SOC_MEM_SPM_SUPPORTED
|| (esp_ptr_in_spm((void *)addr) && esp_ptr_in_spm((void *)(addr + sz - 1)))
#endif
;
}
/**
+2 -2
View File
@@ -63,10 +63,10 @@ enum {
*/
const soc_memory_type_desc_t soc_memory_types[SOC_MEMORY_TYPE_NUM] = {
/* Mem Type Name | High Priority Matching | Medium Priority Matching | Low Priority Matching */
[SOC_MEMORY_TYPE_RETENT_MEM] = { "RETENT_RAM", { MALLOC_L2MEM_BASE_CAPS | MALLOC_CAP_RETENTION | MALLOC_CAP_SIMD, 0, 0 }},
[SOC_MEMORY_TYPE_RETENT_MEM] = { "RETENT_RAM", { MALLOC_CAP_RETENTION | MALLOC_CAP_SIMD, MALLOC_L2MEM_BASE_CAPS, 0 }},
[SOC_MEMORY_TYPE_L2MEM] = { "RAM", { MALLOC_L2MEM_BASE_CAPS | MALLOC_CAP_SIMD, 0, 0 }},
[SOC_MEMORY_TYPE_SPIRAM] = { "SPIRAM", { MALLOC_CAP_SPIRAM, 0, ESP32P4_MEM_COMMON_CAPS | MALLOC_CAP_SIMD }},
[SOC_MEMORY_TYPE_SPM] = { "SPM", { MALLOC_CAP_SPM, ESP32P4_MEM_COMMON_CAPS | MALLOC_CAP_INTERNAL, 0 }},
[SOC_MEMORY_TYPE_SPM] = { "SPM", { MALLOC_CAP_SPM, 0, ESP32P4_MEM_COMMON_CAPS | MALLOC_CAP_INTERNAL }},
[SOC_MEMORY_TYPE_RTCRAM] = { "RTCRAM", { MALLOC_CAP_RTCRAM, 0, MALLOC_RTCRAM_BASE_CAPS}},
};
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -65,25 +65,6 @@ TEST_CASE("Malloc/overwrite, then free all available DRAM", "[heap]")
}
#if CONFIG_SPIRAM_USE_MALLOC && (CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL > 1024)
TEST_CASE("Check if reserved DMA pool still can allocate even when malloc()'ed memory is exhausted", "[heap][psram]")
{
char** dmaMem=malloc(sizeof(char*)*512);
assert(dmaMem);
int m=tryAllocMem();
int i=0;
for (i=0; i<512; i++) {
dmaMem[i]=heap_caps_malloc(1024, MALLOC_CAP_DMA);
if (dmaMem[i]==NULL) break;
}
for (int j=0; j<i; j++) free(dmaMem[j]);
free(dmaMem);
tryAllocMemFree();
printf("Could allocate %dK of DMA memory after allocating all of %dK of normal memory.\n", i, m);
TEST_ASSERT(i);
}
#endif
#if CONFIG_SPIRAM
TEST_CASE("Check if default cap allocates in external memory in priority", "[heap][psram]")
{