Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xtensa/esp32: ESP32 not use IMEM in user heap mode #9020

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions arch/xtensa/src/esp32/Kconfig
Expand Up @@ -787,6 +787,7 @@ config ESP32_IMM_HEAP
bool "Reserve part of DRAM as a separate heap"
select XTENSA_IMEM_USE_SEPARATE_HEAP
default n
depends on ESP32_SPIRAM_COMMON_HEAP

config ESP32_RTC_HEAP
bool "Use the RTC memory as a separate heap"
Expand Down Expand Up @@ -869,7 +870,7 @@ config ESP32_UART0_TXDMA
bool "Enable UART0 TX DMA"
select ARCH_DMA
select UART0_TXDMA
select ESP32_IMM_HEAP if ESP32_SPIRAM
select ESP32_IMM_HEAP if ESP32_SPIRAM_COMMON_HEAP
depends on EXPERIMENTAL
---help---
Due to a hardware bug on the DMA used by the UART
Expand Down Expand Up @@ -936,7 +937,7 @@ config ESP32_UART1_TXDMA
bool "Enable UART1 TX DMA"
select ARCH_DMA
select UART1_TXDMA
select ESP32_IMM_HEAP if ESP32_SPIRAM
select ESP32_IMM_HEAP if ESP32_SPIRAM_COMMON_HEAP
depends on EXPERIMENTAL
---help---
Due to a hardware bug on the DMA used by the UART
Expand Down Expand Up @@ -1003,7 +1004,7 @@ config ESP32_UART2_TXDMA
bool "Enable UART2 TX DMA"
select ARCH_DMA
select UART2_TXDMA
select ESP32_IMM_HEAP if ESP32_SPIRAM
select ESP32_IMM_HEAP if ESP32_SPIRAM_COMMON_HEAP
depends on EXPERIMENTAL
---help---
Due to a hardware bug on the DMA used by the UART
Expand Down Expand Up @@ -1156,14 +1157,14 @@ config ESP32_SPI2_DMA
bool "SPI2 use DMA"
default y
select ARCH_DMA
select ESP32_IMM_HEAP if ESP32_SPIRAM
select ESP32_IMM_HEAP if ESP32_SPIRAM_COMMON_HEAP
depends on ESP32_SPI2

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

config SPI_DMADESC_NUM
Expand Down
20 changes: 16 additions & 4 deletions arch/xtensa/src/esp32/esp32_serial.c
Expand Up @@ -639,16 +639,24 @@ static void esp32_dmasend(struct uart_dev_s *dev)
{
struct esp32_dmadesc_s *dmadesc;
uint8_t *tp;
#ifdef CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP
#ifdef CONFIG_ESP32_SPIRAM
uint8_t *alloctp = NULL;
#endif

/* If the buffer comes from PSRAM, allocate a new one from DRAM */
/**
* If the buffer comes from PSRAM, allocate a new one from
* Internal SRAM.
*/

#ifdef CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP
#ifdef CONFIG_ESP32_SPIRAM
if (esp32_ptr_extram(dev->dmatx.buffer))
{
# ifdef CONFIG_MM_KERNEL_HEAP
alloctp = kmm_malloc(dev->dmatx.length);
# elif defined(CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP)
alloctp = xtensa_imm_malloc(dev->dmatx.length);
# endif

DEBUGASSERT(alloctp != NULL);
memcpy(alloctp, dev->dmatx.buffer, dev->dmatx.length);
tp = alloctp;
Expand Down Expand Up @@ -680,10 +688,14 @@ static void esp32_dmasend(struct uart_dev_s *dev)
modifyreg32(UHCI_DMA_OUT_LINK_REG(priv->config->dma_chan),
UHCI_OUTLINK_STOP_M, UHCI_OUTLINK_START_M);

#ifdef CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP
#ifdef CONFIG_ESP32_SPIRAM
if (alloctp != NULL)
{
# ifdef CONFIG_MM_KERNEL_HEAP
kmm_free(alloctp);
# elif defined(CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP)
xtensa_imm_free(alloctp);
# endif
}
#endif
}
Expand Down
34 changes: 26 additions & 8 deletions arch/xtensa/src/esp32/esp32_spi.c
Expand Up @@ -829,9 +829,9 @@ static void esp32_spi_dma_exchange(struct esp32_spi_priv_s *priv,
uint32_t regval;
struct esp32_dmadesc_s *dma_tx_desc;
struct esp32_dmadesc_s *dma_rx_desc;
#ifdef CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP
#ifdef CONFIG_ESP32_SPIRAM
uint8_t *alloctp = NULL;
uint8_t *allocrp;
uint8_t *allocrp = NULL;
#endif

/* Define these constants outside transfer loop to avoid wasting CPU time
Expand All @@ -853,10 +853,15 @@ static void esp32_spi_dma_exchange(struct esp32_spi_priv_s *priv,

/* If the buffer comes from PSRAM, allocate a new one from DRAM */

#ifdef CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP
#ifdef CONFIG_ESP32_SPIRAM
if (esp32_ptr_extram(txbuffer))
{
# ifdef CONFIG_MM_KERNEL_HEAP
alloctp = kmm_malloc(total);
# elif defined(CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP)
alloctp = xtensa_imm_malloc(total);
# endif

DEBUGASSERT(alloctp != NULL);
memcpy(alloctp, txbuffer, total);
tp = alloctp;
Expand All @@ -867,10 +872,15 @@ static void esp32_spi_dma_exchange(struct esp32_spi_priv_s *priv,
tp = (uint8_t *)txbuffer;
}

#ifdef CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP
#ifdef CONFIG_ESP32_SPIRAM
if (esp32_ptr_extram(rxbuffer))
{
# ifdef CONFIG_MM_KERNEL_HEAP
allocrp = kmm_malloc(total);
# elif defined(CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP)
allocrp = xtensa_imm_malloc(total);
# endif

DEBUGASSERT(allocrp != NULL);
rp = allocrp;
}
Expand Down Expand Up @@ -938,18 +948,26 @@ static void esp32_spi_dma_exchange(struct esp32_spi_priv_s *priv,

esp32_spi_reset_regbits(spi_slave_reg, SPI_INT_EN_M);

#ifdef CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP
if (esp32_ptr_extram(rxbuffer))
#ifdef CONFIG_ESP32_SPIRAM
if (allocrp)
{
memcpy(rxbuffer, allocrp, total);
# ifdef CONFIG_MM_KERNEL_HEAP
kmm_free(allocrp);
# elif defined(CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP)
xtensa_imm_free(allocrp);
# endif
}
#endif

#ifdef CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP
if (esp32_ptr_extram(txbuffer))
#ifdef CONFIG_ESP32_SPIRAM
if (alloctp)
{
# ifdef CONFIG_MM_KERNEL_HEAP
kmm_free(alloctp);
# elif defined(CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP)
xtensa_imm_free(alloctp);
# endif
}
#endif
}
Expand Down