Using DMA with the Tiva LaunchPad (ARM Cortex-M4F) for Audio Output

I've figured out how to use DMA (direct memory access) on the Texas Instruments Tiva LaunchPad (ARM Cortex-M4) microcontroller when using peripherals like an audio output DAC (digital to analog converter).

Tiva Launchpad Logic Analyzer and DAC Annotated.jpg

The DMA controller on the Tiva LaunchPad is known as "micro-DMA" and is abbreviated as "μDMA". Chapter 9 of the TM4C123G datasheet located here contains a large amount of detailed information concerning μDMA.

Utilizing the DMA controller frees up the CPU from having to do the transferring/receiving operations involved with sending/receiving data to/from a peripheral or local memory on the microprocessor. This saves CPU cycles that can be used for other necessary processing.

In an earlier project I used a 16-bit audio DAC with the TM4C123G microcontroller. The audio DAC chip I used is the MAXIM MAX541. A circuit diagram for how the MAX541 DAC and Tiva LaunchPad interface is shown below.

MAXIM MAX541 Circuit Diagram

In the earlier project I handled transferring data to the DAC manually (i.e. not using μDMA, but using the CPU to write sample values to the SPI register address assigned to the DAC). I've used my Embedded Artists LabTool logc analyzer to measure the time duration taken for transferring data for each of the two different methods (μDMA and non-μDMA).

The non-μDMA code transfers a single 16-bit audio sample at a time. It does this 44,100 times per second - matching the audio's 44.1 KHz sample rate. The newer, μDMA code example periodically transfers audio samples into a 256 sample buffer that the μDMA controller uses.

The percentage of CPU time used to transfer samples not using μDMA came to 3.077%. The percentage of CPU time used to transfer samples using the μDMA controller came to 1.418%. Here's a screenshot example of the measurement application used with the LabTool when measuring the non-μDMA method:

LabTool Measurement Non-DMA

. ..and a measurement example when using μDMA:

LabTool Measurement DMA

If you're interested in taking a look at the code, feel free to download it here. It's well commented with information from the datasheet as well as explanations from myself. I used TI's Code Composer Studio for development, building and debugging, but the code can be easily viewed with any text editor.

Author: Terence Darwen
Date: May 22nd, 2017