Skip to content

Commit

Permalink
arch/esp32_spi: Add check to see if the TX_FIFO is empty
Browse files Browse the repository at this point in the history
to avoid sending empty data

Signed-off-by: nuttxs <[email protected]>
  • Loading branch information
nuttxs committed Feb 25, 2025
1 parent 38c348b commit 03e8152
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions arch/xtensa/src/esp32/esp32_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ static void esp32_spi_dma_exchange(struct esp32_spi_priv_s *priv,
const uintptr_t spi_miso_dlen_reg = SPI_MISO_DLEN_REG(id);
const uintptr_t spi_user_reg = SPI_USER_REG(id);
const uintptr_t spi_cmd_reg = SPI_CMD_REG(id);
const uintptr_t spi_dma_rstatus = SPI_DMA_RSTATUS_REG(id);

DEBUGASSERT((txbuffer != NULL) || (rxbuffer != NULL));

Expand Down Expand Up @@ -940,6 +941,16 @@ static void esp32_spi_dma_exchange(struct esp32_spi_priv_s *priv,
esp32_spi_reset_regbits(spi_user_reg, SPI_USR_MISO_M);
}

if (priv->config->flags & ESP32_SPI_IO_W)
{
/* Wait until SPI TX FIFO is not empty */

while ((getreg32(spi_dma_rstatus) & SPI_DMA_TX_FIFO_EMPTY) != 0)
{
;
}
}

esp32_spi_set_regbits(spi_cmd_reg, SPI_USR_M);

esp32_spi_sem_waitdone(priv);
Expand Down
2 changes: 2 additions & 0 deletions arch/xtensa/src/esp32/hardware/esp32_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2782,6 +2782,8 @@
#define SPI_DMA_RSTATUS_OFFSET (0x148)
#define SPI_DMA_RSTATUS_REG(i) (REG_SPI_BASE(i) + SPI_DMA_RSTATUS_OFFSET)

#define SPI_DMA_TX_FIFO_EMPTY (BIT(31))

/* SPI_DMA_OUT_STATUS : RO ;bitpos:[31:0] ;default: 32'b0 ; */

/* Description: spi dma read data from memory status. */
Expand Down

0 comments on commit 03e8152

Please sign in to comment.