Repository navigation
Bidir dshot - #12214
Bidir dshot#12214error414 wants to merge 49 commits into
Conversation
Ports bidirectional DShot (GCR) telemetry from Betaflight, enabling RPM-based gyro filtering without a dedicated ESC telemetry UART. After each DShot output frame the motor pin is switched to timer input capture mode via per-channel DMA to receive the ESC's GCR-encoded eRPM response. The decoded eRPM feeds the existing RPM filter infrastructure. New settings: - dshot_bidir_enabled: enable bidirectional DShot telemetry - dshot_edt_enabled: enable Extended DShot Telemetry (temperature, voltage, current in addition to eRPM) Changes: - drivers/dshot.c/.h: GCR decode, EDT frame parsing, eRPM-to-RPM conversion, motor frequency LPF (ported from Betaflight, GPLv3) - drivers/pwm_output.c: per-channel DMA direction switching between DShot output and GCR input capture on STM32 (StdPeriph/HAL) and AT32 - sensors/esc_sensor.c/.h: DShot bidir data path into ESC sensor framework (escSensorSetDshotData, escSensorIsActive) - flight/rpm_filter.c: DShot telemetry as frequency source alongside serial ESC sensor path - target/common_post.h: USE_RPM_FILTER enabled for any USE_DSHOT target - fc/fc_init.c: call initDshotTelemetry() at startup; fix RPM filter init condition to accept DShot bidir as a valid source - blackbox/blackbox.c: fix NULL dereference when escSensorGetData() returns NULL; fix uninitialized blackboxSlowState_t comparison - telemetry/srxl.c: replace Betaflight-specific USE_DSHOT_TELEMETRY guards with INAV's USE_DSHOT/USE_ESC_SENSOR; use escSensorGetData() Tested on SPEEDYBEEF405V4 (STM32F405, StdPeriph) with Bluejay ESC firmware. eRPM telemetry confirmed in blackbox; RPM gyro filter updating notch frequencies with motor speed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ht#11605 # Conflicts: # src/main/target/common_post.h
dshotDmaStream() is only called from the USE_HAL_DRIVER code paths, but was defined unconditionally with a dead fallback stub, so non-HAL F4 targets (e.g. FF_F35_LIGHTNING) built it with -Werror=unused-function. Scope the definition to USE_HAL_DRIVER to match its call sites.
pwm_output.c called LL_TIM_EnableDMAReq_CCx/LL_TIM_DisableDMAReq_CCx, which don't exist in ST's LL timer driver (only per-channel CC1..CC4 variants are provided). Add local static inline wrappers that set/clear the DIER CCxDE bits directly by mask, matching the equivalent helpers already used internally by timer_impl_hal.c.
…metry settings dshot_bidir_enabled and dshot_edt_enabled were added to settings.yaml but docs/Settings.md was never regenerated, failing CI's update_cli_docs.py check. Ran the generator; purely additive diff, no other drift.
loadDmaBufferDshot() was only defined when USE_DSHOT_DMAR was unset, but pwmCompleteMotorUpdate() also calls it as the per-channel DMA fallback on DMAR targets whenever bidir telemetry is enabled (burst DMA can't drive per-channel direction switching). Define it unconditionally; keep loadDmaBufferDshotStride() gated behind USE_DSHOT_DMAR since it's only used by the DMAR-specific burst path.
fix: keep DShot telemetry decode out of ITCM
…lemetry, magic H7 workdown from betaflight
pwmSetMotorDMACircular() predates bidirectional DSHOT and corrupts its per-channel direction-switching state machine when a config save runs (e.g. servo autotrim saving on disarm): - On USE_DSHOT_DMAR targets the burst path is never armed with bidir, so dmaBurstBuffer stays NULL and loadDmaBufferDshotStride() writes the zero-throttle frame through the NULL pointer into 0x00000000 - which is ITCM RAM holding .tcm_code (FAST_CODE), corrupting the firmware. - On per-channel targets impl_timerPWMSetDMACircular() re-enables the stream without regard to the current transfer direction, and on exit disables the TIM DMA request before the stream: a FIFO-enabled mem-to-periph stream then cannot drain, EN sticks at 1 and every later reconfiguration is silently ignored - the output is dead until reboot. - Circular output also repeats frames back-to-back, colliding with the GCR reply the ESC drives onto the same line after every frame. Match Betaflight instead: with bidir telemetry active, leave motor DMA alone during the flash write and accept the frame gap. Saves only happen disarmed, the ESC holds zero throttle, and the existing decode path rebuilds the streams (full DeInit/Init) on the first update afterwards. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BB55zdRNZq3Q6hZYsDYwTc
…ot-fix BidirDshot - fix for H7, invertion of timer, reset DMA for reading te…
# Conflicts: # src/main/drivers/pwm_output.c # src/main/fc/settings.yaml # src/main/sensors/esc_sensor.c
Structure: - dshot.c/h -> bidir_dshot.c/h, compiled only with USE_DSHOT_BIDIR. The define comes from common_post.h: USE_DSHOT && STM32H7 && !USE_DSHOT_DMAR (direction switching is verified on H7; DMAR has no per-channel stream). dshot_bidir_enabled / dshot_edt_enabled are hidden elsewhere. - Every bidir path in pwm_output.c sits under USE_DSHOT_BIDIR and, at run time, under useDshotTelemetry: with the setting off, plain DSHOT keeps the timer driver's DMA handler, FIFO setup and channel config from maintenance-10.x. The DMAR fallback to per-channel DMA is gone (excluded by the define instead). - USE_RPM_FILTER follows USE_ESC_SENSOR || USE_DSHOT_BIDIR instead of USE_DSHOT, so targets without ESC sensor do not grow. - No circular keep-alive for bidir: the line idles high for the flash write, as in Betaflight. Fixes: - EDT voltage/current were 10x off (0.25 V and 1 A steps into 0.01 V / 0.01 A fields): x25 / x100 instead of x250 / x1000. - ESC sensor RPM taken from the already computed mechanical RPM instead of computeRpm((int16_t)eRPM/100); an EDT-only first frame no longer publishes rpm = 0. - GCR decoder: guard against len < 1 (shift by -1) on glitch edges and on an exactly filled frame, and against len > 21. - Bidir ESC sensor data is aged at the serial poll rate, so a silent ESC drops out of the combined values like a serial one. - useDshotTelemetry is set once, by pwmMotorPreconfigure(); the ESC sensor asks isDshotTelemetryActive() instead of re-deriving it. - pwmDshotDmaIrqHandler keeps tch->dmaState in step with the timer driver's handler (timerPWMDMAInProgress()). - srxl.c: RPM comes through escSensorGetData(), no dshot include needed; duplicate includes removed. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…irdshot for rpi2350
…stead of frequency
…dshot Error414/feature/bidir dshot
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoAdd bidirectional DShot telemetry and RPM filtering
AI Description
Diagram
High-Level Assessment
Files changed (34)
|
Code Review by Qodo
1.
|
|
RAM / Flash usage vs. base commit
See RAM/flash optimization guide for techniques to reduce usage. |
|
Test firmware build ready — commit Download firmware for PR #12214 251 targets built. Find your board's
|
|
|
I tested On the AETH743Basic, both motors were stopped with the throttle stick all the way down. As soon as I disarmed, both briefly started spinning very slowly. This happened several times. I don't have a Blackbox log for it. I tried the same arm/disarm sequence on the FlyingRC and didn't see it happen there. I also saw motor 1's telemetry drop to 0–28% after I connected the second ESC to the AETH743Basic. I unplugged both the battery and USB-C, then powered the FC back up. Telemetry came back on both outputs, and I haven't seen the drop again. In the Configurator motor test, all tested outputs showed 100% telemetry reception at the points below.
One small Configurator thing (#2851). As soon as the RPM reaches five digits, the label wraps and overlaps the motor output percentage. The screenshot shows it at |
|
This sounds concerning?: !!!DONT TURN ON BIDIR DSHOT IF YOU USE BLHELI_32 fw VERSION 32.9 AND EARLIER!!! |
|
Hi @BastelWastel95 , thank you for testing. At first I would like to focus to "after disarm spin issue". Between tests please don't change any other value in config.
And could you provide your settings please. |
|
I changed nothing aside from the telemetry settings between the tests and tried several times to reproduce the motor spin on disarm using the same sequence, but I couldn't get it to happen again. Since I couldn't capture it in a new test, I took the FC apart to get the SD card out and check the logs from the original session. I attached the two logs I could date to that session, with GPS and home position data removed. Both show the ARM switch going off and end with a disarm entry. The throttle input stayed at 988 and both logged motor outputs stayed at 1000 around the switch transition. Each log runs for about a quarter of a second after that. |
|
Hmm, it's not good you are not able to reproduce it. Don't you remember, did you connect to AM32 configurator before testes when have seen the weird behaviour? |
Thanks for carrying bidirectional DShot forward! One request about the settings layout: this PR inserts Could you move the two new fields to the end of Heads-up: #12120 and #12121 (throttle boost / thrust linearization) also append to the end of Thank you! |
done |
…idir-dshot # Conflicts: # src/main/drivers/dma.h

!!!DONT TURN ON BIDIR DSHOT IF YOU USE BLHELI_32 fw VERSION 32.9 AND EARLIER!!!
This PR is based on PR #11605 @halfmanbear thank you very much.
ESC test
FC test
Configurator: iNavFlight/inav-configurator#2851