From 750a914cce390df01dd8eb6a4a1ada5d65db9be2 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Sat, 25 Mar 2023 14:53:09 +0000 Subject: [PATCH] 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 --- libraries/AP_HAL_ChibiOS/RCOutput.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_ChibiOS/RCOutput.cpp b/libraries/AP_HAL_ChibiOS/RCOutput.cpp index b1b3ee79e0..5d2f6b44dd 100644 --- a/libraries/AP_HAL_ChibiOS/RCOutput.cpp +++ b/libraries/AP_HAL_ChibiOS/RCOutput.cpp @@ -1658,9 +1658,15 @@ void RCOutput::dma_cancel(pwm_group& group) chSysLock(); dmaStreamDisable(group.dma); #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]); } +#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 // 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