Skip to content

Conversation

niklaut
Copy link
Contributor

@niklaut niklaut commented Apr 10, 2025

Solved Problem

For the FMUv6s target, we only had one UART TX pin left, so we need to swap the pins internally to receive ESC telemetry data.

Solution

Adds a -x command line flag to the dshot telemetry command. It is intended to be set in the board config, ie dshot telemetry -d /dev/ttyS5 -x in our case. On targets that don't support pin swapping, this selects the half-duplex single-wire mode on the TX pin, so that it can also receive.

Unfortunately I couldn't quite get this to be backward compatible since the previous implementation did not use a command line argument for the device name. But I updated all calls for it in the repo.

Changelog Entry

For release notes:

Feature Allow swapping of RX/TX pin of DShot Telemetry.

Alternatives

We could also add a parameter for the inversion? However, I kinda doubt that a generic serial port will have their pins inverted. This setting is only useful for boards with hardwired ESC telemetry pins.

Test coverage

  • Tested in hardware on Skynode S.
  • Tested in hardware on Skynode X.
  • Upgraded all dshot telemetry /dev/ttyX to dshot telemetry -d /dev/ttyX

Copy link

github-actions bot commented Apr 10, 2025

🔎 FLASH Analysis

px4_fmu-v5x [Total VM Diff: 176 byte (0.01 %)]
    FILE SIZE        VM SIZE    
--------------  -------------- 
+0.0%    +176  +0.0%    +176    .text
  +0.0%     +68  +0.0%     +68    [section .text]
   +61%     +56   +61%     +56    DShotTelemetry::init()
  +5.3%     +20  +5.3%     +20    DShot::custom_command()
  +3.1%     +16  +3.1%     +16    DShot::print_usage()
  [NEW]     +12  [NEW]     +12    CSWTCH.171
   +11%     +12   +11%     +12    DShot::init_telemetry()
  +2.0%      +8  +2.0%      +8    DShot::Run()
 -30.8%      -4 -30.8%      -4    g_nullstring
  [DEL]     -12  [DEL]     -12    CSWTCH.170
+0.0%     +77  [ = ]       0    .debug_abbrev
+0.0%      +4  [ = ]       0    .debug_frame
+0.0%    +359  [ = ]       0    .debug_info
+0.0%    +116  [ = ]       0    .debug_line
   +17%      +1  [ = ]       0    [Unmapped]
  +0.0%    +115  [ = ]       0    [section .debug_line]
+0.0%     +75  [ = ]       0    .debug_loclists
+0.0%      +1  [ = ]       0    .debug_rnglists
  [NEW]      +2  [ = ]       0    [Unmapped]
  -0.0%      -1  [ = ]       0    [section .debug_rnglists]
+0.0%     +56  [ = ]       0    .debug_str
+0.4%      +1  [ = ]       0    .shstrtab
+0.0%     +35  [ = ]       0    .strtab
  [DEL]     -11  [ = ]       0    CSWTCH.170
  [NEW]     +11  [ = ]       0    CSWTCH.171
  [NEW]     +33  [ = ]       0    DShot::_telemetry_swap_rxtx
  +3.3%      +1  [ = ]       0    DShot::init_telemetry()
  +3.4%      +1  [ = ]       0    DShotTelemetry::init()
+0.0%     +32  [ = ]       0    .symtab
  [DEL]     -32  [ = ]       0    CSWTCH.170
  [NEW]     +32  [ = ]       0    CSWTCH.171
  [NEW]     +32  [ = ]       0    DShot::_telemetry_swap_rxtx
   +33%     +16  [ = ]       0    __nxsem_tickwait_uninterruptible_veneer
 -33.3%     -16  [ = ]       0    __stm32_dmastop_veneer
 -25.0%     -16  [ = ]       0    __stm32_recvfifo_veneer
   +50%     +16  [ = ]       0    __uart_recvchars_veneer
-2.0%    -176  [ = ]       0    [Unmapped]
+0.0%    +756  +0.0%    +176    TOTAL

px4_fmu-v6x [Total VM Diff: 184 byte (0.01 %)]
    FILE SIZE        VM SIZE    
--------------  -------------- 
+0.0%    +184  +0.0%    +184    .text
  +0.0%     +64  +0.0%     +64    [section .text]
   +61%     +56   +61%     +56    DShotTelemetry::init()
  +5.3%     +20  +5.3%     +20    DShot::custom_command()
  +3.1%     +16  +3.1%     +16    DShot::print_usage()
  [NEW]     +12  [NEW]     +12    CSWTCH.171
   +11%     +12   +11%     +12    DShot::init_telemetry()
  +2.0%      +8  +2.0%      +8    DShot::Run()
  +0.0%      +8  +0.0%      +8    g_cromfs_image
  [DEL]     -12  [DEL]     -12    CSWTCH.170
