DMA disable issue
My program collects data using DMA in circular buffer. I have following procedure to "start" collecting data.
// "reenable" measurment (enable results readout)
void restart_measurment(void){
run=1;
// DMA channel reset
CLEAR_BIT(TIM1->DIER, TIM_DIER_CC3DE | TIM_DIER_CC2DE); // disable DMA request in TIM1
LL_DMA_DisableStream(DMA2, LL_DMA_STREAM_6); // disable both streams
LL_DMA_DisableStream(DMA2, LL_DMA_STREAM_2);
while(LL_DMA_IsEnabledStream(DMA2, LL_DMA_STREAM_6)); // wait until disabled
while(LL_DMA_IsEnabledStream(DMA2, LL_DMA_STREAM_2));
clear_snapshots(); // clear data buffers
LL_DMA_ClearFlag_HT6(DMA2); // clear flags
LL_DMA_ClearFlag_TC6(DMA2);
LL_DMA_ClearFlag_HT2(DMA2);
LL_DMA_ClearFlag_TC2(DMA2);
LL_DMA_EnableStream(DMA2, LL_DMA_STREAM_6); // enable DMA streams
LL_DMA_EnableStream(DMA2, LL_DMA_STREAM_2);
reset_flipflops(); // manage external HW
TIM1->DIER |= TIM_DIER_CC3DE | TIM_DIER_CC2DE; // enable DMA request from TIM
}
Rarely program freezes in while loop on line "8". There is no any part of code which manipulates with DMA2 Enable bit (only read and clear HT and TC flags and they are not in IRQ). I have not inspected DMA registers yet, but does anyone have any idea what could be the reason to stuck in waiting for DMA disable ?
