mirror of https://github.com/Desuuuu/klipper.git
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>
This commit is contained in:
parent
ce35ee45d6
commit
a2c309a2b0
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue