AP_HAL_ChibiOS: ensure the rcout TIM_UP DMA request source is re-instated after cancellation

This fixes a bug in bdshot whereby dma cancellation could result in the wrong DMA channel
being used for dshot output and hence motors stopping
This commit is contained in:
Andy Piper 2023-03-25 14:53:09 +00:00 committed by Randy Mackay
parent b936b474ed
commit a86e18a09d
1 changed files with 7 additions and 1 deletions

View File

@ -1658,9 +1658,15 @@ void RCOutput::dma_cancel(pwm_group& group)
chSysLock(); chSysLock();
dmaStreamDisable(group.dma); dmaStreamDisable(group.dma);
#ifdef HAL_WITH_BIDIR_DSHOT #ifdef HAL_WITH_BIDIR_DSHOT
if (group.ic_dma_enabled()) { if (group.ic_dma_enabled() && !group.has_shared_ic_up_dma()) {
dmaStreamDisable(group.bdshot.ic_dma[group.bdshot.curr_telem_chan]); dmaStreamDisable(group.bdshot.ic_dma[group.bdshot.curr_telem_chan]);
} }
#if STM32_DMA_SUPPORTS_DMAMUX
// the DMA request source has been switched by the receive path, so reinstate the correct one
if (group.dshot_state == DshotState::RECV_START && group.has_shared_ic_up_dma()) {
dmaSetRequestSource(group.dma, group.dma_up_channel);
}
#endif
#endif #endif
// normally the CCR registers are reset by the final 0 in the DMA buffer // normally the CCR registers are reset by the final 0 in the DMA buffer
// since we are cancelling early they need to be reset to avoid infinite pulses // since we are cancelling early they need to be reset to avoid infinite pulses