Skip to content

Commit bb9fe42

Browse files
aviscontigalak
authored andcommitted
spi: spi_ll_stm32: Fix transceive() ret value in spi_slave case
In SPI slave case the transceive should return either the negative errno code in case of error or the number of frames received. So, now: 1. the spi_stm32_get_err() routine already checks whether the SPI cell got an error and returns -EIO in that case. 2. the transceive() routine always returns whatever the spi_context_wait_for_completion() has returned, which is either: a. -EIO in case of error b. 0 in spi_master ok case c. the number of frames received in spi_slave ok case Signed-off-by: Armando Visconti <[email protected]>
1 parent fa153a0 commit bb9fe42

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

drivers/spi/spi_ll_stm32.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ static int spi_stm32_get_err(SPI_TypeDef *spi)
5252
{
5353
u32_t sr = LL_SPI_ReadReg(spi, SR);
5454

55-
return (int)(sr & SPI_STM32_ERR_MSK);
55+
if (sr & SPI_STM32_ERR_MSK) {
56+
SYS_LOG_ERR("%s: err=%d", __func__,
57+
sr & SPI_STM32_ERR_MSK);
58+
return -EIO;
59+
}
60+
61+
return 0;
5662
}
5763

5864
static inline u16_t spi_stm32_next_tx(struct spi_stm32_data *data)
@@ -410,15 +416,18 @@ static int transceive(struct device *dev,
410416
} while (!ret && spi_stm32_transfer_ongoing(data));
411417

412418
spi_stm32_complete(data, spi, ret);
419+
420+
#ifdef CONFIG_SPI_SLAVE
421+
if (spi_context_is_slave(&data->ctx) && !ret) {
422+
ret = data->ctx.recv_frames;
423+
}
424+
#endif /* CONFIG_SPI_SLAVE */
425+
413426
#endif
414427

415428
spi_context_release(&data->ctx, ret);
416429

417-
if (ret) {
418-
SYS_LOG_ERR("error mask 0x%x", ret);
419-
}
420-
421-
return ret ? -EIO : 0;
430+
return ret;
422431
}
423432

424433
static int spi_stm32_transceive(struct device *dev,

0 commit comments

Comments
 (0)