diff --git a/components/esp32s2beta/Kconfig b/components/esp32s2beta/Kconfig index 2f0b70adb..a032f0be5 100644 --- a/components/esp32s2beta/Kconfig +++ b/components/esp32s2beta/Kconfig @@ -149,10 +149,7 @@ menu "ESP32S2-specific" choice SPIRAM_TYPE prompt "Type of SPI RAM chip in use" - default SPIRAM_TYPE_AUTO - - config SPIRAM_TYPE_AUTO - bool "Auto-detect" + default SPIRAM_TYPE_ESPPSRAM32 config SPIRAM_TYPE_ESPPSRAM32 bool "ESP-PSRAM32 or IS25WP032" @@ -163,7 +160,6 @@ menu "ESP32S2-specific" config SPIRAM_SIZE int - default -1 if SPIRAM_TYPE_AUTO default 4194304 if SPIRAM_TYPE_ESPPSRAM32 default 8388608 if SPIRAM_TYPE_ESPPSRAM64 default 0 diff --git a/components/soc/esp32/soc_memory_layout.c b/components/soc/esp32/soc_memory_layout.c index 3070e86bb..d8ba94d90 100644 --- a/components/soc/esp32/soc_memory_layout.c +++ b/components/soc/esp32/soc_memory_layout.c @@ -68,6 +68,13 @@ const soc_memory_type_desc_t soc_memory_types[] = { const size_t soc_memory_type_count = sizeof(soc_memory_types)/sizeof(soc_memory_type_desc_t); +#if CONFIG_SPIRAM_SIZE == -1 +// Assume we need to reserve 4MB in the auto-detection case +#define RESERVE_SPIRAM_SIZE (4*1024*1024) +#else +#define RESERVE_SPIRAM_SIZE CONFIG_SPIRAM_SIZE +#endif + /* Region descriptors. These describe all regions of memory available, and map them to a type in the above type. @@ -76,7 +83,7 @@ from low to high start address. */ const soc_memory_region_t soc_memory_regions[] = { #ifdef CONFIG_SPIRAM - { SOC_EXTRAM_DATA_LOW, CONFIG_SPIRAM_SIZE, 15, 0}, //SPI SRAM, if available + { SOC_EXTRAM_DATA_LOW, RESERVE_SPIRAM_SIZE, 15, 0}, //SPI SRAM, if available #endif { 0x3FFAE000, 0x2000, 0, 0}, //pool 16 <- used for rom code { 0x3FFB0000, 0x8000, 0, 0}, //pool 15 <- if BT is enabled, used as BT HW shared memory @@ -167,7 +174,7 @@ SOC_RESERVE_MEMORY_REGION(0x3fffc000, 0x40000000, trace_mem); //Reserve trace me #endif #ifdef CONFIG_SPIRAM -SOC_RESERVE_MEMORY_REGION(SOC_EXTRAM_DATA_LOW, SOC_EXTRAM_DATA_LOW + CONFIG_SPIRAM_SIZE, spi_ram); //SPI RAM gets added later if needed, in spiram.c; reserve it for now +SOC_RESERVE_MEMORY_REGION(SOC_EXTRAM_DATA_LOW, SOC_EXTRAM_DATA_LOW + RESERVE_SPIRAM_SIZE, spi_ram); //SPI RAM gets added later if needed, in spiram.c; reserve it for now #endif #endif /* BOOTLOADER_BUILD */ diff --git a/components/soc/include/soc/soc_memory_layout.h b/components/soc/include/soc/soc_memory_layout.h index 3f614a453..75c8c7daa 100644 --- a/components/soc/include/soc/soc_memory_layout.h +++ b/components/soc/include/soc/soc_memory_layout.h @@ -163,9 +163,12 @@ inline static bool IRAM_ATTR esp_ptr_byte_accessible(const void *p) intptr_t ip = (intptr_t) p; bool r; r = (ip >= SOC_BYTE_ACCESSIBLE_LOW && ip < SOC_BYTE_ACCESSIBLE_HIGH); -#if CONFIG_SPIRAM && CONFIG_SPIRAM_SIZE - // ToDo: Use SOC_EXTRAM_DATA_HIGH if CONFIG_SPIRAM_SIZE is -1 (ie max possible SPIRAM size) +#if CONFIG_SPIRAM +#if CONFIG_SPIRAM_SIZE != -1 // Fixed size, can be more accurate r |= (ip >= SOC_EXTRAM_DATA_LOW && ip < (SOC_EXTRAM_DATA_LOW + CONFIG_SPIRAM_SIZE)); +#else + r |= (ip >= SOC_EXTRAM_DATA_LOW && ip < (SOC_EXTRAM_DATA_HIGH)); +#endif #endif return r; }