diff --git a/components/heap/port/esp32/memory_layout.c b/components/heap/port/esp32/memory_layout.c index 633df2c091..378273523d 100644 --- a/components/heap/port/esp32/memory_layout.c +++ b/components/heap/port/esp32/memory_layout.c @@ -60,7 +60,7 @@ const soc_memory_type_desc_t soc_memory_types[] = { //Type 15: SPI SRAM data { "SPIRAM", { MALLOC_CAP_SPIRAM|MALLOC_CAP_DEFAULT, 0, MALLOC_CAP_8BIT|MALLOC_CAP_32BIT}, false, false}, //Type 16: RTC Fast RAM - { "RTCRAM", { MALLOC_CAP_8BIT|MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT, MALLOC_CAP_RTCRAM }, false, false}, + { "RTCRAM", { MALLOC_CAP_RTCRAM, MALLOC_CAP_8BIT|MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT }, false, false}, }; const size_t soc_memory_type_count = sizeof(soc_memory_types)/sizeof(soc_memory_type_desc_t); @@ -72,9 +72,6 @@ Because of requirements in the coalescing code which merges adjacent regions, th from low to high start address. */ const soc_memory_region_t soc_memory_regions[] = { -#ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP - { SOC_RTC_DRAM_LOW, 0x2000, 16, 0}, //RTC Fast Memory -#endif #ifdef CONFIG_SPIRAM { SOC_EXTRAM_DATA_LOW, SOC_EXTRAM_DATA_SIZE, 15, 0}, //SPI SRAM, if available #endif @@ -121,6 +118,9 @@ const soc_memory_region_t soc_memory_regions[] = { { 0x4009A000, 0x2000, 2, 0}, //pool 2-5, mmu page 13 { 0x4009C000, 0x2000, 2, 0}, //pool 2-5, mmu page 14 { 0x4009E000, 0x2000, 2, 0}, //pool 2-5, mmu page 15 +#ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP + { SOC_RTC_DRAM_LOW, 0x2000, 16, 0}, //RTC Fast Memory +#endif }; const size_t soc_memory_region_count = sizeof(soc_memory_regions)/sizeof(soc_memory_region_t); diff --git a/components/heap/port/esp32c3/memory_layout.c b/components/heap/port/esp32c3/memory_layout.c index 8dac89f96f..403a102836 100644 --- a/components/heap/port/esp32c3/memory_layout.c +++ b/components/heap/port/esp32c3/memory_layout.c @@ -34,7 +34,7 @@ const soc_memory_type_desc_t soc_memory_types[] = { // Type 3: IRAM { "IRAM", { MALLOC_CAP_EXEC | MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL, 0, 0 }, false, false}, // Type 4: RTCRAM - { "RTCRAM", { MALLOC_CAP_8BIT|MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT, MALLOC_CAP_RTCRAM }, false, false}, + { "RTCRAM", { MALLOC_CAP_RTCRAM, MALLOC_CAP_8BIT | MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL | MALLOC_CAP_32BIT }, false, false}, }; #ifdef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE diff --git a/components/heap/port/esp32h2/memory_layout.c b/components/heap/port/esp32h2/memory_layout.c index abf1efaa09..57fd94f840 100644 --- a/components/heap/port/esp32h2/memory_layout.c +++ b/components/heap/port/esp32h2/memory_layout.c @@ -34,7 +34,7 @@ const soc_memory_type_desc_t soc_memory_types[] = { // Type 3: IRAM { "IRAM", { MALLOC_CAP_EXEC | MALLOC_CAP_32BIT | MALLOC_CAP_INTERNAL, 0, 0 }, false, false}, // Type 4: RTCRAM - { "RTCRAM", { MALLOC_CAP_8BIT|MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT, MALLOC_CAP_RTCRAM }, false, false}, + { "RTCRAM", { MALLOC_CAP_RTCRAM, MALLOC_CAP_8BIT|MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT }, false, false}, }; #ifdef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE diff --git a/components/heap/port/esp32s2/memory_layout.c b/components/heap/port/esp32s2/memory_layout.c index ca318cb13d..3d003e33cf 100644 --- a/components/heap/port/esp32s2/memory_layout.c +++ b/components/heap/port/esp32s2/memory_layout.c @@ -44,7 +44,7 @@ const soc_memory_type_desc_t soc_memory_types[] = { //TODO, in fact, part of them support EDMA, to be supported. { "SPIRAM", { MALLOC_CAP_SPIRAM|MALLOC_CAP_DEFAULT, 0, MALLOC_CAP_8BIT|MALLOC_CAP_32BIT}, false, false}, //Type 5: RTC Fast RAM - { "RTCRAM", { MALLOC_CAP_8BIT|MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT, MALLOC_CAP_RTCRAM }, false, false}, + { "RTCRAM", { MALLOC_CAP_RTCRAM, MALLOC_CAP_8BIT|MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL|MALLOC_CAP_32BIT }, false, false}, }; #ifdef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE @@ -62,9 +62,6 @@ Because of requirements in the coalescing code which merges adjacent regions, th from low to high start address. */ const soc_memory_region_t soc_memory_regions[] = { -#ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP - { SOC_RTC_DRAM_LOW, 0x2000, 5, 0}, //RTC Fast Memory -#endif #ifdef CONFIG_SPIRAM { SOC_EXTRAM_DATA_LOW, SOC_EXTRAM_DATA_SIZE, 4, 0}, //SPI SRAM, if available #endif @@ -106,6 +103,9 @@ const soc_memory_region_t soc_memory_regions[] = { { 0x3FFF4000, 0x4000, SOC_MEMORY_TYPE_DEFAULT, 0x40064000}, //Block 19, can be used for MAC dump, can be used as trace memory { 0x3FFF8000, 0x4000, SOC_MEMORY_TYPE_DEFAULT, 0x40068000}, //Block 20, can be used for MAC dump, can be used as trace memory { 0x3FFFC000, 0x4000, 1, 0x4006C000}, //Block 21, can be used for MAC dump, can be used as trace memory, used for startup stack +#ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP + { SOC_RTC_DRAM_LOW, 0x2000, 5, 0}, //RTC Fast Memory +#endif }; const size_t soc_memory_region_count = sizeof(soc_memory_regions)/sizeof(soc_memory_region_t); diff --git a/components/heap/port/esp32s3/memory_layout.c b/components/heap/port/esp32s3/memory_layout.c index 2f44446a20..bbcde50b67 100644 --- a/components/heap/port/esp32s3/memory_layout.c +++ b/components/heap/port/esp32s3/memory_layout.c @@ -40,7 +40,7 @@ const soc_memory_type_desc_t soc_memory_types[] = { // Type 5: DRAM which is not DMA accesible { "NON_DMA_DRAM", { MALLOC_CAP_8BIT | MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL | MALLOC_CAP_32BIT, 0 }, false, false}, // Type 6: RTC Fast RAM - { "RTCRAM", { MALLOC_CAP_8BIT | MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL | MALLOC_CAP_32BIT, MALLOC_CAP_RTCRAM }, false, false}, + { "RTCRAM", { MALLOC_CAP_RTCRAM, MALLOC_CAP_8BIT | MALLOC_CAP_DEFAULT, MALLOC_CAP_INTERNAL | MALLOC_CAP_32BIT }, false, false}, }; const size_t soc_memory_type_count = sizeof(soc_memory_types) / sizeof(soc_memory_type_desc_t); diff --git a/components/heap/test/test_malloc_caps.c b/components/heap/test/test_malloc_caps.c index fd3dc02286..b78a088847 100644 --- a/components/heap/test/test_malloc_caps.c +++ b/components/heap/test/test_malloc_caps.c @@ -8,6 +8,7 @@ #include "esp_attr.h" #include "esp_heap_caps.h" #include "esp_spi_flash.h" +#include "soc/soc_memory_types.h" #include #include @@ -245,3 +246,25 @@ TEST_CASE("allocation with invalid capability should also trigger the alloc fail (void)ptr; } + +#ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP +/** + * In MR 16031, the priority of RTC memory has been adjusted to the lowest. + * RTC memory will not be consumed a lot during the startup process. + */ +TEST_CASE("RTC memory shoule be lowest priority and its free size should be big enough", "[heap]") +{ + const size_t allocation_size = 1024 * 4; + void *ptr = NULL; + size_t free_size = 0; + + ptr = heap_caps_malloc(allocation_size, MALLOC_CAP_DEFAULT); + TEST_ASSERT_NOT_NULL(ptr); + TEST_ASSERT(!esp_ptr_in_rtc_dram_fast(ptr)); + + free_size = heap_caps_get_free_size(MALLOC_CAP_RTCRAM); + TEST_ASSERT_GREATER_OR_EQUAL(1024 * 4, free_size); + + free(ptr); +} +#endif