esp_system: make rtc fast memory to heap configuration unified across chips

Closes IDF-2503
This commit is contained in:
Mahavir Jain 2020-12-21 10:56:00 +05:30
parent 7f98aedd23
commit 880a63b2e9
12 changed files with 32 additions and 55 deletions

View File

@ -769,16 +769,4 @@ menu "ESP32-specific"
This is possible due to handling of exceptions `LoadStoreError (3)` and `LoadStoreAlignmentError (9)` This is possible due to handling of exceptions `LoadStoreError (3)` and `LoadStoreAlignmentError (9)`
Each unaligned read/write access will incur a penalty of maximum of 167 CPU cycles. Each unaligned read/write access will incur a penalty of maximum of 167 CPU cycles.
config ESP32_ALLOW_RTC_FAST_MEM_AS_HEAP
bool "Enable RTC fast memory for dynamic allocations"
default y
depends on FREERTOS_UNICORE
help
This config option allows to add RTC fast memory region to system heap with capability
similar to that of DRAM region but without DMA. This memory will be consumed first per
heap initialization order by early startup services and scheduler related code. Speed
wise RTC fast memory operates on APB clock and hence does not have much performance impact.
RTC fast memory is accessible to PRO cpu only and hence this is allowed for single core
configuration only for ESP32.
endmenu # ESP32-Specific endmenu # ESP32-Specific

View File

@ -206,14 +206,4 @@ menu "ESP32C3-Specific"
If enabled, this disables the linking of binary libraries in the application build. Note If enabled, this disables the linking of binary libraries in the application build. Note
that after enabling this Wi-Fi/Bluetooth will not work. that after enabling this Wi-Fi/Bluetooth will not work.
config ESP32C3_ALLOW_RTC_FAST_MEM_AS_HEAP
bool "Enable RTC fast memory for dynamic allocations"
depends on !ESP32C3_MEMPROT_FEATURE
default y
help
This config option allows to add RTC fast memory region to system heap with capability
similar to that of DRAM region but without DMA. This memory will be consumed first per
heap initialization order by early startup services and scheduler related code. Speed
wise RTC fast memory operates on APB clock and hence does not have much performance impact.
endmenu # ESP32C3-Specific endmenu # ESP32C3-Specific

View File

@ -512,13 +512,4 @@ menu "ESP32S2-specific"
help help
RAM size dedicated for static variables (.data & .bss sections). RAM size dedicated for static variables (.data & .bss sections).
config ESP32S2_ALLOW_RTC_FAST_MEM_AS_HEAP
bool "Enable RTC fast memory for dynamic allocations"
default y
help
This config option allows to add RTC fast memory region to system heap with capability
similar to that of DRAM region but without DMA. This memory will be consumed first per
heap initialization order by early startup services and scheduler related code. Speed
wise RTC fast memory operates on APB clock and hence does not have much performance impact.
endmenu # ESP32S2-Specific endmenu # ESP32S2-Specific

View File

@ -515,14 +515,4 @@ menu "ESP32S3-Specific"
help help
RAM size dedicated for static variables (.data & .bss sections). RAM size dedicated for static variables (.data & .bss sections).
config ESP32S3_ALLOW_RTC_FAST_MEM_AS_HEAP
bool "Enable RTC fast memory for dynamic allocations"
depends on !ESP32S3_MEMPROT_FEATURE
default y
help
This config option allows to add RTC fast memory region to system heap with capability
similar to that of DRAM region but without DMA. This memory will be consumed first per
heap initialization order by early startup services and scheduler related code. Speed
wise RTC fast memory operates on APB clock and hence does not have much performance impact.
endmenu # ESP32S3-Specific endmenu # ESP32S3-Specific

View File

@ -27,3 +27,5 @@ CONFIG_TASK_WDT_TIMEOUT_S CONFIG_ESP_TASK_WDT_TIME
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1
CONFIG_ESP32_DEBUG_STUBS_ENABLE CONFIG_ESP_DEBUG_STUBS_ENABLE CONFIG_ESP32_DEBUG_STUBS_ENABLE CONFIG_ESP_DEBUG_STUBS_ENABLE
CONFIG_ESP32_ALLOW_RTC_FAST_MEM_AS_HEAP CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
CONFIG_ESP32S2_ALLOW_RTC_FAST_MEM_AS_HEAP CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP

View File

@ -62,4 +62,21 @@ menu "ESP System Settings"
To accurately determine if the crystal has started, To accurately determine if the crystal has started,
set a larger "Number of cycles for RTC_SLOW_CLK calibration" (about 3000). set a larger "Number of cycles for RTC_SLOW_CLK calibration" (about 3000).
config ESP_SYSTEM_RTC_FAST_MEM_AS_HEAP_DEPCHECK
bool
default y if IDF_TARGET_ESP32 && FREERTOS_UNICORE
default y if IDF_TARGET_ESP32S2
default y if IDF_TARGET_ESP32C3
default y if IDF_TARGET_ESP32S3
config ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
bool "Enable RTC fast memory for dynamic allocations"
default y
depends on ESP_SYSTEM_RTC_FAST_MEM_AS_HEAP_DEPCHECK
help
This config option allows to add RTC fast memory region to system heap with capability
similar to that of DRAM region but without DMA. This memory will be consumed first per
heap initialization order by early startup services and scheduler related code. Speed
wise RTC fast memory operates on APB clock and hence does not have much performance impact.
endmenu # ESP System Settings endmenu # ESP System Settings

View File

@ -275,10 +275,10 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags)
// For deep sleep, wait for the contents of UART FIFO to be sent. // For deep sleep, wait for the contents of UART FIFO to be sent.
bool deep_sleep = pd_flags & RTC_SLEEP_PD_DIG; bool deep_sleep = pd_flags & RTC_SLEEP_PD_DIG;
#if !CONFIG_FREERTOS_UNICORE && ESP32S3_ALLOW_RTC_FAST_MEM_AS_HEAP #if !CONFIG_FREERTOS_UNICORE && CONFIG_IDF_TARGET_ESP32S3 && CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
/* Currently only safe to use deep sleep wake stub & RTC memory as heap in single core mode. /* Currently only safe to use deep sleep wake stub & RTC memory as heap in single core mode.
For ESP32-S3, either disable ESP32S3_ALLOW_RTC_FAST_MEM_AS_HEAP in config or find a way to set the For ESP32-S3, either disable ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP in config or find a way to set the
deep sleep wake stub to NULL. deep sleep wake stub to NULL.
*/ */
assert(!deep_sleep || esp_get_deep_sleep_wake_stub() == NULL); assert(!deep_sleep || esp_get_deep_sleep_wake_stub() == NULL);
@ -360,7 +360,7 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags)
*/ */
portENTER_CRITICAL(&spinlock_rtc_deep_sleep); portENTER_CRITICAL(&spinlock_rtc_deep_sleep);
#if !CONFIG_ESP32_ALLOW_RTC_FAST_MEM_AS_HEAP && !CONFIG_ESP32S2_ALLOW_RTC_FAST_MEM_AS_HEAP && !CONFIG_ESP32S3_ALLOW_RTC_FAST_MEM_AS_HEAP #if !CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
/* If not possible stack is in RTC FAST memory, use the ROM function to calculate the CRC and save ~140 bytes IRAM */ /* If not possible stack is in RTC FAST memory, use the ROM function to calculate the CRC and save ~140 bytes IRAM */
set_rtc_memory_crc(); set_rtc_memory_crc();
result = call_rtc_sleep_start(reject_triggers); result = call_rtc_sleep_start(reject_triggers);
@ -869,7 +869,7 @@ static uint32_t get_power_down_flags(void)
} }
#endif #endif
#if !CONFIG_ESP32_ALLOW_RTC_FAST_MEM_AS_HEAP && !CONFIG_ESP32S2_ALLOW_RTC_FAST_MEM_AS_HEAP && !CONFIG_ESP32S3_ALLOW_RTC_FAST_MEM_AS_HEAP #if !CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
/* RTC_FAST_MEM is needed for deep sleep stub. /* RTC_FAST_MEM is needed for deep sleep stub.
If RTC_FAST_MEM is Auto, keep it powered on, so that deep sleep stub can run. If RTC_FAST_MEM is Auto, keep it powered on, so that deep sleep stub can run.
In the new chip revision, deep sleep stub will be optional, and this can be changed. */ In the new chip revision, deep sleep stub will be optional, and this can be changed. */

