Skip to content

DMA Based SPI will stop working after first call (in some cases) #230

Open
@markcha

Description

@markcha

There is a feature in the Adafruit_ZeroDMA code that any channel registered without a callback will never have its status set back to DMA_STATUS_OK (Adafruit_ZeroDMA issue #17). This will cause startJob to fail with an error. In the following code

char szBufOut[10];
setBufferData(szBufIn);
SPI.transfer(NULL, szBufOut, 10);   // block TRUE or FALSE, makes no difference.

// szBufOut contains proper data
SPI.transfer(NULL, szBufOut, 10); // block TRUE or FALSE, makes no difference.
// szBufOut contains previous data, not new data

The output buffer is not filled in the second time because the DMA channel was never started.

Solution: Register a callback for the readChannel (it copies from SERCOM to output buffer). This has to be done carefully to prevent another possible bug: Currently the SPI transfer is considered done when the writeChannel (the one sending data to the SERCOM). However, this may only write it to a buffer in the SERCOM and the transfer will not be done (all data in the output buffer) until after the readChannel DMA is done. Assuming that we are using a form of transfer that has a readChannel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions