diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index 2c76289888..befbbedee6 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -17,6 +17,7 @@ #include #include +#include #include #include "platform.h" @@ -134,7 +135,9 @@ static void pwmWriteMultiShot(uint8_t index, uint16_t value) void pwmWriteMotor(uint8_t index, uint16_t value) { - pwmWritePtr(index, value); + if (motors[index].enabled) { + pwmWritePtr(index, value); + } } void pwmShutdownPulsesForAllMotors(uint8_t motorCount) @@ -166,6 +169,11 @@ bool pwmAreMotorsEnabled(void) static void pwmCompleteOneshotMotorUpdate(uint8_t motorCount) { for (int index = 0; index < motorCount; index++) { + + if (!motors[index].enabled) { + continue; + } + bool overflowed = false; // If we have not already overflowed this timer for (int j = 0; j < index; j++) { @@ -192,6 +200,8 @@ void pwmCompleteMotorUpdate(uint8_t motorCount) void motorInit(const motorConfig_t *motorConfig, uint16_t idlePulse, uint8_t motorCount) { + memset(motors, 0, sizeof(motors)); + uint32_t timerMhzCounter = 0; bool useUnsyncedPwm = motorConfig->useUnsyncedPwm; bool isDigital = false; @@ -277,6 +287,7 @@ void motorInit(const motorConfig_t *motorConfig, uint16_t idlePulse, uint8_t mot } motors[motorIndex].enabled = true; } + pwmMotorsEnabled = true; } diff --git a/src/main/drivers/pwm_output_stm32f3xx.c b/src/main/drivers/pwm_output_stm32f3xx.c index 7a624c3632..5ae299dcf0 100644 --- a/src/main/drivers/pwm_output_stm32f3xx.c +++ b/src/main/drivers/pwm_output_stm32f3xx.c @@ -61,7 +61,7 @@ void pwmWriteDigital(uint8_t index, uint16_t value) motorDmaOutput_t * const motor = &dmaMotors[index]; - if (!motor->timerHardware->dmaChannel) { + if (!motor->timerHardware || !motor->timerHardware->dmaChannel) { return; } diff --git a/src/main/drivers/pwm_output_stm32f4xx.c b/src/main/drivers/pwm_output_stm32f4xx.c index 55a48bcbaf..03156953a0 100644 --- a/src/main/drivers/pwm_output_stm32f4xx.c +++ b/src/main/drivers/pwm_output_stm32f4xx.c @@ -59,7 +59,7 @@ void pwmWriteDigital(uint8_t index, uint16_t value) motorDmaOutput_t * const motor = &dmaMotors[index]; - if (!motor->timerHardware->dmaStream) { + if (!motor->timerHardware || !motor->timerHardware->dmaStream) { return; } diff --git a/src/main/drivers/pwm_output_stm32f7xx.c b/src/main/drivers/pwm_output_stm32f7xx.c index 30ccd983e2..b898493250 100644 --- a/src/main/drivers/pwm_output_stm32f7xx.c +++ b/src/main/drivers/pwm_output_stm32f7xx.c @@ -58,7 +58,7 @@ void pwmWriteDigital(uint8_t index, uint16_t value) motorDmaOutput_t * const motor = &dmaMotors[index]; - if (!motor->timerHardware->dmaStream) { + if (!motor->timerHardware || !motor->timerHardware->dmaStream) { return; }