From 4a7be33c2592d2f359f8d49b69fa516c0c17c7af Mon Sep 17 00:00:00 2001 From: Thorsten Laux Date: Mon, 22 Apr 2019 11:44:39 +0200 Subject: [PATCH 1/4] invert dshot --- src/main/drivers/pwm_output.c | 5 ++++- src/main/drivers/pwm_output_dshot.c | 10 ++++------ src/main/drivers/pwm_output_dshot_shared.c | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index 2f9931e95a..441f64835e 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -673,8 +673,11 @@ FAST_CODE uint16_t prepareDshotPacket(motorDmaOutput_t *const motor) csum ^= csum_data; // xor data by nibbles csum_data >>= 4; } - csum &= 0xf; // append checksum + if (useDshotTelemetry) { + csum = ~csum; + } + csum &= 0xf; packet = (packet << 4) | csum; return packet; diff --git a/src/main/drivers/pwm_output_dshot.c b/src/main/drivers/pwm_output_dshot.c index b68e359607..6a23638a89 100644 --- a/src/main/drivers/pwm_output_dshot.c +++ b/src/main/drivers/pwm_output_dshot.c @@ -269,14 +269,12 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m const bool configureTimer = (timerIndex == dmaMotorTimerCount-1); uint8_t pupMode = 0; + pupMode = (output & TIMER_OUTPUT_INVERTED) ? GPIO_PuPd_DOWN : GPIO_PuPd_UP; #ifdef USE_DSHOT_TELEMETRY - if (!useDshotTelemetry) { - pupMode = (output & TIMER_OUTPUT_INVERTED) ? GPIO_PuPd_DOWN : GPIO_PuPd_UP; - } else -#endif - { - pupMode = (output & TIMER_OUTPUT_INVERTED) ? GPIO_PuPd_UP : GPIO_PuPd_DOWN; + if (useDshotTelemetry) { + output ^= TIMER_OUTPUT_INVERTED; } +#endif IOConfigGPIOAF(motorIO, IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, pupMode), timerHardware->alternateFunction); diff --git a/src/main/drivers/pwm_output_dshot_shared.c b/src/main/drivers/pwm_output_dshot_shared.c index 0f6f4bbe66..4510767bb4 100644 --- a/src/main/drivers/pwm_output_dshot_shared.c +++ b/src/main/drivers/pwm_output_dshot_shared.c @@ -150,7 +150,7 @@ static uint16_t decodeDshotPacket(uint32_t buffer[]) csum = csum ^ (csum >> 8); // xor bytes csum = csum ^ (csum >> 4); // xor nibbles - if (csum & 0xf) { + if ((csum & 0xf) != 0) { return 0xffff; } return value >> 4; @@ -176,7 +176,7 @@ static uint16_t decodeProshotPacket(uint32_t buffer[]) csum = csum ^ (csum >> 8); // xor bytes csum = csum ^ (csum >> 4); // xor nibbles - if (csum & 0xf) { + if ((csum & 0xf) != 0) { return 0xffff; } return value >> 4; From f1e9c9f19a280804d106f336b8a375d71212e18f Mon Sep 17 00:00:00 2001 From: Thorsten Laux Date: Thu, 2 May 2019 14:05:38 +0200 Subject: [PATCH 2/4] invert csum in telemetry --- src/main/drivers/pwm_output_dshot_shared.c | 4 ++-- src/main/fc/core.c | 8 -------- src/main/fc/init.c | 21 --------------------- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/src/main/drivers/pwm_output_dshot_shared.c b/src/main/drivers/pwm_output_dshot_shared.c index 4510767bb4..56fd092b34 100644 --- a/src/main/drivers/pwm_output_dshot_shared.c +++ b/src/main/drivers/pwm_output_dshot_shared.c @@ -150,7 +150,7 @@ static uint16_t decodeDshotPacket(uint32_t buffer[]) csum = csum ^ (csum >> 8); // xor bytes csum = csum ^ (csum >> 4); // xor nibbles - if ((csum & 0xf) != 0) { + if ((csum & 0xf) != 0xf) { return 0xffff; } return value >> 4; @@ -176,7 +176,7 @@ static uint16_t decodeProshotPacket(uint32_t buffer[]) csum = csum ^ (csum >> 8); // xor bytes csum = csum ^ (csum >> 4); // xor nibbles - if ((csum & 0xf) != 0) { + if ((csum & 0xf) != 0xf) { return 0xffff; } return value >> 4; diff --git a/src/main/fc/core.c b/src/main/fc/core.c index 3ffb428e45..728c77cf84 100644 --- a/src/main/fc/core.c +++ b/src/main/fc/core.c @@ -414,14 +414,6 @@ void tryArm(void) return; } -#ifdef USE_DSHOT_TELEMETRY - if (isMotorProtocolDshot()) { - pwmWriteDshotCommand( - 255, getMotorCount(), motorConfig()->dev.useDshotTelemetry ? - DSHOT_CMD_SIGNAL_LINE_CONTINUOUS_ERPM_TELEMETRY : DSHOT_CMD_SIGNAL_LINE_TELEMETRY_DISABLE, false); - } -#endif - if (isMotorProtocolDshot() && isModeActivationConditionPresent(BOXFLIPOVERAFTERCRASH)) { if (!(IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH) || (tryingToArm == ARMING_DELAYED_CRASHFLIP))) { flipOverAfterCrashActive = false; diff --git a/src/main/fc/init.c b/src/main/fc/init.c index 8ecd6014fa..f5936e92c7 100644 --- a/src/main/fc/init.c +++ b/src/main/fc/init.c @@ -209,20 +209,6 @@ static IO_t busSwitchResetPin = IO_NONE; } #endif -#ifdef USE_DSHOT_TELEMETRY -void activateDshotTelemetry(struct dispatchEntry_s* self) -{ - if (!ARMING_FLAG(ARMED) && !isDshotTelemetryActive()) { - pwmWriteDshotCommand(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SIGNAL_LINE_CONTINUOUS_ERPM_TELEMETRY, false); - dispatchAdd(self, 1e6); // check again in 1 second - } -} - -dispatchEntry_t activateDshotTelemetryEntry = -{ - activateDshotTelemetry, 0, NULL, false -}; -#endif void init(void) { @@ -794,13 +780,6 @@ void init(void) setArmingDisabled(ARMING_DISABLED_BOOT_GRACE_TIME); -#ifdef USE_DSHOT_TELEMETRY - if (motorConfig()->dev.useDshotTelemetry) { - dispatchEnable(); - dispatchAdd(&activateDshotTelemetryEntry, 5000000); - } -#endif - fcTasksInit(); systemState |= SYSTEM_STATE_READY; From 093c2864cae2fc5c0bb1981c42a91929eba2bdc7 Mon Sep 17 00:00:00 2001 From: Thorsten Laux Date: Thu, 2 May 2019 15:02:14 +0200 Subject: [PATCH 3/4] inverted dshot for f7 --- src/main/drivers/pwm_output_dshot_hal.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/drivers/pwm_output_dshot_hal.c b/src/main/drivers/pwm_output_dshot_hal.c index e61fc0c8ba..6bb79edc60 100644 --- a/src/main/drivers/pwm_output_dshot_hal.c +++ b/src/main/drivers/pwm_output_dshot_hal.c @@ -241,16 +241,12 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m const uint8_t timerIndex = getTimerIndex(timer); const bool configureTimer = (timerIndex == dmaMotorTimerCount - 1); - uint8_t pupMode = 0; + uint8_t pupMode = (output & TIMER_OUTPUT_INVERTED) ? GPIO_PULLDOWN : GPIO_PULLUP; #ifdef USE_DSHOT_TELEMETRY - if (!useDshotTelemetry) { - pupMode = (output & TIMER_OUTPUT_INVERTED) ? GPIO_PULLDOWN : GPIO_PULLUP; - } else -#endif - { - pupMode = (output & TIMER_OUTPUT_INVERTED) ? GPIO_PULLUP : GPIO_PULLDOWN; + if (useDshotTelemetry) { + output ^= TIMER_OUTPUT_INVERTED; } - +#endif IOConfigGPIOAF(motorIO, IO_CONFIG(GPIO_MODE_AF_PP, GPIO_SPEED_FREQ_VERY_HIGH, pupMode), timerHardware->alternateFunction); From 51ae8d99d2a771820cc33c755dc0bb99a3a333eb Mon Sep 17 00:00:00 2001 From: Thorsten Laux Date: Thu, 2 May 2019 15:26:00 +0200 Subject: [PATCH 4/4] Avoid high dshot lines with telemetry during startup --- src/main/drivers/pwm_output_dshot.c | 4 ++++ src/main/drivers/pwm_output_dshot_hal.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/main/drivers/pwm_output_dshot.c b/src/main/drivers/pwm_output_dshot.c index 6a23638a89..12f3928536 100644 --- a/src/main/drivers/pwm_output_dshot.c +++ b/src/main/drivers/pwm_output_dshot.c @@ -393,6 +393,10 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m ( 2 + (motor->useProshot ? 4 * MOTOR_NIBBLE_LENGTH_PROSHOT : 16 * MOTOR_BITLENGTH)) / getDshotHz(pwmProtocolType); pwmDshotSetDirectionOutput(motor, true); + if (useDshotTelemetry) { + // avoid high line during startup to prevent bootloader activation + *timerChCCR(timerHardware) = 0xffff; + } #else pwmDshotSetDirectionOutput(motor, true, &OCINIT, &DMAINIT); #endif diff --git a/src/main/drivers/pwm_output_dshot_hal.c b/src/main/drivers/pwm_output_dshot_hal.c index 6bb79edc60..d56ee9810b 100644 --- a/src/main/drivers/pwm_output_dshot_hal.c +++ b/src/main/drivers/pwm_output_dshot_hal.c @@ -354,6 +354,10 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m ( 2 + (motor->useProshot ? 4 * MOTOR_NIBBLE_LENGTH_PROSHOT : 16 * MOTOR_BITLENGTH)) / getDshotHz(pwmProtocolType); pwmDshotSetDirectionOutput(motor, true); + if (useDshotTelemetry) { + // avoid high line during startup to prevent bootloader activation + *timerChCCR(timerHardware) = 0xffff; + } #else pwmDshotSetDirectionOutput(motor, true, &OCINIT, &DMAINIT); #endif