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)
|
uint8_t len, uint8_t *data)
|
||||||
{
|
{
|
||||||
SPI_TypeDef *spi = config.spi;
|
SPI_TypeDef *spi = config.spi;
|
||||||
while (len--) {
|
uint8_t *wptr = data;
|
||||||
writeb((void *)&spi->DR, *data);
|
uint8_t *end = data + len;
|
||||||
while (!(spi->SR & SPI_SR_RXNE))
|
|
||||||
;
|
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);
|
uint8_t rdata = readb((void *)&spi->DR);
|
||||||
if (receive_data)
|
if (receive_data)
|
||||||
*data = rdata;
|
*data = rdata;
|
||||||
|
|
Loading…
Reference in New Issue