Skip to content

CRSF rewrite to be 'more' spec compliant - #3198

Merged
pkendall64 merged 46 commits into
ExpressLRS:masterfrom
pkendall64:crsf-rewrite
Sep 5, 2025
Merged

pkendall64 merged 46 commits into
ExpressLRS:masterfrom
pkendall64:crsf-rewrite

Conversation

@pkendall64

@pkendall64 pkendall64 commented May 2, 2025 •

Copy link
Copy Markdown
Collaborator

This is a rather large set of code changes to extend our CRSF implementation to be more compliant with the CRSF specification. https://github.com/tbs-fpv/tbs-crsf-spec/blob/main/crsf.md

Notes

  1. Adds a new framework with three new classes for implementing the CRSF spec
    1. CRSFRouter - this is the head class of the CRSF framework. The endpoint is responsible for maintaining the routing table and for forwarding messages to the correct endpoints and/or connectors.
    2. CRSFEndpoint - the target for CRSF messages, this will handle all messages directed at it's device_id.
    3. CRSFConnector - a connection to another device in the CRSF network.
  2. Adds implementation of the above classes
    1. TXModuleEndpoint - handles all the CRSF messages for the TX Module e.g. the parameter read/write commands from the Lua script.
    2. TXOTAConnector - sends the CRSF messages OTA to the RX; has special handling for the RC commands.
    3. RXEndpoint - handles all the CRSF messages for the RX, similar to the TXEndpoint.
    4. RXOTAConnector - sends the CRSF messages OTA to the TX; has special handling for the LinkStats.
    5. SerialCRSF - connector for delivering messages to any CRSF connected device e.g. flight controller, GPS etc.
    6. SerialSmartAudio - a 'fake' connector that translates Betaflight CRSF wrapped MSP messages into SmartAudio for a directly connected SmartAudio VTX.
    7. SerialTramp - similar to the SerialSmartAudio, but for IRC Tramp VTX control.

Future Changes

  1. Extend MSPVTX/VTX to become an endpoint so it can be configured as any other CRSF device for which channel/power etc is selected.
  2. The Betaflight config system (TCPSocket) should become an endpoint for translating and forwarding MSP messages to the FC.
  3. The GPS, Tramp and SmartAudio serial devices could become endpoints so they can be configured via CRSF.

Testing

  • Analog VBAT (overridden by CRSF message)
  • Barometer (overridden by CRSF message)
  • MSPVTX
  • Serial GPS
  • HoTT Telemetry sensors
  • SmartAudio
  • Tramp
  • Betaflight config via wifi
  • Backpack wireless Pan/Tilt/Roll
  • Handset PPM/CRSF auto detect
  • MAVLink
  • VTXAdmin
  • Arm on a switch (EdgeTX 2.11)
  • RX passthrough flashing
  • Changing RX protocol from CRSF and back again via Lua

@pkendall64

Copy link
Copy Markdown
Collaborator Author

@wimalopaan Can you check if this satisfies your needs for #2901, #2941, #2975 and #3160
@KissUltra Can you check that this will work for you needs #3009

@wimalopaan

Copy link
Copy Markdown

Oh, cool, that you did spend a lot of work on it!!!

