Hello
I try would change a IO Pin very time syncron. For this I try to use DMA and the PIT.
To startup use the example twrke18f_edma_memory_to_memory. This example work.
Now I tried to expand this example with the working LPIT example and try to configure the LPIT to trigger the DMA.
But I don't work.
Were is my mistake?
#define DMAMUX0 DMAMUX
#define EXAMPLE_DMA DMA0
#define EXAMPLE_DMAMUX DMAMUX0
#define BUFF_LENGTH 4U
#define DEMO_LPIT_BASE LPIT0
#define DEMO_LPIT_IRQn LPIT0_Ch0_IRQn
#define DEMO_LPIT_IRQHandler LPIT0_Ch0_IRQHandler
#define LPIT_SOURCECLOCK CLOCK_GetFreq(kCLOCK_ScgSircAsyncDiv2Clk)
edma_handle_t g_EDMA_Handle;
volatile bool g_Transfer_Done = false;
void EDMA_Callback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds)
{
if (transferDone)
{
g_Transfer_Done = true;
}
}
void DEMO_LPIT_IRQHandler(void)
{
LPIT_ClearStatusFlags(DEMO_LPIT_BASE, kLPIT_Channel0TimerFlag);
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}
AT_NONCACHEABLE_SECTION_INIT(uint32_t srcAddr[BUFF_LENGTH]) = {0x01, 0x02, 0x03, 0x04};
AT_NONCACHEABLE_SECTION_INIT(uint32_t destAddr[BUFF_LENGTH]) = {0x00, 0x00, 0x00, 0x00};
int main(void)
{
uint32_t i = 0;
edma_transfer_config_t transferConfig;
edma_config_t userConfig;
lpit_config_t lpitConfig;
lpit_chnl_params_t lpitChannelConfig;
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
CLOCK_SetIpSrc(kCLOCK_Lpit0, kCLOCK_IpSrcSircAsync);
LPIT_GetDefaultConfig(&lpitConfig);
LPIT_Init(DEMO_LPIT_BASE, &lpitConfig);
lpitChannelConfig.chainChannel = false;
lpitChannelConfig.enableReloadOnTrigger = false;
lpitChannelConfig.enableStartOnTrigger = false;
lpitChannelConfig.enableStopOnTimeout = false;
lpitChannelConfig.timerMode = kLPIT_PeriodicCounter;
lpitChannelConfig.triggerSelect = kLPIT_Trigger_TimerChn0;
lpitChannelConfig.triggerSource = kLPIT_TriggerSource_External;
LPIT_SetupChannel(DEMO_LPIT_BASE, kLPIT_Chnl_0, &lpitChannelConfig);
LPIT_SetTimerPeriod(DEMO_LPIT_BASE, kLPIT_Chnl_0, USEC_TO_COUNT(500000U, LPIT_SOURCECLOCK));
LPIT_EnableInterrupts(DEMO_LPIT_BASE, kLPIT_Channel0TimerInterruptEnable);
EnableIRQ(DEMO_LPIT_IRQn);
PRINTF("EDMA memory to memory transfer example begin.\r\n\r\n");
PRINTF("Destination Buffer:\r\n");
for (i = 0; i < BUFF_LENGTH; i++)
{
PRINTF("%d\t", destAddr[i]);
}
DMAMUX_Init(EXAMPLE_DMAMUX);
#if defined(FSL_FEATURE_DMAMUX_HAS_A_ON) && FSL_FEATURE_DMAMUX_HAS_A_ON
DMAMUX_EnableAlwaysOn(EXAMPLE_DMAMUX, 0, true);
#else
DMAMUX_SetSource(EXAMPLE_DMAMUX, 0, 60);
#endif
DMAMUX_EnableChannel(EXAMPLE_DMAMUX, 0);
EDMA_GetDefaultConfig(&userConfig);
EDMA_Init(EXAMPLE_DMA, &userConfig);
EDMA_CreateHandle(&g_EDMA_Handle, EXAMPLE_DMA, 0);
EDMA_SetCallback(&g_EDMA_Handle, EDMA_Callback, NULL);
EDMA_PrepareTransfer(&transferConfig, srcAddr, sizeof(srcAddr[0]), destAddr, sizeof(destAddr[0]),
sizeof(srcAddr[0]), sizeof(srcAddr), kEDMA_MemoryToMemory);
EDMA_SubmitTransfer(&g_EDMA_Handle, &transferConfig);
DMAMUX_EnablePeriodTrigger(EXAMPLE_DMAMUX, 0);
PRINTF("\r\nStarting channel No.0 ...");
LPIT_StartTimer(DEMO_LPIT_BASE, kLPIT_Chnl_0);
while (g_Transfer_Done != true)
{
}
PRINTF("\r\n\r\nEDMA memory to memory transfer example finish.\r\n\r\n");
PRINTF("Destination Buffer:\r\n");
for (i = 0; i < BUFF_LENGTH; i++)
{
PRINTF("%d\t", destAddr[i]);
}
while (1)
{
}
}
I get the LPIT interrupt but never the DMA interrupt and the copy also don't work.
Thanks for your help.
Tobias