From ad93ec30f1e575aa7e4618ba4f7be8786b9a1c8d Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Tue, 8 Oct 2024 23:41:52 +0200 Subject: [PATCH] [4.5.2] Fixes #13934: Fix motor(PWM protocol) spin while fc reset. (#13937) (#13958) Fixes #13934: Fix motor(PWM protocol) spin while fc reset. (#13937) * Fix motor(PWM protocol) spin while fc reset. * move delay out to motorShutdown Co-authored-by: ke deng --- src/main/drivers/motor.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/drivers/motor.c b/src/main/drivers/motor.c index bbb2247db7..40b18167bc 100644 --- a/src/main/drivers/motor.c +++ b/src/main/drivers/motor.c @@ -51,11 +51,25 @@ static bool motorProtocolDshot = false; void motorShutdown(void) { + uint32_t shutdownDelayUs = 1500; motorDevice->vTable.shutdown(); motorDevice->enabled = false; motorDevice->motorEnableTimeMs = 0; motorDevice->initialized = false; - delayMicroseconds(1500); + + switch (motorConfig()->dev.motorPwmProtocol) { + case PWM_TYPE_STANDARD: + case PWM_TYPE_ONESHOT125: + case PWM_TYPE_ONESHOT42: + case PWM_TYPE_MULTISHOT: + // Delay 500ms will disarm esc which can prevent motor spin while reboot + shutdownDelayUs += 500 * 1000; + break; + default: + break; + } + + delayMicroseconds(shutdownDelayUs); } void motorWriteAll(float *values)