This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 5239d01dba6f971b4279fe39dc77bed5bf8c9a17
Author: [email protected] <[email protected]>
AuthorDate: Wed Nov 1 16:44:49 2023 +0800

    xtensa/esp32s3: Disable psram as task stack
    
    1. Disable psram as task stack to avoid system blocking.
    2. Add some function comments.
---
 arch/xtensa/Kconfig                                |  7 +++
 arch/xtensa/include/arch.h                         | 59 ++++++++++++++++++++--
 arch/xtensa/include/esp32s3/memory_layout.h        |  4 +-
 arch/xtensa/src/common/xtensa_mm.h                 | 18 +++++--
 arch/xtensa/src/esp32s3/Kconfig                    |  2 +
 arch/xtensa/src/esp32s3/esp32s3_imm.c              | 57 +++++++++++++++++++--
 boards/Kconfig                                     |  2 +-
 .../esp32s3-devkit/configs/psram_usrheap/defconfig |  2 +-
 8 files changed, 135 insertions(+), 16 deletions(-)

diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index e74a095b96..f18939c229 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -255,6 +255,13 @@ config XTENSA_INTBACKTRACE
        ---help---
                Add necessary logic to be able to have a full backtrace from an 
interrupt context.
 
+config XTENSA_USE_SPIRAM_HEAP
+       bool "Enable SPI RAM heap"
+       default n
+       ---help---
+               If enabled, SPIRAM can be selected as the heap, of course, the 
premise is that 
+               the device needs to support SPIRAM.
+
 config XTENSA_IMEM_USE_SEPARATE_HEAP
        bool "Use a separate heap for internal memory"
        select ARCH_HAVE_EXTRA_HEAPS
diff --git a/arch/xtensa/include/arch.h b/arch/xtensa/include/arch.h
index 6230714d06..d8d7923868 100644
--- a/arch/xtensa/include/arch.h
+++ b/arch/xtensa/include/arch.h
@@ -68,6 +68,12 @@ struct mallinfo; /* Forward reference, see malloc.h */
  * Description:
  *   Initialize the internal heap.
  *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   None.
+ *
  ****************************************************************************/
 
 void xtensa_imm_initialize(void);
@@ -78,6 +84,12 @@ void xtensa_imm_initialize(void);
  * Description:
  *   Allocate memory from the internal heap.
  *
+ * Input Parameters:
+ *   size - Size (in bytes) of the memory region to be allocated.
+ *
+ * Return Value:
+ *   Adress of the allocated memory space. NULL, if allocation fails.
+ *
  ****************************************************************************/
 
 void *xtensa_imm_malloc(size_t size);
@@ -89,6 +101,13 @@ void *xtensa_imm_malloc(size_t size);
  *   Calculates the size of the allocation and
  *   allocate memory the internal heap.
  *
+ * Input Parameters:
+ *   n         - Size (in types) of the memory region to be allocated.
+ *   elem_size - Size (in bytes) of the type to be allocated.
+ *
+ * Return Value:
+ *   Adress of the allocated memory space. NULL, if allocation fails.
+ *
  ****************************************************************************/
 
 void *xtensa_imm_calloc(size_t n, size_t elem_size);
@@ -99,6 +118,13 @@ void *xtensa_imm_calloc(size_t n, size_t elem_size);
  * Description:
  *   Reallocate memory from the internal heap.
  *
+ * Input Parameters:
+ *   ptr  - Adress to be reallocate.
+ *   size - Size (in bytes) to be reallocate.
+ *
+ * Return Value:
+ *   Adress of the possibly moved memory space. NULL, if allocation fails.
+ *
  ****************************************************************************/
 
 void *xtensa_imm_realloc(void *ptr, size_t size);
@@ -109,6 +135,12 @@ void *xtensa_imm_realloc(void *ptr, size_t size);
  * Description:
  *   Allocate and zero memory from the internal heap.
  *
+ * Input Parameters:
+ *   size - Size (in bytes) of the memory region to be allocated.
+ *
+ * Return Value:
+ *   Adress of the allocated memory space. NULL, if allocation fails.
+ *
  ****************************************************************************/
 
 void *xtensa_imm_zalloc(size_t size);
@@ -119,6 +151,12 @@ void *xtensa_imm_zalloc(size_t size);
  * Description:
  *   Free memory from the internal heap.
  *
+ * Input Parameters:
+ *   mem - Adress to be freed.
+ *
+ * Returned Value:
+ *   None.
+ *
  ****************************************************************************/
 
 void xtensa_imm_free(void *mem);
@@ -131,9 +169,16 @@ void xtensa_imm_free(void *mem);
  *   within that chunk that meets the alignment request and then frees any
  *   leading or trailing space.
  *
- *   The alignment argument must be a power of two (not checked). 8-byte
+ *   The alignment argument must be a power of two (not checked).  8-byte
  *   alignment is guaranteed by normal malloc calls.
  *
+ * Input Parameters:
+ *   alignment - Requested alignment.
+ *   size - Size (in bytes) of the memory region to be allocated.
+ *
+ * Return Value:
+ *   Adress of the allocated adress. NULL, if allocation fails.
+ *
  ****************************************************************************/
 
 void *xtensa_imm_memalign(size_t alignment, size_t size);
@@ -144,11 +189,11 @@ void *xtensa_imm_memalign(size_t alignment, size_t size);
  * Description:
  *   Check if an address lies in the internal heap.
  *
- * Parameters:
- *   mem - The address to check
+ * Input Parameters:
+ *   mem - The address to check.
  *
  * Return Value:
- *   true if the address is a member of the internal heap. false if not
+ *   True if the address is a member of the internal heap. False if not.
  *
  ****************************************************************************/
 
@@ -161,6 +206,12 @@ bool xtensa_imm_heapmember(void *mem);
  *   mallinfo returns a copy of updated current heap information for the
  *   user heap.
  *
+ * Input Parameters:
+ *   None.
+ *
+ * Return Value:
+ *   info - Where memory information will be copied.
+ *
  ****************************************************************************/
 
 struct mallinfo xtensa_imm_mallinfo(void);
diff --git a/arch/xtensa/include/esp32s3/memory_layout.h 
b/arch/xtensa/include/esp32s3/memory_layout.h
index b5f050ae25..b57bf7ba02 100644
--- a/arch/xtensa/include/esp32s3/memory_layout.h
+++ b/arch/xtensa/include/esp32s3/memory_layout.h
@@ -72,8 +72,8 @@
  */
 
 #ifdef CONFIG_MM_KERNEL_HEAP
-#define HEAP_REGION1_END      0x3fccfff0
-#define HEAP_REGION2_START    0x3fcd0000
+#  define HEAP_REGION1_END      0x3fccfff0
+#  define HEAP_REGION2_START    0x3fcd0000
 #endif
 
 #ifdef CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP
diff --git a/arch/xtensa/src/common/xtensa_mm.h 
b/arch/xtensa/src/common/xtensa_mm.h
index 716bc3c114..75f4ca7919 100644
--- a/arch/xtensa/src/common/xtensa_mm.h
+++ b/arch/xtensa/src/common/xtensa_mm.h
@@ -40,10 +40,18 @@
 #  define UMM_FREE(p)        xtensa_imm_free(p)
 #  define UMM_HEAPMEMEBER(p) xtensa_imm_heapmember(p)
 #else
