Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bi-directional dshot on iomcu F103 #25197

Merged
merged 19 commits into from
Dec 18, 2023

Conversation

andyp1per
Copy link
Collaborator

@andyp1per andyp1per commented Oct 6, 2023

This PR adds support for bdshot telemetry on iomcus using the F103. There is one limitation - only channels 1-4,7-8 support telemetry. It is not possible to support 5-6 as these share a DMA channel with the fast UART interconnect.

Support is built into the iomcu dshot variant so to use you simply need to set BRD_IO_DSHOT and supply the appropriate SERVO_BLH_BDMASK. ESC telemetry indexes are modified to reflect the fact that ESC's 1-4 and 7-8 can now provide telemetry.

EDT is working, so you can get temperature, current and voltage information from the ESCs using bdshot as well. To use set SERVO_DSHOT_ESC in the normal way.

This PR also fixes a few bugs found in the iomcu dshot support:

  • mode masks were being set incorrectly
  • mode masks were being updated too frequently
  • the minimum bdshot cancel timeout was being set incorrectly to micros rather than ticks
  • EDT was not working on AUX channels of boards with iomcu
  • DShot LEDs were not working with EDT
  • servo reversing and 3d was not working on FMU channels of boards with IOMCU

This work was generously sponsored by Holybro and builds on the existing dshot work kindly sponsored by CubePilot.

Copy link
Contributor

@tridge tridge left a comment

Choose a reason for hiding this comment

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

not complete review ... complex stuff!

libraries/AP_HAL_ChibiOS/RCOutput.cpp Outdated Show resolved Hide resolved
libraries/AP_HAL_ChibiOS/RCOutput.cpp Outdated Show resolved Hide resolved
libraries/AP_HAL_ChibiOS/RCOutput.cpp Outdated Show resolved Hide resolved
libraries/AP_HAL_ChibiOS/RCOutput.h Show resolved Hide resolved
libraries/AP_HAL_ChibiOS/RCOutput_bdshot.cpp Outdated Show resolved Hide resolved
@andyp1per
Copy link
Collaborator Author

This has been refactored on top of #25315 in order to make the review easier. I have also where possible pulled functions out into RCOuput_iofirmware.cpp. This increases the copy and paste a little but makes the non-iofirmware bdshot codepaths much less changed

libraries/AP_HAL_ChibiOS/RCOutput_bdshot.cpp Show resolved Hide resolved
libraries/AP_HAL_ChibiOS/RCOutput_bdshot.cpp Outdated Show resolved Hide resolved
libraries/AP_HAL_ChibiOS/RCOutput_bdshot.cpp Show resolved Hide resolved
libraries/AP_HAL_ChibiOS/RCOutput_bdshot.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@tridge tridge left a comment

Choose a reason for hiding this comment

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

mostly needs testing now

libraries/AP_IOMCU/iofirmware/ioprotocol.h Outdated Show resolved Hide resolved
libraries/AP_IOMCU/iofirmware/ioprotocol.h Outdated Show resolved Hide resolved
libraries/AP_IOMCU/iofirmware/ioprotocol.h Outdated Show resolved Hide resolved
@tridge tridge removed the DevCallEU label Nov 1, 2023
@andyp1per andyp1per force-pushed the pr-bdshot-iomcu-f103 branch from e2df36b to 60327d5 Compare November 1, 2023 17:43
@andyp1per andyp1per requested a review from tridge November 1, 2023 17:43
@andyp1per andyp1per force-pushed the pr-bdshot-iomcu-f103 branch from 60327d5 to d9719ea Compare November 8, 2023 09:49
@timtuxworth
Copy link
Contributor

I built master (not including this PR_ on my Durandal and got a number of internal errors and iomcu errors. If I use this PR, these errors go away. I don't know what that means, but I think no errors is good - right?
Screenshot 2023-12-11 at 6 29 12 PM

@andyp1per andyp1per force-pushed the pr-bdshot-iomcu-f103 branch 2 times, most recently from e65a413 to 8378585 Compare December 16, 2023 15:27
prevent repeated rcout mode sets
add ESC telemetry if compiled in
add infrastructure to support propagating erpm and telemetry from iomcu
add support to propagate bdmask to iomcu
add support for EDT
scale voltage and current correctly when reading EDT data
ensure that telemetry data is reset
reset ESC telemetry data to zero if stale
ESC type and bdmask must be setup before the output mode
add direct accessor for telemetry data to be used by iomcu
don't update telemetry data if no data
add support to tell if shared DMA channel is actually shared
avoid starting and stopping the timer peripheral with bdshot
ensure that rcout DMA allocation and deallocation happens entirely within the lock
increase rcout thread working area for bdshot
fix mode mask that is sent to the iomcu
ensure iomcu rcout thread gets timeouts for callbacks
control bdshot input and output line levels on f103
use input capture channel pairs to read rising and falling edges of telemetry on f103
reset channel pairs together on iomcu
generalize the bdshot input path to support suitable buffer sizes for iomcu
generalize DMAR reading of CCR registers to read two at a time on iomcu
enable bi-directional dshot channels on PWM1-4 on iomcu
add methods to directly access erpm values from rcout
update erpm mask and esc telemetry correctly for firmware supporting dshot
add support for propagating bdmask to iomcu
dshot commands to all channels need to be aware of iomcu
ensure esc type is propagated to iomcu
cope with iomcu channel numbering when using EDT
ensure pwm driver is reset properly for dshot commands on iomcu
correctly reset pwm for dshot commands
correctly mask off bdshot bits going to iomcu
don't reset GPIO modes on disabled lines
don't reset pwm_started when sharing DMA channels
set thread name on iomcu rcout and reduce stack size on iomcu
ensure that bdshot pulses with no response are handled correctly
correctly setup DMA for input capture on f103
deal with out of order captured bytes when decoding bdshot telemetry
ensure DMA sharing on f103 does not pull lines low
only disable the timer peripheral when switching DMA channels on iomcu
add support for waiting for _UP to finish before proceeding with dshot
re-order iomcu dshot channels to let TIM4_UP go first
ensure that a cascading event will always come when expected on rcout
allow timeouts when using cascading dshot
always rotate telemetry channel after trying to capture input
cater for both in order and out-of-order bdshot telemetry packets
cope with reversed packets when decoding bdshot telemetry
ensure UP DMA channel is fully free on iomcu before starting next dshot cycle
refactor rcout for iofirmware into separate file
remove unneeded packed attribute
reset the PWM status after channels have been enabled or disabled
enabled shared_up_dma to be fully compiled out
address some minor review comments
…nnels to 16

make ADC readings interrupt driven
turn off iomcu updates when debugging
allow for correct number of telemetry channels
cycle between vservo and vrssi when reading adc
build adc with O2
don't look for multiple pages on single-page packets
@andyp1per andyp1per force-pushed the pr-bdshot-iomcu-f103 branch from 8378585 to 710b4a1 Compare December 17, 2023 09:06
@tridge tridge merged commit d902242 into ArduPilot:master Dec 18, 2023
88 checks passed
@andyp1per andyp1per deleted the pr-bdshot-iomcu-f103 branch December 18, 2023 08:03
@andyp1per
Copy link
Collaborator Author

This was tested by @timtuxworth at the weekend on plane on a Durandal with no issues found - thanks Tim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants