Skip to content

Clear the FEC encode buffer before use#3473

Merged
pkendall64 merged 1 commit intoExpressLRS:masterfrom
pkendall64:fix-gemini-K-modes
Jan 2, 2026
Merged

Clear the FEC encode buffer before use#3473
pkendall64 merged 1 commit intoExpressLRS:masterfrom
pkendall64:fix-gemini-K-modes

Conversation

@pkendall64
Copy link
Collaborator

@pkendall64 pkendall64 commented Jan 1, 2026

The FEC codec or's the data into the output buffer so it is assumed that the buffer is initialised to zeroes!
I've put a memset as the first line of the function so this is no longer a requirement on the caller.

Copy link
Member

@CapnBry CapnBry left a comment

Choose a reason for hiding this comment

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

Ah! Now I see how I also had fixed it by initing a second, cleared buffer too, thinking that the timing was the problem. I clearly didn't test that correctly because this works and solves all the issues I was seeing yesterday, including the connection dropout when switching to 1:2 for telemboost. I think you also removed the "removed the compiler initialisation of the outbuffer" because we still need to do that, for those 3 extra bytes?

This FEC code needs a little rework I think, but we can save that for a less-pressing time.

  • FECEncode clears the encodedBuffer despite writing to all positions
  • FECEncode needs to clear the FECBuffer (which it could do in its loop) but instead we're doing it with a memset in the caller, to a buffer we also clear before we call it (but we need to because of the 3 trailing bytes needed)
  • The top level buffer is some randomly chosen 32 bytes instead of what it needs to be
  • FECEncode calls HammingTableEncode which itself is just returning an array lookup, leading to extra function calls across units. We really should just move all of hamming into FEC.cpp
  • None of this is in IRAM (FECEncode, HammingTableEncode, the const table), leading me to wonder how important that is at all since so much of the code we call from an ISR isn't.
  • The FEC functions could use some comments about the fact that it can ONLY operate on 8 bytes of data
  • Between all of this it could be a little faster (inlining of hamming functions) and be roughly 200 fewer bytes of code

Copy link
Contributor

@mha1 mha1 left a comment

Choose a reason for hiding this comment

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

Telemetry tested X-Band and 2.4G K packet rates at 1:2 and STD ok.

@pkendall64
Copy link
Collaborator Author

I agree with everything you have said @CapnBry.
Yes I removed the removal of the compiler initiailisation as a remembered the +3 was to have 3 extra zeros for the timeout! Hence the addition of the comment as a reminder to future us.

@pkendall64 pkendall64 merged commit b11eb25 into ExpressLRS:master Jan 2, 2026
26 checks passed
@pkendall64 pkendall64 deleted the fix-gemini-K-modes branch January 3, 2026 00:48
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.

3 participants