@@ -262,7 +262,9 @@ void SPIClass::transfer(const void* txbuf, void* rxbuf, size_t count,
262
262
true ); // Increment dest address
263
263
readChannel.setTrigger (getDMAC_ID_RX ());
264
264
readChannel.setAction (DMA_TRIGGER_ACTON_BEAT);
265
- readChannel.setCallback (dmaCallback);
265
+ // Since all RX transfers involve a TX,
266
+ // I don't think this separate callback is necessary.
267
+ // readChannel.setCallback(dmaCallback);
266
268
spiPtr[readChannel.getChannel ()] = this ;
267
269
}
268
270
}
@@ -328,43 +330,29 @@ void SPIClass::transfer(const void* txbuf, void* rxbuf, size_t count,
328
330
}
329
331
330
332
// Issue 'bytesThisPass' bytes...
331
- dma_busy = true ;
332
333
if (rxbuf) {
333
334
// Reading, or reading + writing.
334
- // Set up read descriptor for reading .
335
+ // Set up read descriptor.
335
336
// Src address doesn't change, only dest & count.
336
337
// DMA needs address set to END of buffer, so
337
338
// increment the address now, before the transfer.
338
339
readDescriptor->DSTADDR .reg += bytesThisPass;
339
340
readDescriptor->BTCNT .reg = bytesThisPass;
340
- if (txbuf) {
341
- // Writing and reading simultaneously.
342
- // Set up write descriptor for writing real data.
343
- // Src address and count both change.
344
- // DMA needs address set to END of buffer, so
345
- // increment the address now, before the transfer.
346
- writeDescriptor->SRCADDR .reg += bytesThisPass;
347
- writeDescriptor->BTCNT .reg = bytesThisPass;
348
- } else {
349
- // Reading only.
350
- // Write descriptor was already set up for dummy
351
- // writes outside loop, only BTCNT needs set.
352
- writeDescriptor->SRCADDR .reg = (uint32_t )&dum;
353
- writeDescriptor->BTCNT .reg = bytesThisPass;
354
- }
355
341
// Start the RX job BEFORE the TX job!
356
342
// That's the whole secret sauce to the two-channel transfer.
343
+ // Nothing will actually happen until the write channel job
344
+ // is also started.
357
345
readChannel.startJob ();
358
- } else if (txbuf) {
359
- // Writing only.
360
- // Set up write descriptor for writing real data.
346
+ }
347
+ if (txbuf) {
361
348
// DMA needs address set to END of buffer, so
362
349
// increment the address now, before the transfer.
363
350
writeDescriptor->SRCADDR .reg += bytesThisPass;
364
- writeDescriptor->BTCNT .reg = bytesThisPass;
365
351
}
352
+ writeDescriptor->BTCNT .reg = bytesThisPass;
353
+ dma_busy = true ;
366
354
writeChannel.startJob ();
367
- count -= bytesThisPass;
355
+ count -= bytesThisPass;
368
356
if (block) {
369
357
while (dma_busy);
370
358
}
0 commit comments