Commit Graph
23 Commits
Author SHA1 Message Date
Peter Barker e4f836b315 Revert "AP_HAL_ChibiOS: add HOLD_HIGH PWM pins handed to their timer at first output"
This reverts commit 239f5c1f97.

PR #34359 was merged by mistake.  On the bench, with an ESC on
YJUAV_A6SE_H743 output 1, the hold presents a continuous high (full
throttle to a PWM ESC) for about 10.5s after every reset, and for as
long as safety is engaged when output 1 is a motor outside
BRD_SAFETY_MASK, which is Copter's default.  The ESC started to enter
throttle calibration.  Back the change out until the hold can be
chosen per output.
2026-09-18 00:04:45 +10:00
Peter Barker 239f5c1f97 AP_HAL_ChibiOS: add HOLD_HIGH PWM pins handed to their timer at first output
The STM32 JTAG pins JTDI (PA15) and NJTRST (PB4) come out of every
reset, and out of power-on, with an internal pull-up enabled, and 84
hwdef directories in the tree route a PWM output through one of them:
61 through PA15, 38 through PB4, 15 through both.  A servo on such an
output sees the line pulled high from then until firmware reconfigures
the pin.  On the H743 that measured 692us to the bootloader's board init
on a warm reset, and 496us and 520us on two cold power-ons.  Each is a
pulse inside the range servos accept, so the servo drives to an endpoint
and holds it through the rest of the boot.  Nothing can shorten that
window, since no code runs during it.

Give hwdef a HOLD_HIGH keyword for PWM pins.  The generator emits such a
pin as a pulled-up input with its timer alternate function preset, and a
HAL_PWM_HOLD_HIGH_MASK of the channels concerned.  It rejects the keyword
on any pin RCOutput will never hand back to a timer: anything other than
a PWM(n) timer output in the main configuration, so also an RC input, the
alarm and an ALT(n) pin.  One predicate decides both that and which pins
get a mask bit, so the two cannot disagree.  The check is made when the
pin is parsed, which covers bootloader builds too.  STM32F1 is rejected
outright, since its pin setup does not honour the keyword at all.

RCOutput keeps each channel an input until the first non-zero value is
pushed to it, in the PWM and DShot output paths, and only then switches
the pin to the timer.  With the bootloader also keeping the pull-up, the
line is high continuously from the reset until the first real frame,
which for a channel outside BRD_SAFETY_MASK means until safety is
disarmed, so the servo sees a high far longer than any valid pulse
rather than a plausible short one followed by seconds of silence.  On
the bench the test servo did not move at all across ten reboots.

The mode switch is an unlocked read-modify-write of the port registers,
and other threads change the modes of other pins on the same port, so
a single write can be lost.  The channel is therefore not marked handed
over until a later output finds the pin already in alternate mode; until
then each output writes the mode again, so a lost write is repaired one
output later rather than leaving the pin an input until reboot.

Several other owners of a pad have to take it explicitly, because none
of them goes through the normal output path:

 - the alarm driver configures a timer and never the pad, and disables
   the group's channels first, so the hold on the alarm's own channel is
   released before that.  Only that channel: no real frame will ever
   arrive for the rest of the group, so a HOLD_HIGH pin among them is
   correctly left held;
 - soft serial saves and restores the pad's mode, so BLHeli passthrough
   hands the pin over when it selects it, or it would save "input" and
   transmit nothing;
 - neopixel and ProfiLED output is chosen at runtime by SERVOx_FUNCTION
   on an ordinary PWM(n) pin and is sent without push_local(), so the
   serial LED path releases its group's pads before driving them;
 - DShot commands such as beeps are sent before arming, when nothing has
   released the pad yet, so the command path releases every channel it
   transmits on;
 - bidirectional DShot, when enabled at runtime, takes the pads of a
   whole group during init, so it clears the pending bit there.  A pin
   merely declared BIDIR keeps its hold; one whose group has bidirectional
   DShot enabled gets no protection.  The hwdef allows HOLD_HIGH and BIDIR
   together deliberately.

