cancel
Showing results for 
Search instead for 
Did you mean: 

How many AHB cycle required to perform memory to memory DMA after EN bit enabled?

Test User
Associate III
Posted on July 08, 2018 at 12:10

How many AHB cycle required to perform memory to memory DMA after EN bit enabled?

I'm checking the STM32F4xx_DSP_StdPeriph_Lib_V1.8.0\Project\STM32F4xx_StdPeriph_Examples\DMA\DMA_FLASHToRAM example and after the DMA is enabled there are some code which inits the NVIC controller. So I think at least 20-50 cycle needed before starting the mem to mem copy (or the copy has itself delay)

  /* DMA Stream enable */

  DMA_Cmd(DMA_STREAM, ENABLE);

  /* Check if the DMA Stream has been effectively enabled.

     The DMA Stream Enable bit is cleared immediately by hardware if there is an

     error in the configuration parameters and the transfer is no started (ie. when

     wrong FIFO threshold is configured ...) */

  Timeout = TIMEOUT_MAX;

  while ((DMA_GetCmdStatus(DMA_STREAM) != ENABLE) && (Timeout-- > 0))

  {

  }

   

  /* Check if a timeout condition occurred */

  if (Timeout == 0)

  {

    /* Manage the error: to simplify the code enter an infinite loop */

    while (1)

    {

    }

  }

  /* Enable the DMA Stream IRQ Channel */

  NVIC_InitStructure.NVIC_IRQChannel = DMA_STREAM_IRQ;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);     

}
6 REPLIES 6
Posted on July 08, 2018 at 14:13

How many AHB cycle required to perform memory to memory DMA after EN bit enabled?

I don't think this is different from 'normal' DMA, except that the trigger is present all the time until the whole transfer is finished. See AN4031. I did not time this but I guess the minimum will be around 8 cycles per transfer.

JW

Test User
Associate III
Posted on July 09, 2018 at 07:47

After enabling the DMA how many C lines can I write in the program? See my previous code.

Posted on July 09, 2018 at 09:15

I would enable the transfer completion interrupt before enabling the DMA.

JW

Posted on July 09, 2018 at 10:11

Yes, but this is an official example from STM.

Posted on July 09, 2018 at 14:07

One more thing: it's enough to enable the TC interrupt in the stream's control register. When the transfer is finished, the TC flag gets set in the DMA status register, and even if the respective interrupt is not enabled in NVIC at that moment, as soon as it is enabled anytime later, it will trigger the interrupt.

So I take back what I've said above: this example is OK (even if I would do things differently).

JW

Posted on July 09, 2018 at 13:30

There is probably no delay between enabling DMA and the first transfer, but given one transfer lasts say minimum 8 cycles, if there's say a dozen of transfers or more, it may give enough headroom for enabling the TC interrupt (this all provided that there are no other interrupts enabled which might cut in etc.etc.)

That it's not a good practice is another thing.

Some of the examples are of the 'oh, it works for me' type, unfortunately. Nobody is perfect. However, given SPL is deprecated, it's unlikely this particular one got fixed, or discussed by ST at all.

JW