diff --git a/arch/xtensa/include/esp32/memory_layout.h b/arch/xtensa/include/esp32/memory_layout.h index edd880ba434..729a613eec8 100644 --- a/arch/xtensa/include/esp32/memory_layout.h +++ b/arch/xtensa/include/esp32/memory_layout.h @@ -96,3 +96,8 @@ # define ESP32_IMEM_START 0x3ffe7e40 #endif +/* Region of unused ROM App data */ + +#define HEAP_REGION_ROMAPP_START 0x3ffe4360 +#define HEAP_REGION_ROMAPP_END 0x3ffe5230 + diff --git a/arch/xtensa/src/esp32/esp32_allocateheap.c b/arch/xtensa/src/esp32/esp32_allocateheap.c index 866e78eef5b..9b9afa36668 100644 --- a/arch/xtensa/src/esp32/esp32_allocateheap.c +++ b/arch/xtensa/src/esp32/esp32_allocateheap.c @@ -96,8 +96,15 @@ void xtensa_add_region(void) { size_t region2_start = HEAP_REGION2_START + XTENSA_IMEM_REGION_SIZE; +#ifndef CONFIG_SMP umm_addregion((FAR void *)region2_start, (size_t)(uintptr_t)&_eheap - region2_start); +#else + umm_addregion((FAR void *)region2_start, + (size_t)HEAP_REGION2_END - region2_start); + umm_addregion((FAR void *)HEAP_REGION3_START, + (size_t)&_eheap - HEAP_REGION3_START); +#endif #if defined(CONFIG_ESP32_SPIRAM) /* Check for any additional memory regions */ diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/smp/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/smp/defconfig index 23eafc67acd..deb67a2a9f3 100644 --- a/boards/xtensa/esp32/esp32-devkitc/configs/smp/defconfig +++ b/boards/xtensa/esp32/esp32-devkitc/configs/smp/defconfig @@ -28,7 +28,7 @@ CONFIG_HAVE_CXXINITIALIZE=y CONFIG_IDLETHREAD_STACKSIZE=3072 CONFIG_INTELHEX_BINARY=y CONFIG_MAX_TASKS=16 -CONFIG_MM_REGIONS=2 +CONFIG_MM_REGIONS=3 CONFIG_NFILE_DESCRIPTORS=8 CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/wapi_smp/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/wapi_smp/defconfig index 27c5f353a35..f40ca647b26 100644 --- a/boards/xtensa/esp32/esp32-devkitc/configs/wapi_smp/defconfig +++ b/boards/xtensa/esp32/esp32-devkitc/configs/wapi_smp/defconfig @@ -41,7 +41,7 @@ CONFIG_HAVE_CXXINITIALIZE=y CONFIG_IDLETHREAD_STACKSIZE=2048 CONFIG_INTELHEX_BINARY=y CONFIG_IOB_NBUFFERS=128 -CONFIG_MM_REGIONS=2 +CONFIG_MM_REGIONS=3 CONFIG_NAME_MAX=48 CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDEVICES=y diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32_boot.c b/boards/xtensa/esp32/esp32-devkitc/src/esp32_boot.c index b3c6f7397c9..740c89c9fbf 100644 --- a/boards/xtensa/esp32/esp32-devkitc/src/esp32_boot.c +++ b/boards/xtensa/esp32/esp32-devkitc/src/esp32_boot.c @@ -27,7 +27,9 @@ #include #include +#include #include +#include #include "esp32-devkitc.h" @@ -78,5 +80,17 @@ void board_late_initialize(void) /* Perform board-specific initialization */ esp32_bringup(); + +#ifdef CONFIG_SMP + /* To avoid corrupting the heap, this region of memory (~3KB) is not + * included until the APP CPU has started. + * So we can't add it with the rest of the regions at xtensa_add_region(), + * that function is called early from up_initialize(). We wait until the + * SMP bringup is complete. + */ + + umm_addregion((FAR void *)HEAP_REGION_ROMAPP_START, + (size_t)(HEAP_REGION_ROMAPP_END - HEAP_REGION_ROMAPP_START)); +#endif } #endif diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_boot.c b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_boot.c index cf964c3a2ae..e173894e03f 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_boot.c +++ b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_boot.c @@ -27,7 +27,9 @@ #include #include +#include #include +#include #include "esp32-ethernet-kit.h" @@ -78,5 +80,17 @@ void board_late_initialize(void) /* Perform board-specific initialization */ esp32_bringup(); + +#ifdef CONFIG_SMP + /* To avoid corrupting the heap, this region of memory (~3KB) is not + * included until the APP CPU has started. + * So we can't add it with the rest of the regions at xtensa_add_region(), + * that function is called early from up_initialize(). We wait until the + * SMP bringup is complete. + */ + + umm_addregion((FAR void *)HEAP_REGION_ROMAPP_START, + (size_t)(HEAP_REGION_ROMAPP_END - HEAP_REGION_ROMAPP_START)); +#endif } #endif diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_boot.c b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_boot.c index bf05463e85b..25f7de63a21 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_boot.c +++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_boot.c @@ -27,7 +27,9 @@ #include #include +#include #include +#include #include "esp32-wrover-kit.h" @@ -83,5 +85,17 @@ void board_late_initialize(void) /* Perform board-specific initialization */ esp32_bringup(); + +#ifdef CONFIG_SMP + /* To avoid corrupting the heap, this region of memory (~3KB) is not + * included until the APP CPU has started. + * So we can't add it with the rest of the regions at xtensa_add_region(), + * that function is called early from up_initialize(). We wait until the + * SMP bringup is complete. + */ + + umm_addregion((FAR void *)HEAP_REGION_ROMAPP_START, + (size_t)(HEAP_REGION_ROMAPP_END - HEAP_REGION_ROMAPP_START)); +#endif } #endif