AnsweredAssumed Answered

How to use a circular buffer (ADDRESS MODULO) with Kinetis L DMA?

Question asked by Mark Butcher on Jun 18, 2014
Latest reply on Jun 25, 2014 by Mark Butcher

Hi All

 

I am wondering about the address modulo option in the Kinetis L DMA.

 

It allows the use of a buffer or 16, 32, 64, 128, 256, ..  up to 256kB in size (it needs to be on a modulo address boundary and have the modulo bytes size) but allows a single DMA controller channel to manage a circular buffer. This is useful - for example - to sample an ADC input channel to so that it keeps filling the buffer until the end and then starts at the beginning again.

The requirements is that the transfer size programmed must be a multiple of the buffer size for it to be able to start but there is a maxiumum that can be set (0xfffff is the limite - but respecting the multiple buffer length requirement). For a buffer of 512 bytes in size the maximum number of bytes is therefore 0xffe00, which is 2047x the buffer. When this operatrion runs it runs until the circular buffer has been repeated 2047 times and then stops. If the ADC were to be sampled at 8kHz (for example) it would allow the operation to run autonomously for 131s before it stops.

 

But what if one wants it to run forever as would be typical in such a design with a free-running circular buffer?

 

I tried writing the value 0xffe00 to the BCR register while DMA was running, which set the count value back and so extended the period before it stopped. But is this what is intended? It there is risk involved (configuration error resulting at certain count values)? Is there a better way to achieve the infinite free-running solution using a single DMA channel?

 

Regards

 

Mark

Outcomes