Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 54 additions & 23 deletions arch/xtensa/src/esp32/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,6 @@ config ESP32_RUN_IRAM
This loads all of NuttX inside IRAM. Used to test somewhat small
images that can fit entirely in IRAM.

config ESP32_RTC_HEAP
bool "Use the RTC memory as a separate heap"
select ARCH_HAVE_EXTRA_HEAPS
default n

config ESP32_IRAM_HEAP
bool "Use the rest of IRAM as a separate heap"
select ARCH_HAVE_EXTRA_HEAPS
default n

menu "ESP32 Peripheral Selection"

config ESP32_UART
Expand Down Expand Up @@ -579,10 +569,9 @@ config ESP32_SPI3
select SPI

config ESP32_SPIRAM
bool "SPI RAM Support"
bool "SPI RAM"
default n
select ARCH_HAVE_HEAP2 if !ESP32_USER_DATA_EXTMEM
select XTENSA_IMEM_USE_SEPARATE_HEAP
select ARCH_HAVE_HEAP2

if ESP32_SPIRAM && SMP

Expand Down Expand Up @@ -764,6 +753,41 @@ config ESP32_ULP_COPROC_RESERVE_MEM
int "Reserved ULP co-processor DRAM"
default 0

comment "Additional Heaps"

choice ESP32_SPIRAM_HEAP
prompt "SPI RAM heap function"
default ESP32_SPIRAM_COMMON_HEAP if BUILD_FLAT
default ESP32_SPIRAM_USER_HEAP if BUILD_PROTECTED
depends on ESP32_SPIRAM
---help---
Select how the SPI RAM will be used as heap.

config ESP32_SPIRAM_COMMON_HEAP
bool "Additional region to kernel heap"

config ESP32_SPIRAM_USER_HEAP
bool "Separated userspace heap"
select MM_KERNEL_HEAP
select ESP32_USER_DATA_EXTMEM if BUILD_PROTECTED

endchoice

config ESP32_IMM_HEAP
bool "Reserve part of DRAM as a separate heap"
select XTENSA_IMEM_USE_SEPARATE_HEAP
default n

config ESP32_RTC_HEAP
bool "Use the RTC memory as a separate heap"
select ARCH_HAVE_EXTRA_HEAPS
default n

config ESP32_IRAM_HEAP
bool "Use the rest of IRAM as a separate heap"
select ARCH_HAVE_EXTRA_HEAPS
default n

endmenu # Memory Configuration

config ESP32_GPIO_IRQ
Expand All @@ -772,7 +796,7 @@ config ESP32_GPIO_IRQ
---help---
Enable support for interrupting GPIO pins

menu "UART configuration"
menu "UART Configuration"
depends on ESP32_UART

if ESP32_UART0
Expand Down Expand Up @@ -829,6 +853,7 @@ config ESP32_UART0_TXDMA
bool "Enable UART0 TX DMA"
select ARCH_DMA
select UART0_TXDMA
select ESP32_IMM_HEAP if ESP32_SPIRAM
depends on EXPERIMENTAL
---help---
Due to a hardware bug on the DMA used by the UART
Expand Down Expand Up @@ -895,6 +920,7 @@ config ESP32_UART1_TXDMA
bool "Enable UART1 TX DMA"
select ARCH_DMA
select UART1_TXDMA
select ESP32_IMM_HEAP if ESP32_SPIRAM
depends on EXPERIMENTAL
---help---
Due to a hardware bug on the DMA used by the UART
Expand Down Expand Up @@ -961,6 +987,7 @@ config ESP32_UART2_TXDMA
bool "Enable UART2 TX DMA"
select ARCH_DMA
select UART2_TXDMA
select ESP32_IMM_HEAP if ESP32_SPIRAM
depends on EXPERIMENTAL
---help---
Due to a hardware bug on the DMA used by the UART
Expand Down Expand Up @@ -1000,7 +1027,7 @@ config UART_DMADESC_NUM

endmenu # UART configuration

menu "I2C configuration"
menu "I2C Configuration"
depends on ESP32_I2C

if ESP32_I2C0
Expand Down Expand Up @@ -1093,7 +1120,7 @@ config ESP32_TWAI_REGDEBUG

endmenu #ESP32_TWAI

menu "SPI configuration"
menu "SPI Configuration"
depends on ESP32_SPI

config ESP32_SPI_SWCS
Expand All @@ -1112,11 +1139,15 @@ config ESP32_SPI_UDCS
config ESP32_SPI2_DMA
bool "SPI2 use DMA"
default y
select ARCH_DMA
select ESP32_IMM_HEAP if ESP32_SPIRAM
depends on ESP32_SPI2

config ESP32_SPI3_DMA
bool "SPI3 use DMA"
default y
select ARCH_DMA
select ESP32_IMM_HEAP if ESP32_SPIRAM
depends on ESP32_SPI3