This PR is against master, would it be applicable to 3.x.x-maintenance also (for #2975) ?

Yes, I will test that, but that will take some days ...

@KissUltra

Copy link
Copy Markdown

Very cool. Will check against my osd code. Thank you.

@pkendall64

Copy link
Copy Markdown
Collaborator Author

This PR is against master, would it be applicable to 3.x.x-maintenance also (for #2975) ?

No this will not be applicable to 3.x.x

@pkendall64

pkendall64 commented May 3, 2025 •

Copy link
Copy Markdown
Collaborator Author

When testing this please remember that you will need to flash both the TX and the RX as the master branch is NOT compatible with 3.x.x

@KissUltra

KissUltra commented May 3, 2025 •

Copy link
Copy Markdown

Just did quick test, and my ELRS detection is no more :)
I am using:

uint8_t tmp[6] = { 0xc8, 0x04, 0x28, 0xEC, 0xC8, 0 }; //request device info

NO TX powered. Works fine with latest release.

Getting no response back. Something changed in this area?

@pkendall64

Copy link
Copy Markdown
Collaborator Author

Yes, I've broken it. I'll get back to you when it's fixed... again

@pkendall64

Copy link
Copy Markdown
Collaborator Author

Getting no response back. Something changed in this area?

No, but yes. No data is output on the serial port of there is a model mismatch or team-race is on and not on the selected model. The issue is that model matched is false by default, so until there is a valid connection from a TX then nothing wull be output.
This will need to change, but in the meantime you should it should work if you have a TX connected.

@KissUltra

Copy link
Copy Markdown

Should work without ANY radio. I will wait for your fix for next test. You should be able to configure just RX.

@pkendall64

Copy link
Copy Markdown
Collaborator Author

Should work without ANY radio. I will wait for your fix for next test. You should be able to configure just RX.

Ok, I've done some more work on this and it should be all good now.
Please let me know if you have any issues.

@KissUltra

Copy link
Copy Markdown

Just did some test. Device info indeed works now. Devices enumeration from osd - still doesnt.

@KissUltra

Copy link
Copy Markdown

Enumeration works using sending to broadcast address:

uint8_t tmp[6] = {0xc8, 0x04, 0x28, 0x00, 0x80, 0}; //  osd id is 0x80

@pkendall64

Copy link
Copy Markdown
Collaborator Author

Just did some test. Device info indeed works now. Devices enumeration from osd - still doesnt.

What command are you sending that doesn't work? i.e. the full command.

If I send a broadcast message in the the serial port from 0x80 then the 0x80 is added as a known device on the serial connector.
Then if I query for a parameter from the CRSF_RECEIVER (0xEC) e.g. parameter 1 from the 0x80 device then the response is send out the serial port.

@KissUltra

Copy link
Copy Markdown

as u see, i send from 80 to serial receiver BROADCAST message. All devices must respond back VIA receiver. That doesnt happen. Keep in mind, FC has 2 addresses (and potentially 10 if 8 esc are registered). All of it behind fc endpoint. So, if 80 sends a broadcast, 80 should be registered on receiver endpoint towards FC. then reveiver should respond back.

@KissUltra

Copy link
Copy Markdown

Where are u located? I can send you ultra if u like.

@pkendall64

Copy link
Copy Markdown
Collaborator Author

Where are u located? I can send you ultra if u like.

Can we connect on discord. Might make things easier

@KissUltra

Copy link
Copy Markdown

Yes of course.

FedorCommander

@KissUltra

Copy link
Copy Markdown
Screenshot 2025-05-04 at 11 30 12 When it will start from 0xC8 aka sync byte, should be fine. :)))

@KissUltra

Copy link
Copy Markdown

aha!
Screenshot 2025-05-04 at 21 41 47
Screenshot 2025-05-04 at 21 41 19
Screenshot 2025-05-04 at 21 41 40

@pkendall64
pkendall64 marked this pull request as ready for review May 14, 2025 04:31
pkendall64 added 14 commits June 6, 2025 17:20
# Conflicts:
#	src/lib/CrsfProtocol/crsf_protocol.h
#	src/lib/Handset/CRSFHandset.cpp
#	src/lib/LUA/lua.cpp
#	src/lib/Telemetry/telemetry.cpp
#	src/lib/Telemetry/telemetry.h
#	src/src/rx-serial/SerialCRSF.cpp
#	src/src/rx-serial/SerialMavlink.h
#	src/src/rx_main.cpp
#	src/targets/unified.ini
# Conflicts:
#	src/lib/rx-crsf/devRXLUA.cpp
#	src/lib/tx-crsf/devTXLUA.cpp
# Conflicts:
#	src/lib/LUA/lua.cpp
#	src/lib/tx-crsf/devTXLUA.cpp
# Conflicts:
#	src/lib/CrsfProtocol/CRSFEndpoint.h
Handle and do NOT forward heartbeat messages
Slight adjustments and fix locking/unlocking
Use a mutex to only allow a single thread to be in the OTA telemetry functions
@wimalopaan

Copy link
Copy Markdown

If I configure two serials, e.g. ER8: 1. serial CRSF and 2. serial CRSF on CH8/CH7-Pins, only the 1. serial outputs RC-Channel data. The 2. serial only outputs RC-LinkStats, Telemetry from RX and Telemetry produced on the 1. serial.

I this, the 2. serial should also output RC-channel-data.

@wimalopaan

Copy link
Copy Markdown

Maybe this is related?

Weird observation regarding ELRS V4: I use the following setup: RM ER8 with current master, a TX15 with current master and a TuneRC (rx-as-tx (internal, full-duplex) with current master. Powering on ER8 and TX15 -> all works well (PWM outputs of teh ER( and the CRSF serial data with 420KBaud). Powering on the ER8 with TuneRc, that gets only RC-Channel data at 100Hz, the ER8 outputs at its PWM-outputs the correct signal for all 8 channels (the PWM-duty is correct corresponding to the value that are sent to the TuneRC rx-as-tx). But the output at the Serial is weird: no 420kBaud, well, I can't figure out the baudrate that strange signal is (using a LA). Powercycling the ER8 and turning on the TX15: all is well again. This is reproducible. So, I would think, this is some strange initialistion error on the RX side, since the rx-as-tx transfers all data because the ER8 outputs correct PWM. Any hints???
Side note, same behaviour for HR7E.
The same setup has been working for ELRS V3 since ever 😉

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

Labels

enhancement 🪄 New feature or request V4.0 🍔

Projects

None yet

4 participants