From 05a8141139187940c2fc7031442d2c06f0193f93 Mon Sep 17 00:00:00 2001 From: mikeller Date: Thu, 24 Aug 2017 04:34:10 +1200 Subject: [PATCH] Enable only DMA for channels that are used. --- src/main/drivers/pwm_output.c | 3 --- src/main/drivers/pwm_output.h | 1 + src/main/drivers/pwm_output_dshot.c | 5 ++++- src/main/drivers/pwm_output_dshot_hal.c | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) 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 6e3e8c9065..1d5929686c 100644 --- a/src/main/drivers/pwm_output.h +++ b/src/main/drivers/pwm_output.h @@ -107,6 +107,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 c4a65cfed4..a382154a0e 100644 --- a/src/main/drivers/pwm_output_dshot_hal.c +++ b/src/main/drivers/pwm_output_dshot_hal.c @@ -115,6 +115,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 */