Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/drivers/timer_impl_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,20 @@ void impl_timerPWMPrepareDMA(TCH_t * tch, uint32_t dmaBufferElementCount)
DMA_CLEAR_FLAG(tch->dma, DMA_IT_TCIF);
}

// Wait for EN bit to actually clear before reconfiguring DMA registers.
// Per STM32F7 RM: writes to DMA_SxNDTR and DMA_SxM0AR are ignored while EN=1.
// The EN bit does not clear synchronously - hardware may still be completing an
// in-progress burst when software writes 0 to EN.
for (uint32_t timeout = 10000; timeout && LL_DMA_IsEnabledStream(dmaBase, streamLL); timeout--) {
__NOP();
}
if (LL_DMA_IsEnabledStream(dmaBase, streamLL)) {
// EN did not clear - cannot reconfigure this cycle. Skip frame (ESC holds
// last command); EN should clear before the next call.
tch->dmaState = TCH_DMA_IDLE;
return;
}

LL_DMA_SetDataLength(dmaBase, streamLL, dmaBufferElementCount);
LL_DMA_ConfigAddresses(dmaBase, streamLL, (uint32_t)tch->dmaBuffer, (uint32_t)impl_timerCCR(tch), LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
LL_DMA_EnableIT_TC(dmaBase, streamLL);
Expand Down