+0.0%     +77  [ = ]       0    .debug_abbrev
+0.0%      +4  [ = ]       0    .debug_frame
+0.0%    +359  [ = ]       0    .debug_info
+0.0%    +116  [ = ]       0    .debug_line
  [NEW]      +1  [ = ]       0    [Unmapped]
  +0.0%    +115  [ = ]       0    [section .debug_line]
+0.0%     +75  [ = ]       0    .debug_loclists
-0.0%      -3  [ = ]       0    .debug_rnglists
  [DEL]      -2  [ = ]       0    [Unmapped]
  -0.0%      -1  [ = ]       0    [section .debug_rnglists]
+0.0%     +56  [ = ]       0    .debug_str
+0.4%      +1  [ = ]       0    .shstrtab
+0.0%     +35  [ = ]       0    .strtab
  [DEL]     -11  [ = ]       0    CSWTCH.170
  [NEW]     +11  [ = ]       0    CSWTCH.171
  [NEW]     +33  [ = ]       0    DShot::_telemetry_swap_rxtx
  +3.3%      +1  [ = ]       0    DShot::init_telemetry()
  +3.4%      +1  [ = ]       0    DShotTelemetry::init()
+0.0%     +32  [ = ]       0    .symtab
  [DEL]     -32  [ = ]       0    CSWTCH.170
  [NEW]     +32  [ = ]       0    CSWTCH.171
  [NEW]     +32  [ = ]       0    DShot::_telemetry_swap_rxtx
-2.6%    -184  [ = ]       0    [Unmapped]
+0.0%    +752  +0.0%    +184    TOTAL

Updated: 2025-05-27T08:32:56

@PetervdPerk-NXP
Copy link
Member

On the IMXRT we don't support TIOCSSWAP unfortunely, however when using TIOCSSINGLEWIRE the TX pin becomes half-duplex but also has the capability to RX as well.

I do happen to have a board that needs this feature since you're doing the PR, would be able to add TIOCSSINGLEWIRE as an feature as well?

@niklaut
Copy link
Contributor Author

niklaut commented Apr 14, 2025

would be able to add TIOCSSINGLEWIRE as an feature as well?

Sure, absolutely. Maybe -s is a bit too confusing to use for both Swap and Singlewire though. Maybe -x for swap (x = "cross over") and -s for single wire?

@PetervdPerk-NXP
Copy link
Member

would be able to add TIOCSSINGLEWIRE as an feature as well?

Sure, absolutely. Maybe -s is a bit too confusing to use for both Swap and Singlewire though. Maybe -x for swap (x = "cross over") and -s for single wire?

Good point, i think using -s and -x makes the most sense yeah.

@niklaut niklaut force-pushed the pr-swap-esc-telem-pins branch from 6e8d78c to 82aed5c Compare April 14, 2025 13:36
@niklaut
Copy link
Contributor Author

niklaut commented Apr 14, 2025

I've tested both swapping and single wire on the STM32H7 and they both work for my use-case.
I've implemented -x as pin swap or single wire mode. The end result is the same, and we don't expect people to use the TX pin of the same UART for anything else.

@niklaut niklaut marked this pull request as ready for review April 14, 2025 13:39
@niklaut niklaut requested a review from alexcekay April 14, 2025 13:39
@niklaut niklaut force-pushed the pr-swap-esc-telem-pins branch from 82aed5c to 53ae4c1 Compare April 14, 2025 13:45
@niklaut niklaut requested a review from PetervdPerk-NXP April 14, 2025 14:07
@niklaut niklaut force-pushed the pr-swap-esc-telem-pins branch 2 times, most recently from b9c990e to d37b637 Compare April 15, 2025 08:55
Copy link
Member

@PetervdPerk-NXP PetervdPerk-NXP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, don't have the hardware right now, but i'll test it when I have.

@niklaut niklaut force-pushed the pr-swap-esc-telem-pins branch 3 times, most recently from 11cc593 to 0b05536 Compare April 15, 2025 15:52
@niklaut niklaut force-pushed the pr-swap-esc-telem-pins branch 2 times, most recently from b2ae00d to 0424d9c Compare April 23, 2025 09:31
@niklaut niklaut force-pushed the pr-swap-esc-telem-pins branch from 0424d9c to 9334893 Compare May 26, 2025 14:50
@niklaut niklaut force-pushed the pr-swap-esc-telem-pins branch from 9334893 to f927540 Compare May 27, 2025 08:27
Copy link
Member

@alexcekay alexcekay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@niklaut niklaut merged commit 8c6d723 into main May 27, 2025
69 checks passed
@niklaut niklaut deleted the pr-swap-esc-telem-pins branch May 27, 2025 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants