diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index 067be78fc3..9ace87f45e 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -397,9 +397,6 @@ void pwmWriteDshotCommand(uint8_t index, uint8_t motorCount, uint8_t command) motorDmaOutput_t *const motor = getMotorDmaOutput(i); motor->requestTelemetry = true; pwmWriteDshotInt(i, command); - } else { - // Needed to avoid DMA errors - pwmWriteDshotInt(i, DSHOT_CMD_MOTOR_STOP); } } diff --git a/src/main/drivers/pwm_output.h b/src/main/drivers/pwm_output.h index 9767a13726..2aef68332f 100644 --- a/src/main/drivers/pwm_output.h +++ b/src/main/drivers/pwm_output.h @@ -115,6 +115,7 @@ typedef struct { const timerHardware_t *timerHardware; uint16_t value; uint16_t timerDmaSource; + motorDmaTimer_t *timer; volatile bool requestTelemetry; #if defined(STM32F3) || defined(STM32F4) || defined(STM32F7) uint32_t dmaBuffer[DSHOT_DMA_BUFFER_SIZE]; diff --git a/src/main/drivers/pwm_output_dshot.c b/src/main/drivers/pwm_output_dshot.c index ff38430937..8bd18a2864 100644 --- a/src/main/drivers/pwm_output_dshot.c +++ b/src/main/drivers/pwm_output_dshot.c @@ -66,6 +66,7 @@ void pwmWriteDshotInt(uint8_t index, uint16_t value) uint8_t bufferSize = loadDmaBuffer(motor, packet); + motor->timer->timerDmaSources |= motor->timerDmaSource; DMA_SetCurrDataCounter(motor->timerHardware->dmaRef, bufferSize); DMA_Cmd(motor->timerHardware->dmaRef, ENABLE); } @@ -77,6 +78,7 @@ void pwmCompleteDshotMotorUpdate(uint8_t motorCount) for (int i = 0; i < dmaMotorTimerCount; i++) { TIM_SetCounter(dmaMotorTimers[i].timer, 0); TIM_DMACmd(dmaMotorTimers[i].timer, dmaMotorTimers[i].timerDmaSources, ENABLE); + dmaMotorTimers[i].timerDmaSources = 0; } } @@ -138,7 +140,8 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m timerOCInit(timer, timerHardware->channel, &TIM_OCInitStructure); timerOCPreloadConfig(timer, timerHardware->channel, TIM_OCPreload_Enable); motor->timerDmaSource = timerDmaSource(timerHardware->channel); - dmaMotorTimers[timerIndex].timerDmaSources |= motor->timerDmaSource; + motor->timer = &dmaMotorTimers[timerIndex]; + motor->timer->timerDmaSources &= ~motor->timerDmaSource; TIM_CCxCmd(timer, timerHardware->channel, TIM_CCx_Enable); diff --git a/src/main/drivers/pwm_output_dshot_hal.c b/src/main/drivers/pwm_output_dshot_hal.c index bd3d6a9bb8..bfdb3db83e 100644 --- a/src/main/drivers/pwm_output_dshot_hal.c +++ b/src/main/drivers/pwm_output_dshot_hal.c @@ -120,6 +120,7 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m } motor->timerDmaSource = timerDmaSource(timerHardware->channel); + motor->timer = &dmaMotorTimers[timerIndex]; dmaMotorTimers[timerIndex].timerDmaSources |= motor->timerDmaSource; /* Set the parameters to be configured */