Skip to content

RGB LED Fixes - #3536

Merged
pkendall64 merged 4 commits into
ExpressLRS:masterfrom
pkendall64:next/rgb-fixes
Mar 8, 2026
Merged

pkendall64 merged 4 commits into
ExpressLRS:masterfrom
pkendall64:next/rgb-fixes

Conversation

@pkendall64

@pkendall64 pkendall64 commented Feb 13, 2026 •

Copy link
Copy Markdown
Collaborator

Issue

When defining more than 8 LEDs the RX will crash

Problem

The DMA buffers were incorrectly allocated in the RGB code.

Solution

  1. Fix the code that allocates the DMA buffers for the RGB (I2S) driver.
  2. Increase the buffer size to a fixed 2KB size.
  3. Calculate the maximum number of LEDs that will fit in the buffer and hard limit to that.
    • 42 RGB LEDs is the maximum, cause... you know.

Fixes #3338

@CapnBry CapnBry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wowie, 48 bytes per LED? That's insane! Not your problem but golly, that's so fat for the 3 bytes each LED actually needs to receive.

In ESP32LedDriver::ESP32LedDriver() you calculate out_buffer_size and use that for the malloc, but in the Begin() you tell it to use 2x 1KB buffers and the max number of LEDs is limited to the entire span of both buffers. I'm not familiar with the I2S peripheral but can you quickly explain how the limit for a single update can span 2 buffers and why this wouldn't use the same size as what there is to send?

@pkendall64

Copy link
Copy Markdown
Collaborator Author

In ESP32LedDriver::ESP32LedDriver() you calculate out_buffer_size and use that for the malloc, but in the Begin() you tell it to use 2x 1KB buffers and the max number of LEDs is limited to the entire span of both buffers. I'm not familiar with the I2S peripheral but can you quickly explain how the limit for a single update can span 2 buffers and why this wouldn't use the same size as what there is to send?

For the I2S driver we have to tell it the maximum amount of memory to allocate as internal DMA buffer so we tell it 2 x 1KB buffers. The maximum single buffer is 1KB. We could calculate as out_buffer_size if it's less than 1KB otherwise 2 buffers of half the out_buffer_size + 4

@CapnBry

CapnBry commented Feb 23, 2026

Copy link
Copy Markdown
Member

In ESP32LedDriver::ESP32LedDriver() you calculate out_buffer_size and use that for the malloc, but in the Begin() you tell it to use 2x 1KB buffers and the max number of LEDs is limited to the entire span of both buffers. I'm not familiar with the I2S peripheral but can you quickly explain how the limit for a single update can span 2 buffers and why this wouldn't use the same size as what there is to send?

For the I2S driver we have to tell it the maximum amount of memory to allocate as internal DMA buffer so we tell it 2 x 1KB buffers. The maximum single buffer is 1KB. We could calculate as out_buffer_size if it's less than 1KB otherwise 2 buffers of half the out_buffer_size + 4

Thanks for the explanation and I am sorry if I am being a bit dense about this, but in ::Show() we write our full buffer to i2s, which can be twice the size of the buffer we told i2s to allocate for its internal DMA. You're saying this is OK and it will split our ~2KB write() call into 2x 1024 byte internal DMA buffers? That sounds fishy to me.

@pkendall64

pkendall64 commented Feb 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

Yup, that's exactly what it does. Thats why theres an extra 4 bytes added as it appends a pointer to the next internal DMA buffer to the end of the first one.
I've tested this with a string of 48 LEDs, and with the current constraints 42 of them light up!

@CapnBry CapnBry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested on an RX (BAYCK) and a TX (Bandit) and it still works, I did not try a long ARGBLED string to the limit.

I was skeptical of the DMA split but that's pretty neat, appreciate the discussion.

@pkendall64
pkendall64 merged commit 1de30f7 into ExpressLRS:master Mar 8, 2026
26 checks passed
@pkendall64
pkendall64 deleted the next/rgb-fixes branch March 8, 2026 07:04
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.

Using more than 8 external WS2812b leds makes ESP32 receiver stuck in boot/startup

3 participants