I'm currently working on a project that require DMA to be hardware triggered each time there is a rising edge generated by a clock on a GPIO pin.
For now I've managed to get the DMA working properly in "one shot mode" but I can't figure out how to configure the DMA to be triggered not once but each time there is a rising edge.
I think there in a bit to reset somewhere but I have no clue.
volatile bool g_Transfer_Done = false;
dma_handle_t g_DMA_Handle;
static const int BUFF_LENGTH = 4U;
uint32_t dta = 0xAABBCCDD;
/* DMA descripter table used for ping-pong mode. */
SDK_ALIGN(uint32_t s_dma_table[2 * sizeof(dma_descriptor_t)], FSL_FEATURE_DMA_DESCRIPTOR_ALIGN_SIZE) = {0};
int cpt = 0;
void DMA_Callback(dma_handle_t *handle, void *param, bool transferDone, uint32_t tcds)
{
if (transferDone)
{
cpt++;
}
}
void DMA_Initialisation()
{
uint32_t xferConfig = DMA_CHANNEL_XFER(true,
true,
true,
false,
4,
kDMA_AddressInterleave0xWidth,
kDMA_AddressInterleave1xWidth,
4
);
DMA_Init(DMA0);
DMA_CreateHandle(&g_DMA_Handle, DMA0, 0);
DMA_EnableChannel(DMA0, 0);
DMA_SetCallback(&g_DMA_Handle, DMA_Callback, NULL);
DMA_SetChannelConfig(DMA0, 0, &triggerConfig, false);
PINT_Init(PINT);
INPUTMUX_Init(INPUTMUX);
INPUTMUX_AttachSignal(INPUTMUX, kPINT_PinInt0, kINPUTMUX_GpioPort1Pin28ToPintsel);
INPUTMUX_AttachSignal(INPUTMUX, kPINT_PinInt0, kINPUTMUX_PinInt0ToDma0);
INPUTMUX_Deinit(INPUTMUX); /* Turnoff clock to inputmux to save power. Clock is only needed to make changes */
/* Clear Rise and Fall flags first */
PINT->RISE = (1UL << kPINT_PinInt0);
PINT->FALL = (1UL << kPINT_PinInt0);
/* select level or edge sensitive */
PINT->ISEL = (PINT->ISEL & ~(1UL << kPINT_PinInt0)) |
(((PINT_PIN_RISE_EDGE & PINT_PIN_INT_LEVEL) != 0U) ? (1UL << kPINT_PinInt0) : 0U);
/* enable rising edge */
PINT->SIENR = 1UL << kPINT_PinInt0;
//(void *)(&GPIO->PIN[1])
DMA_PrepareChannelTransfer(&transferConfig,
&dta,
&destBuffer[0],
xferConfig,
kDMA_MemoryToMemory,
&triggerConfig,
(dma_descriptor_t *)&(s_dma_table[0])
);
triggerConfig.type = kDMA_RisingEdgeTrigger;
triggerConfig.burst = kDMA_LevelBurstTransfer;
triggerConfig.wrap = kDMA_NoWrap;
DMA_SubmitChannelTransfer(&g_DMA_Handle, &transferConfig);
/* Set two DMA descripters to use ping-pong mode. */
DMA_SetupDescriptor((dma_descriptor_t *)&(s_dma_table[0]), xferConfig, &dta,
(void *)destBuffer, (dma_descriptor_t *)&(s_dma_table[4]));
DMA_SetupDescriptor((dma_descriptor_t *)&(s_dma_table[4]), xferConfig, &dta,
(void *)destBuffer, (dma_descriptor_t *)&(s_dma_table[0]));
DMA_StartTransfer(&g_DMA_Handle);
}
Note : I'm using a LPC55
Thank's for your attention