1
\$\begingroup\$

I am using DMA on an STM32F4 Discovery board to push values from an array into a peripheral. This needs to be done repeatedly, so I am using the circular DMA mode: DMA_InitStruct.DMA_Mode = DMA_Mode_Circular; which gets the DMA source address to jump back to the start of the array automatically.

I would like to count how many times this wrap has happened. Is there an interrupt or other feature built in to do this?

\$\endgroup\$
4
\$\begingroup\$

STM32 DMA has some interrupts. You can try to use the DMA_IT_TC flag. I have not tested it with mode from array to periph, but it worked with periph to array (example from my code):

DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE);

You should have also to set up NVIC interrupt (example):

ADCNVICConfig.NVIC_IRQChannel = DMA2_Stream0_IRQn;
ADCNVICConfig.NVIC_IRQChannelPreemptionPriority = 0;
ADCNVICConfig.NVIC_IRQChannelSubPriority = 1;
ADCNVICConfig.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&ADCNVICConfig);

TC flag means "transfer completed".

Example interrupt:

void DMA2_Stream0_IRQHandler(void)
{

    //Something

    if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0) != RESET)
    {
        DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
        //Something
    }

    //Something

}
\$\endgroup\$
  • \$\begingroup\$ Oh, that's cool - the "transfer complete" still works, even though the transfer keeps going? \$\endgroup\$ – Greg d'Eon Feb 26 '15 at 15:41
  • \$\begingroup\$ It works each completed transfer. But it's important to clear flag of interrupt, as in any other interrupt. See edited post. \$\endgroup\$ – Sławomir Kozok Feb 26 '15 at 15:44
  • \$\begingroup\$ As per usual in STM32 interrupts. Neat - very good to know! \$\endgroup\$ – Greg d'Eon Feb 26 '15 at 15:50
1
\$\begingroup\$

if you don't want to send the same array every time. You should wait for the both callbacks, the TxHalfCpltCallback and the TxCpltCallback. When the first half is transmited TxHalfCpltCallback is called, you should write this half of the buffer with new data, then when the TxCpltCallback is called write the second half of the buffer, and keep doing this until needed.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.