Ping Pong EDMA

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ping Pong EDMA

2,105 Views
lacouturepatric
Contributor I

Hello,

 

I want to store flexio data (FLEXIO_CAMERA_GetRxBufferAddress) into 2 buffers (Ping pong) with Flexio + EDMA:

 

- The First buffer will contain the first N data (step 1) when the buffer 1 is full, data will be written into buffer 2

-  the second buffer will contain N+1 data to 2*N  (step 2), when the buffer 2 is full, data will be written into buffer 1 ...

 

I am using MCUXpresso IDE v10.0.0_344 and SDK_2.2_TWR-K80F150M.

 

I succeed to write into the first buffer but not into the second buffer. Do you know why I can not write into the second buffer or have any example ?

 

Thank you in advance

Regards,

 

Patrice

 

Bellow my code

 

 

 

 

__attribute__((aligned(32))) uint32_t FrameBuffer1[BUFF_LENGTH] = {0U};
__attribute__((aligned(32))) uint32_t FrameBuffer2[BUFF_LENGTH] = {0U};
 /* User callback function for EDMA transfer. */
 void EDMA_Callback(edma_handle_t *handle, void *param, bool transferDone, uint32_t tcds)
 {
     if (transferDone)
     {
      isTransferCompleted = true;
     }
 }
