diff options
author | Arne Jansen <arne@die-jansens.de> | 2020-01-19 08:42:20 +0000 |
---|---|---|
committer | KevinOConnor <kevin@koconnor.net> | 2020-01-23 11:10:39 -0500 |
commit | a2c309a2b02d16ec15fee5702463621239261266 (patch) | |
tree | c6d3cd7503fe280654605b441ebfe3949800ad2e /src/stm32/spi.c | |
parent | ce35ee45d69a07d9ee6c90c667bb9d2afde8c009 (diff) | |
download | kutter-a2c309a2b02d16ec15fee5702463621239261266.tar.gz kutter-a2c309a2b02d16ec15fee5702463621239261266.tar.xz kutter-a2c309a2b02d16ec15fee5702463621239261266.zip |
stm32: performance improvement for spi on stm32f0
The stm32 has a small queue for spi tx/rx. The current code only uses the
spi with a single byte buffer, effectively waiting for each byte to complete
before starting the next transfer.
This patch changes the structure of spi_transfer() to make use of the queue
and achieve back-to-back transfer of bytes on spi.
Signed-off-by: Arne Jansen <arne@die-jansens.de>
Diffstat (limited to 'src/stm32/spi.c')
-rw-r--r-- | src/stm32/spi.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/stm32/spi.c b/src/stm32/spi.c index 376e11d0..f3d83e83 100644 --- a/src/stm32/spi.c +++ b/src/stm32/spi.c @@ -84,10 +84,14 @@ spi_transfer(struct spi_config config, uint8_t receive_data, uint8_t len, uint8_t *data) { SPI_TypeDef *spi = config.spi; - while (len--) { - writeb((void *)&spi->DR, *data); - while (!(spi->SR & SPI_SR_RXNE)) - ; + uint8_t *wptr = data; + uint8_t *end = data + len; + + while (data < end) { + if (spi->SR & SPI_SR_TXE && wptr < end) + writeb((void *)&spi->DR, *wptr++); + if (!(spi->SR & SPI_SR_RXNE)) + continue; uint8_t rdata = readb((void *)&spi->DR); if (receive_data) *data = rdata; |