title: DMA transfer taking more time than CPU transfer
body: <p>Our task is intended to demonstrate the benefit of using DMA to copy a large amount of data versus relying on the processor to directly handle the copying.
  The processor is an STM32F407 on the ST discovery board. </p>
  
  <p>In order to measure the copying time, a GPIO pin must be turned ON during copying and OFF once it has been copied.</p>
  
  <p>The code appears to be functional but it is currently showing the CPU taking about <strong>2.15ms</strong> to complete and DMA about <strong>4.5ms</strong>, which is the opposite of what is intended. I'm not sure if there simply isn't enough data for the faster speed of DMA to offset the overhead in setting it up perhaps?</p>
  
  <p>I have tried both copying elements of an array using the CPU and also using the memcpy function which seemed to yield very similar times.</p>
  
  <p>The function code is shown below:</p>
  
  <pre><code>DMASpeed(void)
  {
      #define elementNum 32000
      int *ptr = NULL;
      ptr = (int*)malloc(elementNum * sizeof(int));
      int *ptr2 = NULL;
      ptr2 = (int*)malloc(elementNum * sizeof(int));
      for (int i = 0; i &lt; elementNum; i++)
      {
          ptr[i] = 4;
      }
      LD5_GPIO_Port-&gt;BSRR = (uint32_t)LD5_Pin &lt;&lt; 16U;
      LD6_GPIO_Port-&gt;BSRR = (uint32_t)LD6_Pin &lt;&lt; 16U;
      // Initial value
      // printf("BEFORE: dst = '%s'\n", dst);
  
      // Transfer
      printf("Initiate DMA Transfer...\n");
      HAL_DMA_Start(&amp;hdma_memtomem_dma2_stream0, (int)ptr, (int)ptr2, (elementNum * sizeof(int)));
      LD5_GPIO_Port-&gt;BSRR = LD5_Pin;
      printf("DMA Transfer initiated.\n");
  
  
      // Poll for DMA completion
      printf("Poll for DMA completion.\n");
      HAL_DMA_PollForTransfer(&amp;hdma_memtomem_dma2_stream0,
          HAL_DMA_FULL_TRANSFER, HAL_MAX_DELAY);
      LD5_GPIO_Port-&gt;BSRR = (uint32_t)LD5_Pin &lt;&lt; 16U;
      printf("DMA complete.\n");
  
      // Print result
      // printf("AFTER: dst = '%s'\n", dst);
      free(ptr);
      free(ptr2);
  
      ptr = (int*)malloc(elementNum * sizeof(int));
      ptr2 = (int*)malloc(elementNum * sizeof(int));
      for (int i = 0; i &lt; elementNum; i++)
      {
          ptr[i] = i;
      }
  
      printf("Initiate CPU Transfer...\n");
      LD6_GPIO_Port-&gt;BSRR = LD6_Pin;
      //  for (int i = 0; i&lt;512; i++)
      //  {
      //  ptr2[i] = ptr[i];
      //  }
      memcpy(ptr2, ptr, (elementNum * sizeof(int)));
      printf("CPU Transfer Complete.\n");
      LD6_GPIO_Port-&gt;BSRR = (uint32_t)LD6_Pin &lt;&lt; 16U;
  
      free(ptr);
      free(ptr2);
  }
  </code></pre>
  
  <p>Thanks in advance for any assistance</p>