Skip to content

Commit fbb2848

Browse files
gautierg-stnashif
authored andcommitted
drivers: spi: stm32: fix spi rtio with fifo-enable
This commit fixes the SPI RTIO transfers when the fifo-enable property is enabled. Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
1 parent 133da1c commit fbb2848

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

drivers/spi/spi_stm32.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ static void spi_stm32_iodev_msg_start(const struct device *dev, struct spi_confi
648648
const uint8_t *tx_buf, uint8_t *rx_buf, uint32_t buf_len)
649649
{
650650
struct spi_stm32_data *data = dev->data;
651-
uint32_t size = buf_len / (SPI_WORD_SIZE_GET(config->operation) / BITS_PER_BYTE);
651+
uint32_t size = buf_len / bits2bytes(config->operation);
652652

653653
const struct spi_buf current_tx = {.buf = NULL, .len = size};
654654
const struct spi_buf current_rx = {.buf = NULL, .len = size};
@@ -674,6 +674,10 @@ static void spi_stm32_iodev_msg_start(const struct device *dev, struct spi_confi
674674
SPI_TypeDef *spi = cfg->spi;
675675

676676
if (cfg->fifo_enabled && SPI_OP_MODE_GET(config->operation) == SPI_OP_MODE_MASTER) {
677+
if (LL_SPI_IsEnabled(spi)) {
678+
/* SPI needs to be disabled to set the transfer size */
679+
ll_func_disable_spi(spi);
680+
}
677681
LL_SPI_SetTransferSize(spi, size);
678682
}
679683
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi) */
@@ -773,6 +777,12 @@ static void spi_stm32_complete(const struct device *dev, int status)
773777

774778
#ifdef CONFIG_SPI_RTIO
775779
if (data->rtio_ctx->txn_head != NULL) {
780+
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi)
781+
if (cfg->fifo_enabled) {
782+
LL_SPI_ClearFlag_TXTF(spi);
783+
LL_SPI_ClearFlag_OVR(spi);
784+
}
785+
#endif /* DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi) */
776786
spi_stm32_iodev_complete(dev, status);
777787
return;
778788
}

0 commit comments

Comments
 (0)