-#  define UMM_MALLOC(s)      kumm_malloc(s)
-#  define UMM_MEMALIGN(a,s)  kumm_memalign(a,s)
-#  define UMM_FREE(p)        kumm_free(p)
-#  define UMM_HEAPMEMEBER(p) umm_heapmember(p)
-#endif
+#  ifdef CONFIG_XTENSA_USE_SPIRAM_HEAP
+#    define UMM_MALLOC(s)      kmm_malloc(s)
+#    define UMM_MEMALIGN(a,s)  kmm_memalign(a,s)
+#    define UMM_FREE(p)        kmm_free(p)
+#    define UMM_HEAPMEMEBER(p) mm_heapmember(p)
+#  else
+#    define UMM_MALLOC(s)      kumm_malloc(s)
+#    define UMM_MEMALIGN(a,s)  kumm_memalign(a,s)
+#    define UMM_FREE(p)        kumm_free(p)
+#    define UMM_HEAPMEMEBER(p) umm_heapmember(p)
+#  endif /* CONFIG_XTENSA_USE_SPIRAM_HEAP */
+
+#endif  /* CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP */
 
 #endif /* __ARCH_XTENSA_SRC_COMMON_XTENSA_MM_H */
diff --git a/arch/xtensa/src/esp32s3/Kconfig b/arch/xtensa/src/esp32s3/Kconfig
index f1d8276521..aa2fc37ad3 100644
--- a/arch/xtensa/src/esp32s3/Kconfig
+++ b/arch/xtensa/src/esp32s3/Kconfig
@@ -875,10 +875,12 @@ choice ESP32S3_SPIRAM_HEAP
 
 config ESP32S3_SPIRAM_COMMON_HEAP
        bool "Additional region to kernel heap"
+       select XTENSA_USE_SPIRAM_HEAP
 
 config ESP32S3_SPIRAM_USER_HEAP
        bool "Separated userspace heap"
        select MM_KERNEL_HEAP
+       select XTENSA_USE_SPIRAM_HEAP
 
 endchoice # ESP32S3_SPIRAM_HEAP
 
diff --git a/arch/xtensa/src/esp32s3/esp32s3_imm.c 
b/arch/xtensa/src/esp32s3/esp32s3_imm.c
index 0b8f1724ff..e1e432670c 100644
--- a/arch/xtensa/src/esp32s3/esp32s3_imm.c
+++ b/arch/xtensa/src/esp32s3/esp32s3_imm.c
@@ -51,6 +51,12 @@ struct mm_heap_s *g_iheap;
  * Description:
  *   Initialize the internal heap.
  *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   None.
+ *
  ****************************************************************************/
 
 void xtensa_imm_initialize(void)
@@ -69,6 +75,12 @@ void xtensa_imm_initialize(void)
  * Description:
  *   Allocate memory from the internal heap.
  *
+ * Input Parameters:
+ *   size - Size (in bytes) of the memory region to be allocated.
+ *
+ * Return Value:
+ *   Adress of the allocated memory space. NULL, if allocation fails.
+ *
  ****************************************************************************/
 
 void *xtensa_imm_malloc(size_t size)
@@ -83,6 +95,13 @@ void *xtensa_imm_malloc(size_t size)
  *   Calculates the size of the allocation and
  *   allocate memory the internal heap.
  *
+ * Input Parameters:
+ *   n         - Size (in types) of the memory region to be allocated.
+ *   elem_size - Size (in bytes) of the type to be allocated.
+ *
+ * Return Value:
+ *   Adress of the allocated memory space. NULL, if allocation fails.
+ *
  ****************************************************************************/
 
 void *xtensa_imm_calloc(size_t n, size_t elem_size)
@@ -96,6 +115,13 @@ void *xtensa_imm_calloc(size_t n, size_t elem_size)
  * Description:
  *   Reallocate memory from the internal heap.
  *
+ * Input Parameters:
+ *   ptr  - Adress to be reallocate.
+ *   size - Size (in bytes) to be reallocate.
+ *
+ * Return Value:
+ *   Adress of the possibly moved memory space. NULL, if allocation fails.
+ *
  ****************************************************************************/
 
 void *xtensa_imm_realloc(void *ptr, size_t size)
@@ -109,6 +135,12 @@ void *xtensa_imm_realloc(void *ptr, size_t size)
  * Description:
  *   Allocate and zero memory from the internal heap.
  *
