use spi dma/easyDMA in a fifo manure, or cyclic queue

hello Nordic

i am working with nrf52832 and nrf52840, with ncs 1.9.2 with zephyr

i am sampling a sensor at high speed, i set spi_xfer call to read 8 bytes from the sensor every time there is a sample, this happens many times via ppi and a timer.

i don't want to copy the data from spi buffer every time for 8 bytes, i want to get some callback or interrupt once the dma buffer got 32 samples, for example (128 bytes of data), 

then i can copy the data (128 bytes) from this part of the dma while the spi_xfer operation keeps filling 8 bytes to the next section or buffer in the dma.

can this be done ?

if so, is there some example or guide as to how to do it ?

hope to read from you soon

best regards

Ziv

  • I suggest you use the EasyDMA list feature of the SPIM. This will require you to use the nrfx_spim driver and HAL directly instead of relying on zephyr's SPI device driver API, as you will want to handle CS/CONVST and SPIM's TASKS_START task with a TIMER. 

    The DMA list feature (RXD.LIST) increments the RXD.PTR after an EVENTS_END. The SPIM is then ready for the next transfer. You can disable the SPIM interrupts entirely, and let the ArrayList buffer fill up.

    There is a catch however and that is that the SPIM does not know the size of the DMA list, nor have any mechanism to stop the SPIM from overflowing the DMA list if TASKS_START is triggered after the DMA list buffer is full. 

    You will therefore need to count the number of times EVENTS_STARTED has been triggered and manually update RXD.PTR to the next DMA list buffer. 

    This can be done by triggering a TIMER's TASKS_COUNT (in counter mode), on EVENTS_STARTED. And enabling a COMPARE event after 'X' EVENTS_STARTED, where 'X' is the size, in bytes, of your DMA list buffer divided by RXD.MAXCNT

    The TIMER's COMPARE interrupt will then signal that your DMA list buffer is about to be full and that you need update RXD.PTR with the address to the next DMA list buffer. 

     

    With this implementation the ADC sampling will have minimal impact with respect to scheduling overheads. 


Related