Skip to content

Commit 6984425

Browse files
committed
atmel-samd: Correctly wait for the SPI DMA transaction to finish.
1 parent c138d0f commit 6984425

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

atmel-samd/shared_dma.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,18 @@ enum status_code shared_dma_write(Sercom* sercom, const uint8_t* buffer, uint32_
106106
return status;
107107
}
108108

109-
// Wait for the transfer to finish.
109+
// Wait for the dma transfer to finish.
110110
while (general_dma_tx.job_status == STATUS_BUSY) {}
111111

112+
// Wait for the SPI transfer to complete.
113+
while (sercom->SPI.INTFLAG.bit.TXC == 0) {}
114+
112115
// This transmit will cause the RX buffer overflow but we're OK with that.
113-
// So, read the garbage data and clear the overflow flag.
114-
sercom->SPI.DATA.reg;
115-
sercom->SPI.DATA.reg;
116+
// So, read the garbage and clear the overflow flag.
117+
while (sercom->SPI.INTFLAG.bit.RXC == 1) {
118+
sercom->SPI.DATA.reg;
119+
}
116120
sercom->SPI.STATUS.bit.BUFOVF = 1;
117-
sercom->SPI.DATA.reg;
118121

119122
return general_dma_tx.job_status;
120123
}
@@ -160,5 +163,7 @@ enum status_code shared_dma_read(Sercom* sercom, uint8_t* buffer, uint32_t lengt
160163

161164
// Wait for the transfer to finish.
162165
while (general_dma_rx.job_status == STATUS_BUSY) {}
166+
167+
while (sercom->SPI.INTFLAG.bit.RXC == 1) {}
163168
return general_dma_rx.job_status;
164169
}

0 commit comments

Comments
 (0)