From cba44928d27cdddb8835131ba6a84466f5c2ea9c Mon Sep 17 00:00:00 2001 From: Abdelatif Guettouche Date: Mon, 8 Mar 2021 09:59:20 +0100 Subject: [PATCH] arch/xtensa/esp32: Part of the ROM regions in middle of DRAM are not used, retrieve them as heap. Signed-off-by: Abdelatif Guettouche --- arch/xtensa/include/esp32/memory_layout.h | 5 +++++ arch/xtensa/src/esp32/esp32_allocateheap.c | 7 +++++++ .../esp32/esp32-devkitc/configs/smp/defconfig | 2 +- .../esp32/esp32-devkitc/configs/wapi_smp/defconfig | 2 +- boards/xtensa/esp32/esp32-devkitc/src/esp32_boot.c | 14 ++++++++++++++ .../esp32/esp32-ethernet-kit/src/esp32_boot.c | 14 ++++++++++++++ .../xtensa/esp32/esp32-wrover-kit/src/esp32_boot.c | 14 ++++++++++++++ 7 files changed, 56 insertions(+), 2 deletions(-) diff --git a/arch/xtensa/include/esp32/memory_layout.h b/arch/xtensa/include/esp32/memory_layout.h index edd880ba43..729a613eec 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 866e78eef5..9b9afa3666 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 23eafc67ac..deb67a2a9f 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 27c5f353a3..f40ca647b2 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 b3c6f7397c..740c89c9fb 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 cf964c3a2a..e173894e03 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 bf05463e85..25f7de63a2 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