aboutsummaryrefslogtreecommitdiff
path: root/atmel-samd
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2017-05-12 13:11:30 -0700
committerScott Shawcroft <scott.shawcroft@gmail.com>2017-05-12 13:13:50 -0700
commit6984425f5da415ff232bd93c1b3c3cf10f81c1c2 (patch)
tree22db61929a0a80aea1d816db7bf3d1683d6e6df8 /atmel-samd
parentc138d0f025acd460e40bcff9714ba62b9ab68e8f (diff)
atmel-samd: Correctly wait for the SPI DMA transaction to finish.
Diffstat (limited to 'atmel-samd')
-rw-r--r--atmel-samd/shared_dma.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/atmel-samd/shared_dma.c b/atmel-samd/shared_dma.c
index d7063fb6b..6b6274d89 100644
--- a/atmel-samd/shared_dma.c
+++ b/atmel-samd/shared_dma.c
@@ -106,15 +106,18 @@ enum status_code shared_dma_write(Sercom* sercom, const uint8_t* buffer, uint32_
return status;
}
- // Wait for the transfer to finish.
+ // Wait for the dma transfer to finish.
while (general_dma_tx.job_status == STATUS_BUSY) {}
+ // Wait for the SPI transfer to complete.
+ while (sercom->SPI.INTFLAG.bit.TXC == 0) {}
+
// This transmit will cause the RX buffer overflow but we're OK with that.
- // So, read the garbage data and clear the overflow flag.
- sercom->SPI.DATA.reg;
- sercom->SPI.DATA.reg;
+ // So, read the garbage and clear the overflow flag.
+ while (sercom->SPI.INTFLAG.bit.RXC == 1) {
+ sercom->SPI.DATA.reg;
+ }
sercom->SPI.STATUS.bit.BUFOVF = 1;
- sercom->SPI.DATA.reg;
return general_dma_tx.job_status;
}
@@ -160,5 +163,7 @@ enum status_code shared_dma_read(Sercom* sercom, uint8_t* buffer, uint32_t lengt
// Wait for the transfer to finish.
while (general_dma_rx.job_status == STATUS_BUSY) {}
+
+ while (sercom->SPI.INTFLAG.bit.RXC == 1) {}
return general_dma_rx.job_status;
}