Verified under Renode on YJUAV_A6SE_H743 with ArduPlane: the
application's board init leaves PA15 an input, it stays one through
24.8s of init, and the mode write that puts it on TIM2 lands at the same
microsecond as the first non-zero CCR1 write.  With the first mode write
dropped on purpose, the next output found PA15 still an input and wrote
it; unmodified, the second output sees the mode has held and later
outputs no longer read the port.  MatekF405-TE and the IOMCU
firmware still build, and a no-mask board's firmware is byte-identical.
2026-09-17 22:56:37 +10:00
Andy Piper 48624f189e AP_HAL_ChibiOS: dshot commands for reverse/3D should be sent to IOMCU
normalize servo/FMU channels for dshot commands and 3D mask
2024-09-04 18:34:10 +10:00
Andy Piper fc51829b63 AP_HAL_ChibiOS: add iomcu support for reversible mask
check armed state on iomcu before sending dshot packets
2024-09-04 18:34:10 +10:00
Andy Piper ea76c0bd01 AP_HAL_ChibiOS: ensure dshot commands are send to all FMU channels when IOMCU is present 2023-12-18 19:02:52 +11:00
Andy Piper 8c03c9e4bf AP_HAL_ChibiOS: cache values of io_dshot() and io_enabled()
enabled shared_up_dma to be fully compiled out
address some minor review comments
2023-12-18 19:02:52 +11:00
Andy Piper 9f30d01561 AP_HAL_ChibiOS: bdshot for f103 iofirmware
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
2023-12-18 19:02:52 +11:00
Andy Piper c6c78a9c32 AP_HAL_ChibiOS: ensure reverse and reversible masks are applied to iomcu 2023-08-15 06:53:48 +10:00
Andy Piper 837c81af5e AP_HAL_ChibiOS: fix sending of dshot commands to all channels 2023-08-15 06:53:48 +10:00
bugobliterator 9a21297cd1 AP_HAL_ChibiOS: add support for DShot on IOMCU
set timer counter size to be a byte wide
use HAL_DSHOT_ENABLED instead of DISABLE_DSHOT
build iomcu-dshot from existing iomcu
correct defines for DMAR size on iomcu
allow iomcu dshot rate to be configured from FMU
correct DMA allocation for dshot on iomcu
allow debug builds on iofirmware
ensure dshot is enabled on iomcu dshot
support proper iomcu dshot output thread triggered by FMU
allow selective disablement of serial LEDs and passthrough
disable serial LEDs and passthrough on iomcu-dshot
propagate ESC telemetry to iomcu
dshot_send_groups() for iomcu
remove use of ICU on iomcu for dshot. only allocate possible DMA channels
rename serial passthrough and dshot defines
update dshot docs
resize dshot iomcu main stack to minimum
correct dshot prescaler usage and bit_width_mul calculation
use ChibiOS in tickless mode on iomcu-dshot so that virtual timers can be used
propagate dshot commands to iomcu
passthrough oneshot125 to iomcu
2023-08-15 06:53:48 +10:00
Andy Piper 76b7566cd1 AP_HAL_ChibiOS: implement extended dshot telemetry (EDT) 2023-06-27 09:28:33 +10:00
Andy Piper cabaef6173 AP_HAL_ChibiOS: add BLHeli_S ESC type and use it to control bitwidths 2022-05-25 17:06:08 +10:00
Andrew Tridgell 1d9abefbb1 AP_HAL_ChibiOS: more changes for 32 bit servo mask 2022-05-22 12:07:37 +10:00
Iampete1 7fc691d8d5 AP_HAL_ChibiOS: enable 32 servo outs 2022-05-22 12:07:37 +10:00
Andy Piper 4fa0e275fd AP_HAL_ChibiOS: fix ESCs constantly arming on rover with dshot commands
make sure debug will compile
take into account active channels when configuring bdshot
add channel mask debug output
correct set bdshot telemetry position at startup
make sure all channels in a bdshot group are pulled high to prevent spurious pulses
2022-03-29 10:29:31 +11:00
Andy PiperandRandy Mackay 458ff45fe6 AP_HAL_ChibiOS: correct channel offsets for dshot commands
Co-authored-by: Randy Mackay <rmackay9@yahoo.com>
2022-03-24 11:20:09 +09:00
Andrew Tridgell 638e20a0b9 HAL_ChibiOS: bring in hal.h where it is needed 2022-02-22 12:13:19 +11:00
Andrew Tridgell f4ad8f6ef5 HAL_ChibiOS: fix for HAL_PWM_COUNT zero
reported by Mallikarjun
2021-09-01 13:05:20 +10:00
Andy Piper a51e58022f AP_HAL_ChibiOS: add accessor for reversed mask
allow mask updates to be disabled
send dshot commands even if armed - they will be accepted as long as throttle is at zero
only accept low-priority dshot commands while disarmed
apply reversed and reversible mask as servo channels
2021-08-12 19:00:51 +09:00
Andy Piper 9e99f724e5 AP_HAL_ChibiOS: add 1Hz update_channel_masks()
Send dshot commands in update function
2021-06-22 09:55:27 +10:00
Michel Pastor a148849ec3 AP_HAL_ChibiOS: RCOutput_serial: fix comment for set_reversible_mask() 2021-05-26 17:59:04 +10:00
Andy Piper 66fadf53a1 AP_HAL_ChibiOS: remove dshot calibration step 2021-05-05 17:41:24 +10:00
Andy Piper f3f3056dba AP_HAL_ChibiOS: add support for dshot commands to rcout
add support for dshot beepcodes through tonealarm
add support for dshot reversal and command queue
add support for dshot commands to all channels
correctly manage channel enablement in PWM groups
Correctly send dshot commands when using bi-dir dshot
allow reversible settings to be changed
ChibiOS: allow more than one type of ESC for dshot commands
Only execute reverse/reversible commands on BLHeli
add support for checking active ESCS
mark ESCs active when bdshot telemetry is returned
allow dshot alarm to be disabled
allow priroitized dshot commands
2021-05-05 17:41:24 +10:00