config SPI_DMADESC_NUM
Expand Down Expand Up @@ -1657,7 +1688,7 @@ endif # ESP32_PCNT_U7

endmenu # ESP32_PCNT

menu "SPI Flash configuration"
menu "SPI Flash Configuration"

choice ESP32_FLASH_MODE
prompt "SPI Flash mode"
Expand Down Expand Up @@ -1745,7 +1776,7 @@ endif

if ESP32_SPIFLASH

comment "General storage MTD configuration"
comment "General storage MTD Configuration"

config ESP32_STORAGE_MTD_ENCRYPT
bool "Encrypt Storage MTD partition"
Expand Down Expand Up @@ -1775,7 +1806,7 @@ config ESP32_SPIFLASH_DEBUG

if ESP32_APP_FORMAT_LEGACY

comment "Partition Table configuration"
comment "Partition Table Configuration"

config ESP32_PARTITION_TABLE
bool "Create MTD partitions from Partition Table"
Expand All @@ -1794,7 +1825,7 @@ endif # ESP32_SPIFLASH

endmenu # SPI Flash configuration

menu "SPI RAM Config"
menu "SPI RAM Configuration"
depends on ESP32_SPIRAM

choice ESP32_SPIRAM_TYPE
Expand Down Expand Up @@ -1899,7 +1930,7 @@ config SPIRAM_BANKSWITCH_RESERVE

endmenu #SPI RAM Config

menu "Ethernet configuration"
menu "Ethernet Configuration"
depends on ESP32_EMAC

config ESP32_ETH_NRXDESC
Expand Down Expand Up @@ -1938,7 +1969,7 @@ config ESP32_ETH_PHY_ADDR

endmenu # ESP32_EMAC

menu "Wi-Fi configuration"
menu "Wi-Fi Configuration"
depends on ESP32_WIFI

choice
Expand Down Expand Up @@ -2192,7 +2223,7 @@ config ESP32_RTC_CLK_SRC_INT_8MD256
endchoice
endmenu # "RTC Configuration"

menu "LEDC configuration"
menu "LEDC Configuration"
depends on ESP32_LEDC

menuconfig ESP32_LEDC_TIM0
Expand Down
105 changes: 74 additions & 31 deletions arch/xtensa/src/esp32/esp32_allocateheap.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@
#endif
#include <arch/esp32/memory_layout.h>

#ifdef CONFIG_ESP32_SPIRAM_BANKSWITCH_ENABLE
#include <nuttx/himem/himem.h>
#include "xtensa.h"
#ifdef CONFIG_ESP32_SPIRAM
#include "esp32_himem.h"
#endif

#include "xtensa.h"

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#ifdef CONFIG_BUILD_PROTECTED
#ifdef CONFIG_MM_KERNEL_HEAP
# if defined(CONFIG_ESP32_SPIRAM) && defined(CONFIG_ARCH_HAVE_HEAP2)
# define MM_USER_HEAP_EXTRAM
# else
# define MM_USER_HEAP_IRAM
# endif

# define MM_ADDREGION kmm_addregion
#else
# define MM_ADDREGION umm_addregion
Expand All @@ -76,32 +80,56 @@

void up_allocate_heap(void **heap_start, size_t *heap_size)
{
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP)
uintptr_t ubase = USERSPACE->us_dataend;
uintptr_t utop = USERSPACE->us_heapend;
size_t usize = utop - ubase;
uintptr_t ubase;
uintptr_t utop;
size_t usize;

#if defined(CONFIG_ESP32_USER_DATA_EXTMEM) && \
defined(CONFIG_ESP32_SPIRAM_BANKSWITCH_ENABLE)
#ifdef CONFIG_MM_KERNEL_HEAP
# ifdef CONFIG_BUILD_PROTECTED
ubase = USERSPACE->us_dataend;
utop = USERSPACE->us_heapend;
usize = utop - ubase;
# ifdef CONFIG_ESP32_USER_DATA_EXTMEM
usize -= esp_himem_reserved_area_size();
#endif
# endif

# elif defined(CONFIG_BUILD_FLAT)
# ifdef MM_USER_HEAP_EXTRAM
# ifdef CONFIG_XTENSA_EXTMEM_BSS
ubase = (uintptr_t)_ebss_extmem;
usize = CONFIG_HEAP2_SIZE - (size_t)(_ebss_extmem - _sbss_extmem);
# else
ubase = CONFIG_HEAP2_BASE;
usize = CONFIG_HEAP2_SIZE;
# endif
usize -= esp_himem_reserved_area_size();
utop = ubase + usize;

# elif defined(MM_USER_HEAP_IRAM)
ubase = ESP32_IMEM_START + XTENSA_IMEM_REGION_SIZE;
utop = (uintptr_t)_eheap;
usize = utop - ubase;
# endif /* MM_USER_HEAP_EXTRAM */

# endif /* CONFIG_BUILD_PROTECTED */