+ * Input Parameters:
+ *   size - Size (in bytes) of the memory region to be allocated.
+ *
+ * Return Value:
+ *   Adress of the allocated memory space. NULL, if allocation fails.
+ *
  ****************************************************************************/
 
 void *xtensa_imm_zalloc(size_t size)
@@ -122,6 +154,12 @@ void *xtensa_imm_zalloc(size_t size)
  * Description:
  *   Free memory from the internal heap.
  *
+ * Input Parameters:
+ *   mem - Adress to be freed.
+ *
+ * Returned Value:
+ *   None.
+ *
  ****************************************************************************/
 
 void xtensa_imm_free(void *mem)
@@ -140,6 +178,13 @@ void xtensa_imm_free(void *mem)
  *   The alignment argument must be a power of two (not checked).  8-byte
  *   alignment is guaranteed by normal malloc calls.
  *
+ * Input Parameters:
+ *   alignment - Requested alignment.
+ *   size - Size (in bytes) of the memory region to be allocated.
+ *
+ * Return Value:
+ *   Adress of the allocated adress. NULL, if allocation fails.
+ *
  ****************************************************************************/
 
 void *xtensa_imm_memalign(size_t alignment, size_t size)
@@ -153,11 +198,11 @@ void *xtensa_imm_memalign(size_t alignment, size_t size)
  * Description:
  *   Check if an address lies in the internal heap.
  *
- * Parameters:
- *   mem - The address to check
+ * Input Parameters:
+ *   mem - The address to check.
  *
  * Return Value:
- *   true if the address is a member of the internal heap.  false if not
+ *   True if the address is a member of the internal heap. False if not.
  *
  ****************************************************************************/
 
@@ -173,6 +218,12 @@ bool xtensa_imm_heapmember(void *mem)
  *   mallinfo returns a copy of updated current heap information for the
  *   user heap.
  *
+ * Input Parameters:
+ *   None.
+ *
+ * Return Value:
+ *   info - Where memory information will be copied.
+ *
  ****************************************************************************/
 
 struct mallinfo xtensa_imm_mallinfo(void)
diff --git a/boards/Kconfig b/boards/Kconfig
index d956a3c5c6..ccc24e665e 100644
--- a/boards/Kconfig
+++ b/boards/Kconfig
@@ -423,7 +423,7 @@ config ARCH_BOARD_FRANZININHO_WIFI
 
 config ARCH_BOARD_ESP32S3_DEVKIT
        bool "Espressif ESP32-S3 DevKit"
-       depends on ARCH_CHIP_ESP32S3WROOM1 || ARCH_CHIP_ESP32S3MINI1
+       depends on ARCH_CHIP_ESP32S3WROOM1 || ARCH_CHIP_ESP32S3MINI1 || 
ARCH_CHIP_ESP32S3WROOM2
        select ARCH_HAVE_LEDS
        select ARCH_HAVE_BUTTONS
        select ARCH_HAVE_IRQBUTTONS if ESP32S3_GPIO_IRQ
diff --git 
a/boards/xtensa/esp32s3/esp32s3-devkit/configs/psram_usrheap/defconfig 
b/boards/xtensa/esp32s3/esp32s3-devkit/configs/psram_usrheap/defconfig
index de2e2cb130..47a5f71ce6 100644
--- a/boards/xtensa/esp32s3/esp32s3-devkit/configs/psram_usrheap/defconfig
+++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/psram_usrheap/defconfig
@@ -14,7 +14,7 @@ CONFIG_ARCH_BOARD_COMMON=y
 CONFIG_ARCH_BOARD_ESP32S3_DEVKIT=y
 CONFIG_ARCH_CHIP="esp32s3"
 CONFIG_ARCH_CHIP_ESP32S3=y
-CONFIG_ARCH_CHIP_ESP32S3WROOM1=y
+CONFIG_ARCH_CHIP_ESP32S3WROOM2=y
 CONFIG_ARCH_INTERRUPTSTACK=2048
 CONFIG_ARCH_STACKDUMP=y
 CONFIG_ARCH_XTENSA=y

Reply via email to