diff --git a/components/esp32s2/Kconfig b/components/esp32s2/Kconfig index c9e4b6017d..a02de1306b 100644 --- a/components/esp32s2/Kconfig +++ b/components/esp32s2/Kconfig @@ -505,6 +505,25 @@ menu "ESP32S2-specific" This option allows to place .rtc_data and .rtc_rodata sections into RTC fast memory segment to free the slow memory region for ULP programs. + config ESP32S2_USE_FIXED_STATIC_RAM_SIZE + bool "Use fixed static RAM size" + default n + help + If this option is disabled, the DRAM part of the heap starts right after the .bss section, + within the dram0_0 region. As a result, adding or removing some static variables + will change the available heap size. + + If this option is enabled, the DRAM part of the heap starts right after the dram0_0 region, + where its length is set with ESP32S2_FIXED_STATIC_RAM_SIZE + + config ESP32S2_FIXED_STATIC_RAM_SIZE + hex "Fixed Static RAM size" + default 0x10000 + range 0 0x34000 + depends on ESP32S2_USE_FIXED_STATIC_RAM_SIZE + help + 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" depends on !ESP32S2_MEMPROT_FEATURE diff --git a/components/esp32s2/ld/esp32s2.ld b/components/esp32s2/ld/esp32s2.ld index 87f4c9bae6..08e4987463 100644 --- a/components/esp32s2/ld/esp32s2.ld +++ b/components/esp32s2/ld/esp32s2.ld @@ -44,6 +44,17 @@ #define I_D_RAM_SIZE DATA_RAM_END - DRAM_ORG +#if defined(CONFIG_ESP32S2_USE_FIXED_STATIC_RAM_SIZE) + +ASSERT((CONFIG_ESP32S2_FIXED_STATIC_RAM_SIZE <= I_D_RAM_SIZE), + "Fixed static ram data does not fit.") + +#define STATIC_RAM_SIZE CONFIG_ESP32S2_FIXED_STATIC_RAM_SIZE + +#else +#define STATIC_RAM_SIZE 0 +#endif + MEMORY { /* All these values assume the flash cache is on, and have the blocks this uses subtracted from the length @@ -69,7 +80,7 @@ MEMORY /* Shared data RAM, excluding memory reserved for bootloader and ROM bss/data/stack. */ - dram0_0_seg (RW) : org = DRAM_ORG, len = I_D_RAM_SIZE + dram0_0_seg (RW) : org = DRAM_ORG, len = I_D_RAM_SIZE - STATIC_RAM_SIZE #ifdef CONFIG_APP_BUILD_USE_FLASH_SECTIONS /* Flash mapped constant data */ @@ -93,7 +104,12 @@ MEMORY rtc_data_seg(RW) : org = 0x3ff9e000, len = 0x2000 - ESP_BOOTLOADER_RESERVE_RTC } +#if defined(CONFIG_ESP32S2_USE_FIXED_STATIC_RAM_SIZE) +/* static data ends at defined address */ +_static_data_end = DRAM_ORG + STATIC_RAM_SIZE; +#else _static_data_end = _bss_end; +#endif _heap_end = 0x40000000; diff --git a/components/esp32s2/ld/esp32s2.project.ld.in b/components/esp32s2/ld/esp32s2.project.ld.in index cffa42e9c4..45a299e081 100644 --- a/components/esp32s2/ld/esp32s2.project.ld.in +++ b/components/esp32s2/ld/esp32s2.project.ld.in @@ -265,8 +265,6 @@ SECTIONS . = ALIGN (8); _bss_end = ABSOLUTE(.); - /* The heap starts right after end of this section */ - _heap_start = ABSOLUTE(.); } > dram0_0_seg /* When modifying the alignment, update tls_section_alignment in pxPortInitialiseStack */