#else /* !CONFIG_MM_KERNEL_HEAP */
ubase = (uintptr_t)_sheap;
utop = HEAP_REGION1_END;
usize = utop - ubase;
#endif /* CONFIG_MM_KERNEL_HEAP */

minfo("Heap: start=%" PRIxPTR " end=%" PRIxPTR " size=%zu\n",
ubase, utop, usize);

DEBUGASSERT(utop > ubase);

board_autoled_on(LED_HEAPALLOCATE);

/* Return the userspace heap settings */

*heap_start = (void *)ubase;
*heap_size = usize;
#else
board_autoled_on(LED_HEAPALLOCATE);

*heap_start = (void *)_sheap;
DEBUGASSERT(HEAP_REGION1_END > (uintptr_t)*heap_start);
*heap_size = (size_t)(HEAP_REGION1_END - (uintptr_t)*heap_start);
#endif /* CONFIG_BUILD_PROTECTED && CONFIG_MM_KERNEL_HEAP */
}

/****************************************************************************
Expand All @@ -114,30 +142,44 @@ void up_allocate_heap(void **heap_start, size_t *heap_size)
* userspace heaps (CONFIG_MM_KERNEL_HEAP=y), this function allocates
* (and protects) the kernel space heap.
*
* For Flat build (CONFIG_BUILD_FLAT=y), this function enables a separate
* (although unprotected) heap for the kernel.
*
****************************************************************************/

#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP) && \
defined(__KERNEL__)
#ifdef CONFIG_MM_KERNEL_HEAP
void up_allocate_kheap(void **heap_start, size_t *heap_size)
{
uintptr_t kbase;
uintptr_t ktop;
size_t ksize;

#ifdef CONFIG_BUILD_PROTECTED
/* These values come from the linker scripts (kernel-space.ld and
* protected_memory.ld).
* Check boards/xtensa/esp32.
*/

uintptr_t kbase = (uintptr_t)_sheap;
uintptr_t ktop = KDRAM_0_END;
size_t ksize = ktop - kbase;
kbase = (uintptr_t)_sheap;
ktop = KDRAM_0_END;
ksize = ktop - kbase;
#elif defined(CONFIG_BUILD_FLAT)
kbase = (uintptr_t)_sheap;
ktop = HEAP_REGION1_END;
ksize = ktop - kbase;
#endif

minfo("Heap: start=%" PRIxPTR " end=%" PRIxPTR " size=%zu\n",
kbase, ktop, ksize);

DEBUGASSERT(ktop > kbase);

board_autoled_on(LED_HEAPALLOCATE);

*heap_start = (void *)kbase;
*heap_size = ksize;
}
#endif /* CONFIG_BUILD_PROTECTED && CONFIG_MM_KERNEL_HEAP */
#endif /* CONFIG_MM_KERNEL_HEAP */

/****************************************************************************
* Name: xtensa_add_region
Expand Down Expand Up @@ -168,7 +210,7 @@ void xtensa_add_region(void)
availregions = 2;
#endif

#if defined(CONFIG_ESP32_SPIRAM) && !defined(CONFIG_BUILD_PROTECTED)
#ifdef CONFIG_ESP32_SPIRAM_COMMON_HEAP
availregions++;
#endif

Expand All @@ -184,31 +226,32 @@ void xtensa_add_region(void)
MM_ADDREGION(start, size);
#endif

#ifndef MM_USER_HEAP_IRAM
/* Skip internal heap region if CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP is
* enabled.
*/

start = (void *)ESP32_IMEM_START + XTENSA_IMEM_REGION_SIZE;
size = (size_t)(uintptr_t)_eheap - (size_t)start;
MM_ADDREGION(start, size);
#endif

#ifndef CONFIG_ESP32_BLE
start = (void *)HEAP_REGION0_START;
size = (size_t)(HEAP_REGION0_END - HEAP_REGION0_START);
MM_ADDREGION(start, size);
#endif

#if defined(CONFIG_ESP32_SPIRAM) && defined(CONFIG_ARCH_HAVE_HEAP2)
#ifdef CONFIG_ESP32_SPIRAM_COMMON_HEAP
#ifdef CONFIG_XTENSA_EXTMEM_BSS
start = (void *)(_ebss_extmem);
size = CONFIG_HEAP2_SIZE - (size_t)(_ebss_extmem - _sbss_extmem);
size = CONFIG_HEAP2_SIZE - (size_t)(_ebss_extmem - _sbss_extmem);
#else
start = (void *)CONFIG_HEAP2_BASE;
size = CONFIG_HEAP2_SIZE;
size = CONFIG_HEAP2_SIZE;
#endif
#ifdef CONFIG_ESP32_SPIRAM_BANKSWITCH_ENABLE
size -= esp_himem_reserved_area_size();
#endif

MM_ADDREGION(start, size);
#endif
}
Expand Down
Loading