Skip to content

Commit

Permalink
xtensa/esp32s3: Disable psram as task stack
Browse files Browse the repository at this point in the history
  • Loading branch information
cwespressif committed Nov 7, 2023
1 parent f447f9c commit 20e97d5
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 14 deletions.
7 changes: 7 additions & 0 deletions arch/xtensa/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 55 additions & 4 deletions arch/xtensa/include/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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.
*
****************************************************************************/

Expand All @@ -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);
Expand Down
18 changes: 13 additions & 5 deletions arch/xtensa/src/common/xtensa_mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
2 changes: 2 additions & 0 deletions arch/xtensa/src/esp32s3/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
57 changes: 54 additions & 3 deletions arch/xtensa/src/esp32s3/esp32s3_imm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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.
*
****************************************************************************/

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion boards/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 20e97d5

Please sign in to comment.