void Max2769_Init_V2(void)
  {
  uint32_t errCount;
  edma_transfer_config_t transferConfig;
   edma_config_t edmaConfig;
   edma_handle_t g_edmaHandle;
   flexio_camera_edma_handle_t g_cameraEdmaHandle;
   flexio_camera_transfer_t cameraTransfer;
   isTransferCompleted = false;

     /*Init the flexio to the camera mode */
     FLEXIO_MAX2769Init();

     /* Configure DMAMUX */
     DMAMUX_Init(DMAMUX0);
     DMAMUX_SetSource(DMAMUX0, DMA_CHN_FLEXIO_TO_FRAMEBUFF, (s_FlexioMax2769Device. shifterStartIdx + 1U));
     DMAMUX_EnableChannel(DMAMUX0, DMA_CHN_FLEXIO_TO_FRAMEBUFF);
     /* Configure DMA */
     EDMA_GetDefaultConfig(&edmaConfig);
     EDMA_Init(DMA0, &edmaConfig);
     //First TCD ( to FrameBuffer1)
    
     s_TcdMemoryPtrFlexioToFrame[0].SADDR = FLEXIO_CAMERA_GetRxBufferAddress(&s_FlexioMax2769Device);
     s_TcdMemoryPtrFlexioToFrame[0].SOFF = 0;
     s_TcdMemoryPtrFlexioToFrame[0].ATTR =
     DMA_ATTR_SSIZE(kEDMA_TransferSize32Bytes) | DMA_ATTR_DSIZE(kEDMA_TransferSize32Bytes);
     s_TcdMemoryPtrFlexioToFrame[0].NBYTES = 32;
     s_TcdMemoryPtrFlexioToFrame[0].SLAST = 0;
     s_TcdMemoryPtrFlexioToFrame[0].DADDR = (uint32_t)&FrameBuffer1;
     s_TcdMemoryPtrFlexioToFrame[0].DOFF = 32;
     s_TcdMemoryPtrFlexioToFrame[0].CITER = 1;
     s_TcdMemoryPtrFlexioToFrame[0].DLAST_SGA = (uint32_t) &s_TcdMemoryPtrFlexioToFrame[1];
     s_TcdMemoryPtrFlexioToFrame[0].CSR = 0;
     s_TcdMemoryPtrFlexioToFrame[0].BITER = 1;
    
     //First TCD ( to FrameBuffer2)
     s_TcdMemoryPtrFlexioToFrame[1].SADDR = FLEXIO_CAMERA_GetRxBufferAddress(&s_FlexioMax2769Device);
     s_TcdMemoryPtrFlexioToFrame[1].SOFF = 0;
     s_TcdMemoryPtrFlexioToFrame[1].ATTR =
     DMA_ATTR_SSIZE(kEDMA_TransferSize32Bytes) | DMA_ATTR_DSIZE(kEDMA_TransferSize32Bytes);
     s_TcdMemoryPtrFlexioToFrame[1].NBYTES = 32;
     s_TcdMemoryPtrFlexioToFrame[1].SLAST = 0;
     s_TcdMemoryPtrFlexioToFrame[1].DADDR = (uint32_t)&FrameBuffer2;
     s_TcdMemoryPtrFlexioToFrame[1].DOFF = 32;
     s_TcdMemoryPtrFlexioToFrame[1].CITER = 1;
     s_TcdMemoryPtrFlexioToFrame[1].DLAST_SGA = (uint32_t) &s_TcdMemoryPtrFlexioToFrame[0];
     s_TcdMemoryPtrFlexioToFrame[1].CSR = 0;
     s_TcdMemoryPtrFlexioToFrame[1].BITER = 1;
     // DMA INIT
     EDMA_CreateHandle(&g_edmaHandle, DMA0, DMA_CHN_FLEXIO_TO_FRAMEBUFF);
     EDMA_SetCallback(&g_edmaHandle, EDMA_Callback, NULL);
     EDMA_TcdSetTransferConfig(&s_TcdMemoryPtrFlexioToFrame[0], &transferConfig, &s_TcdMemoryPtrFlexioToFrame[1]);
     EDMA_InstallTCDMemory(&g_edmaHandle, s_TcdMemoryPtrFlexioToFrame, 2);
     EDMA_PrepareTransfer(&transferConfig, (void *)FLEXIO_CAMERA_GetRxBufferAddress(&s_FlexioMax2769Device), 32,  FrameBuffer1,
                                       32, 32, sizeof(FrameBuffer1) , kEDMA_PeripheralToMemory);
     EDMA_SubmitTransfer(&g_edmaHandle, &transferConfig);
     EDMA_StartTransfer(&g_edmaHandle);
     FLEXIO_CAMERA_EnableRxDMA(&s_FlexioMax2769Device, true);
   while (!(isTransferCompleted))
   {
  }
   sTransferCompleted= false;
  
   /* debug */
  for(uint32_t i=0;i<64;i++)
     {
     printf("0x%08X\n", FrameBuffer1[i]);
     }
  errCount =0;
  for(uint32_t i=0;i<BUFF_LENGTH;i++)
  {
         if (FrameBuffer1[i] != i+1)
         {
          errCount++;
         }
  }
   printf("errorCount == %d\n", errCount);
     
   while (!(isTransferCompleted))
   {
  }
   PRINTF("isTransferCompleted : \n");
 /* debug */
  for(uint32_t i=0;i<64;i++)
     {
     printf("0x%08X\n", FrameBuffer2[i]);
     }
errCount =0;
  for(uint32_t i=0;i<BUFF_LENGTH;i++)
  {
         if (FrameBuffer1[i] != i+1)
         {
          errCount++;
         }
  }
   printf("errorCount == %d\n", errCount);
  
  }

Original Attachment has been moved to: code.c.zip

Tags (1)
0 Kudos
Reply
2 Replies

1,494 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Lacouture,

Sorry for reply you so late.

What I get from your code is you use scatter/gather mode to transfer data. You should set TCD->CSR.ESG bit to enable scatter/gather processing. Reference manual Page 638 is the detail. You can try to refer to the example_edma_scatter_gather.
Here is an example which use another way to play ping-pong. https://www.nxp.com/docs/en/application-note/AN4520.pdf?fsrch=1&sr=1&pageNum=1
Btw, I'm a bit confused that MAX2769 is a GPS chip, it use SPI like bus, the Flex_IO_camera use I2C like bus. So...

Regards

Jing

1,494 Views
lacouturepatric
Contributor I

Hi Jing Pan,

Thank you for your help. I can now use the ping pong edma with flexio and save the data to the SD card. The speed rate dépends mostly to the SD card quality that is used!!

 

Regards,

Patrice

0 Kudos
Reply