View File

@ -289,8 +289,7 @@ TEST_CASE_MULTIPLE_STAGES("can set sleep wake stub", "[deepsleep][reset=DEEPSLEE
check_wake_stub); check_wake_stub);
#if CONFIG_ESP32_ALLOW_RTC_FAST_MEM_AS_HEAP || CONFIG_ESP32S2_ALLOW_RTC_FAST_MEM_AS_HEAP \ #if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
|| CONFIG_ESP32S3_ALLOW_RTC_FAST_MEM_AS_HEAP
#if CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION #if CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION
/* Version of prepare_wake_stub() that sets up the deep sleep call while running /* Version of prepare_wake_stub() that sets up the deep sleep call while running
@ -348,7 +347,7 @@ TEST_CASE_MULTIPLE_STAGES("can set sleep wake stub from stack in RTC RAM", "[dee
check_wake_stub); check_wake_stub);
#endif // CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION #endif // CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION
#endif // CONFIG_xyz_ALLOW_RTC_FAST_MEM_AS_HEAP #endif // CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
TEST_CASE("wake up using ext0 (13 high)", "[deepsleep][ignore]") TEST_CASE("wake up using ext0 (13 high)", "[deepsleep][ignore]")
{ {

View File

@ -81,7 +81,7 @@ Because of requirements in the coalescing code which merges adjacent regions, th
from low to high start address. from low to high start address.
*/ */
const soc_memory_region_t soc_memory_regions[] = { const soc_memory_region_t soc_memory_regions[] = {
#ifdef CONFIG_ESP32_ALLOW_RTC_FAST_MEM_AS_HEAP #ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
{ SOC_RTC_DRAM_LOW, 0x2000, 16, 0}, //RTC Fast Memory { SOC_RTC_DRAM_LOW, 0x2000, 16, 0}, //RTC Fast Memory
#endif #endif
#ifdef CONFIG_SPIRAM #ifdef CONFIG_SPIRAM
@ -190,7 +190,7 @@ SOC_RESERVE_MEMORY_REGION((intptr_t)&_data_start, (intptr_t)&_heap_start, dram_d
SOC_RESERVE_MEMORY_REGION((intptr_t)&_iram_start, (intptr_t)&_iram_end, iram_code); SOC_RESERVE_MEMORY_REGION((intptr_t)&_iram_start, (intptr_t)&_iram_end, iram_code);
// RTC Fast RAM region // RTC Fast RAM region
#ifdef CONFIG_ESP32_ALLOW_RTC_FAST_MEM_AS_HEAP #ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
#ifdef CONFIG_ESP32_RTCDATA_IN_FAST_MEM #ifdef CONFIG_ESP32_RTCDATA_IN_FAST_MEM
SOC_RESERVE_MEMORY_REGION(SOC_RTC_DRAM_LOW, (intptr_t)&_rtc_noinit_end, rtcram_data); SOC_RESERVE_MEMORY_REGION(SOC_RTC_DRAM_LOW, (intptr_t)&_rtc_noinit_end, rtcram_data);
#else #else

View File

@ -64,7 +64,7 @@ const soc_memory_region_t soc_memory_regions[] = {
{ 0x3FC80000, 0x20000, SOC_MEMORY_TYPE_DEFAULT, 0x40380000}, //Block 4, can be remapped to ROM, can be used as trace memory { 0x3FC80000, 0x20000, SOC_MEMORY_TYPE_DEFAULT, 0x40380000}, //Block 4, can be remapped to ROM, can be used as trace memory
{ 0x3FCA0000, 0x20000, SOC_MEMORY_TYPE_DEFAULT, 0x403A0000}, //Block 5, can be remapped to ROM, can be used as trace memory { 0x3FCA0000, 0x20000, SOC_MEMORY_TYPE_DEFAULT, 0x403A0000}, //Block 5, can be remapped to ROM, can be used as trace memory
{ 0x3FCC0000, 0x20000, 1, 0x403C0000}, //Block 9, can be used as trace memory { 0x3FCC0000, 0x20000, 1, 0x403C0000}, //Block 9, can be used as trace memory
#ifdef CONFIG_ESP32C3_ALLOW_RTC_FAST_MEM_AS_HEAP #ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
{ 0x50000000, 0x2000, 4, 0}, //Fast RTC memory { 0x50000000, 0x2000, 4, 0}, //Fast RTC memory
#endif #endif
}; };

View File

@ -70,7 +70,7 @@ Because of requirements in the coalescing code which merges adjacent regions, th
from low to high start address. from low to high start address.
*/ */
const soc_memory_region_t soc_memory_regions[] = { const soc_memory_region_t soc_memory_regions[] = {
#ifdef CONFIG_ESP32S2_ALLOW_RTC_FAST_MEM_AS_HEAP #ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
{ SOC_RTC_DRAM_LOW, 0x2000, 5, 0}, //RTC Fast Memory { SOC_RTC_DRAM_LOW, 0x2000, 5, 0}, //RTC Fast Memory
#endif #endif
#ifdef CONFIG_SPIRAM #ifdef CONFIG_SPIRAM
@ -149,7 +149,7 @@ SOC_RESERVE_MEMORY_REGION(0x3fffc000 - CONFIG_ESP32S2_TRACEMEM_RESERVE_DRAM, 0x3
#endif #endif
// RTC Fast RAM region // RTC Fast RAM region
#ifdef CONFIG_ESP32S2_ALLOW_RTC_FAST_MEM_AS_HEAP #ifdef CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
#ifdef CONFIG_ESP32S2_RTCDATA_IN_FAST_MEM #ifdef CONFIG_ESP32S2_RTCDATA_IN_FAST_MEM
SOC_RESERVE_MEMORY_REGION(SOC_RTC_DRAM_LOW, (intptr_t)&_rtc_noinit_end, rtcram_data); SOC_RESERVE_MEMORY_REGION(SOC_RTC_DRAM_LOW, (intptr_t)&_rtc_noinit_end, rtcram_data);
#else #else

View File

@ -177,7 +177,7 @@ inline static bool IRAM_ATTR esp_ptr_byte_accessible(const void *p)
intptr_t ip = (intptr_t) p; intptr_t ip = (intptr_t) p;
bool r; bool r;
r = (ip >= SOC_BYTE_ACCESSIBLE_LOW && ip < SOC_BYTE_ACCESSIBLE_HIGH); r = (ip >= SOC_BYTE_ACCESSIBLE_LOW && ip < SOC_BYTE_ACCESSIBLE_HIGH);
#if CONFIG_ESP32_ALLOW_RTC_FAST_MEM_AS_HEAP #if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
/* For ESP32 case, RTC fast memory is accessible to PRO cpu only and hence /* For ESP32 case, RTC fast memory is accessible to PRO cpu only and hence
* for single core configuration (where it gets added to system heap) following * for single core configuration (where it gets added to system heap) following
* additional check is required */ * additional check is required */
@ -197,7 +197,7 @@ inline static bool IRAM_ATTR esp_ptr_internal(const void *p) {
bool r; bool r;
r = ((intptr_t)p >= SOC_MEM_INTERNAL_LOW && (intptr_t)p < SOC_MEM_INTERNAL_HIGH); r = ((intptr_t)p >= SOC_MEM_INTERNAL_LOW && (intptr_t)p < SOC_MEM_INTERNAL_HIGH);
r |= ((intptr_t)p >= SOC_RTC_DATA_LOW && (intptr_t)p < SOC_RTC_DATA_HIGH); r |= ((intptr_t)p >= SOC_RTC_DATA_LOW && (intptr_t)p < SOC_RTC_DATA_HIGH);
#if CONFIG_ESP32_ALLOW_RTC_FAST_MEM_AS_HEAP #if CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
/* For ESP32 case, RTC fast memory is accessible to PRO cpu only and hence /* For ESP32 case, RTC fast memory is accessible to PRO cpu only and hence
* for single core configuration (where it gets added to system heap) following * for single core configuration (where it gets added to system heap) following
* additional check is required */ * additional check is required */