MKMxxZxxACxx5 Bare Metal Software Drivers  R4.1.6
Reference Manual
DMA Peripheral to Memory Transfer

This example shows advanced use of the Direct Memory Access (DMA) module for storing results of the analogue to digital conversion to the buffer without software intervention. The example configures AFE channel in low power mode, clocked by 1MHz IRC and with PGA disabled. The OSR value=1024 thus output sample rate=976Hz. After AFE channel and DMA transfer converted 24-bit results to the dedicated RAM memory array are configured the conversion starts and device enters Very Low Power Stop (VLPS) mode. When the last converted 24-bit result is transferred (after ~ 4 seconds) the DMA channel generates interrupt request and device resumes VLPR operation.

Source code:
/******************************************************************************
* (c) Copyright 2010-2015, Freescale Semiconductor Inc.
* ALL RIGHTS RESERVED.
******************************************************************************
* dmap2m_test.c
******************************************************************************/
#include "drivers.h"
/* static data definitions */
static int32 volatile samples[3000];
/* DMA callback prototype */
static void dma0_callback (DMA_CH_CALLBACK_TYPE type);
void main (void)
{
/* Initialize SMC and SIM modules */
SIM_Init (SIM_MODULE_LP_CONFIG);
/* Clock mode 2:1:1, 2.00 MHz (chip is trimmed) */
/* VREF module must be initialized after SIM module */
VREFL_Trim( 3); /* VREFL trimmed to 0.400 V */
PMC_SetBGEN (); /* enable VREF in VLPR mode */
SMC_SetMode (VLPR); /* transition to VLPR mode */
/* Install DMA0 callback and initialize DMA0 channel */
DMA_InstallCallback (DMA0, PRI_LVL3, dma0_callback);
&AFE_CH0_RR,samples,sizeof(samples)));
/* Initialize AFE_CH0 */
/* Enable interrupts */
/* Trigger AFE conversions */
/* Main loop */
while (1)
{
/* Transition to VLPS mode */
SMC_SetMode (VLPS); /* Power consumption: 1.01mA@VLPS; 1.04mA@STOP */
/* Wait for 3 seconds to enable current measurement */
arch_delay (3000000); /* Power consumption: 1.22mA@VLPR; 2.29mA@RUN */
/* Re-initialize DMA0 for peripheral to memory transfer */
&AFE_CH0_RR,samples,sizeof(samples)));
}
}
/* DMA callback function definition */
static void dma0_callback (DMA_CH_CALLBACK_TYPE type) { /* wakeup by IRQ */ }
Toolchain support:
IAR EWARM 7.40.7CodeWarrior 10.6KEIL uVision 5.15CrossWorks 3.6ATOLLIC TrueStudio 5.3.0Kinetis Design Studio 3.0.0