Skip to content

Spektrum SRXL2 ESC: enable the driver and fix protocol decoding - #2

Open
RobertoD91 wants to merge 4 commits into
maintenance-10.xfrom
claude/esc-spektrum-protocol-check-i5b6jx
Open

Spektrum SRXL2 ESC: enable the driver and fix protocol decoding#2
RobertoD91 wants to merge 4 commits into
maintenance-10.xfrom
claude/esc-spektrum-protocol-check-i5b6jx

Conversation

@RobertoD91

@RobertoD91 RobertoD91 commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Spektrum SRXL2 Smart ESC support

Drives a Spektrum Smart ESC (Avian/Firma) directly from a UART TX pad over the single-wire half-duplex SRXL2 bus, replacing PWM and carrying ESC telemetry (RPM, voltage, current, FET temperature) back to the FC. The FC implements the SRXL2 bus-master role (device ID 0x21) per the official SpektrumRC/SRXL2 state machine.

Bench-validated on MATEKF405SE + Spektrum Smart ESC: handshake completes, motor responds to throttle, ESC answers telemetry polls.

Full documentation: docs/SRXL2_ESC.md (wiring, configuration, protocol details, debug_mode = SRXL2 reference, development notes).

What's included

  • src/main/drivers/srxl2_esc.c/h: SRXL2 master driver — official handshake sequence (50ms addressed polls → ESC reply → final 0xFF broadcast handshake), 100Hz control frames, telemetry polling every 10th frame, 300µs half-duplex turnaround guard, DEBUG_SRXL2 counters.
  • PWM_TYPE_SRXL2 motor protocol (no hardware timer), FUNCTION_SRXL2_ESC serial function (bit 28), USE_SRXL2_ESC gate (targets >512KB flash).
  • ESC sensor integration for telemetry consumers (e.g. vbat_meter_type = ESC).

Issues found and fixed along the way

  1. CRC16-CCITT byte order on RX validation (big-endian on wire, no swap on compare).
  2. Current telemetry already in centiamps — removed wrong ×10 scaling.
  3. Half-duplex: SERIAL_BIDIR (open-drain + pull-up, Betaflight-proven). SERIAL_BIDIR_PP floats the line between frames — reverted.
  4. Handshake state machine: the ESC's unprompted destId 0 handshake is a request to answer, not a confirmation; the final 0xFF broadcast is required for the ESC to enter Running.
  5. baudSupported = 0: advertising 400k (as the original code did) makes the ESC switch baud on the broadcast handshake and drop off the bus.
  6. Throttle channel band: Spektrum channel values span ±150% travel (32768 = center); raw 0 decodes as an invalid −150% throttle and the ESC keeps beeping. Now mapped to the standard ±100% band 0x2AA0..0xD554.
  7. Build fixes for non-DSHOT targets (pwmCompleteMotorUpdate guard) and fork CI (check-pg-versions.sh, log.c VLA folding, osd.c STATIC_ASSERT float literal on Apple clang).

Known limitations / follow-ups

  • Single ESC (motor 0); no motor-pole RPM scaling.
  • Telemetry display path under investigation (frames arrive and are parsed; consumer wiring being verified).
  • ESC reverse channel transmitted but fixed to "forward" — reversible-ESC integration is future work.

Companion configurator PR: RobertoD91/inav-configurator#5

🤖 Generated with Claude Code

https://claude.ai/code/session_01GroYFi23gHDgj43xrTAVaY

Drives a Spektrum Smart ESC (Avian/Firma) from a UART TX pad over the
single-wire half-duplex SRXL2 bus, replacing PWM and carrying ESC
telemetry (RPM, voltage, current, FET temperature) back to the FC. The
FC implements the SRXL2 bus-master role (device ID 0x21) following the
official SpektrumRC/SRXL2 device state machine: addressed handshake
polls every 50ms, reply to the ESC's unprompted requests, final 0xFF
broadcast handshake, then 100Hz control frames with a telemetry poll
every 10th frame and a 300us half-duplex turnaround guard. Channel
values use the Spektrum +/-100% band (0x2AA0..0xD554).

Includes: PWM_TYPE_SRXL2 motor protocol (no hardware timer),
FUNCTION_SRXL2_ESC serial function (bit 28), USE_SRXL2_ESC gate
(>512KB flash targets), esc_sensor integration (vbat_meter_type = ESC),
MOTOR REVERSE mode (permanentId 70) driving the ESC reverse channel for
reversible ESCs, DEBUG_SRXL2 debug mode, and docs/SRXL2_ESC.md.

Bench-validated on MATEKF405SE + Spektrum Smart ESC: handshake
completes, motor responds to throttle, ESC answers telemetry polls.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GroYFi23gHDgj43xrTAVaY
@RobertoD91
RobertoD91 force-pushed the claude/esc-spektrum-protocol-check-i5b6jx branch from 4d5807c to b76dc7e Compare July 29, 2026 15:38
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

Test firmware build ready — commit f6509e6

Download firmware for PR #2

243 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

claude added 3 commits July 30, 2026 00:36
The ESC reports electrical RPM; convert to shaft RPM with motor_poles
(default 14), matching how DSHOT telemetry is handled.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GroYFi23gHDgj43xrTAVaY
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GroYFi23gHDgj43xrTAVaY
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GroYFi23gHDgj43xrTAVaY
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.

2 participants