You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(rmt5): keep a reused RMT channel enabled between frames (#5359) - #5360
The RMT5 engine ran rmt_enable() before every transmission and rmt_disable() on completion. The next frame then reused the same channel on the same pin, so the pair was pure overhead. A cycle-counter profile on an ESP32-C6 (35 WS2812, forced-RMT legacy path) put it at 13 µs to enable plus 32 µs to disable and release, per frame.
What
A reused channel stays enabled (ChannelState::enabled).
Every RMT handle deletion goes through deleteHwChannel(). It disables the channel first because rmt_del_channel() rejects an enabled channel, and it refuses to delete if the disable fails.
reclaimPin() clears the flag because rebindTxPin() disables the channel for rmt_tx_switch_gpio().
With CONFIG_PM_ENABLE the channel is still disabled after each frame. Otherwise rmt_enable()'s PM lock would block light sleep for as long as a strip exists.
Also fixes a pre-existing double decrement of mDMAChannelsInUse in configureChannel() when callback registration fails.
The RMT mock now enforces IDF's state rules: no double enable, no delete while enabled, and a rebind leaves the channel disabled. It also counts enables.
Evidence
Host RED → GREEN:
Before the fix, RMT5 driver - reused channel stays enabled across frames fails: getEnableCount() is 4 after 4 frames, and the test expects 1.
The extended reused channel reclaims a rerouted pin fails if reclaimPin() does not clear the flag.
ChannelEngineRMTImpl enabled the RMT channel before every transmission
and disabled it on completion, although the next frame reuses the same
channel on the same pin. On an ESP32-C6 (35 WS2812, forced-RMT legacy
path) the pair cost ~45 us per frame.
A reused channel now stays enabled. Every handle deletion goes through
deleteHwChannel(), which disables first because rmt_del_channel()
rejects an enabled channel and refuses to delete if the disable fails.
reclaimPin() clears the flag because rebindTxPin() disables the channel.
With CONFIG_PM_ENABLE the channel is still disabled after each frame so
rmt_enable()'s PM lock does not block light sleep.
Also fixes a pre-existing double decrement of mDMAChannelsInUse when
callback registration fails in configureChannel().
The RMT mock now enforces IDF's state rules (no double enable, no
delete while enabled, rebind leaves the channel disabled) and counts
enables.
ESP32-C6 show(), same session: master 342/356.5/652 us -> 310/333.1/627 us
(min/mean/max). ESP32-S3 image_flash unchanged (local 320383 B).
CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.
Parsing warnings: 1
Validation error: Unrecognized key: "enabled" at "reviews.pre_merge_checks"
If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
No actionable comments were generated in the recent review.
Walkthrough
The RMT5 engine now tracks channel enablement and reuses enabled channels across frames. It disables channels before deletion, including during rebinding, reconfiguration, and cleanup. The mock and tests now check these channel state rules and repeated-frame behavior.
Changes: RMT5 channel reuse
Layer / File(s)
Summary
Track channel state and reuse between frames src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp
The engine tracks whether each channel is enabled and skips repeated enable operations for enabled channels. On completion, it disables a channel only when CONFIG_PM_ENABLE is defined.
Disable channels before rebinding or deletion src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp, src/platforms/esp/32/drivers/rmt/rmt_5/rmt5_peripheral_esp.cpp.hpp
Channel cleanup uses deleteHwChannel to disable an enabled channel before deletion. Pin rebinding clears the engine’s enabled-state tracking.
Enforce and test channel lifecycle rules src/platforms/shared/mock/esp/32/drivers/rmt5_peripheral_mock.h, src/platforms/shared/mock/esp/32/drivers/rmt5_peripheral_mock.cpp.hpp, tests/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp, tests/platforms/shared/mock/esp/32/drivers/rmt5_peripheral_mock.cpp
The mock rejects repeated enables and deletion while enabled, and counts successful enables. Tests cover repeated frames, pin rebinding, and disabling before deletion.
Change: Refactor · Severity of issue fixed: Medium
Possibly related issues
Issue 5356: The change keeps a reused RMT5 channel enabled between frames, addressing the per-frame channel enable and disable cost described in the issue. The issue also describes other per-frame costs that this change does not cover.
Merge Risk: Minimal · up to bd06f
This change keeps a reused RMT channel enabled between frames, which cuts per-frame show() overhead. It still disables the channel after each frame when power management is enabled. No concrete merge-blocking defect was established. One unlikely edge case, a failed disable during pin reconfiguration, behaves the same as before and has no demonstrated trigger.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: the RMT5 driver now keeps a reused channel enabled between frames instead of enabling and disabling it around every frame. The raw summary, objectives, and linked issu…
Linked Issues check
Directly linked issue #5359 has these coding requirements. (1) Keep a reused RMT channel enabled between frames. The change adds ChannelState::enabled and enables a channel only when it is not alrea…
Out of Scope Changes check
Changes map to #5359 except one. The mDMAChannelsInUse double-decrement fix in configureChannel() is a separate pre-existing bug. It is disclosed in the PR description. It sits in the same functio…
Full details: Title check
Explanation
The title names the main change: the RMT5 driver now keeps a reused channel enabled between frames instead of enabling and disabling it around every frame. The raw summary, objectives, and linked issue #5359 all describe this change. The title is specific, uses the conventional commit prefix, and has no vague terms. The title carries a PR number, (#5359), but the objectives reference PR #5360 for the same title, so the number does not match the linked PR. That mismatch is a metadata issue and does not affect the title's relevance to the changeset.
Full details: Linked Issues check
Explanation
Directly linked issue #5359 has these coding requirements. (1) Keep a reused RMT channel enabled between frames. The change adds ChannelState::enabled and enables a channel only when it is not already enabled. Without CONFIG_PM_ENABLE, the channel stays enabled after completion. (2) Disable a channel only before handle deletion, through one helper. deleteHwChannel() disables an enabled channel before rmt_del_channel(). Pin change, encoder failure, reconfiguration, and destructor paths use this helper, and the destructor no longer disables channels directly. (3) The RMT mock enforces IDF state rules and counts enables. enableChannel rejects a second enable, deleteChannel rejects enabled channels, rebindTxPin disables the channel, and getEnableCount() is added. (4) Automated tests cover the behavior. RMT5 driver - reused channel stays enabled across frames checks one enable over four frames. The rerouted-pin test checks that reclaimPin() clears the flag. The PR description adds the CONFIG_PM_ENABLE condition from the PR objectives, and the code path matches it per the change summary. The review used the change summary and PR description, not a line-level diff read, so line-level details are not independently verified.
Full details: Out of Scope Changes check
Explanation
Changes map to #5359 except one. The mDMAChannelsInUse double-decrement fix in configureChannel() is a separate pre-existing bug. It is disclosed in the PR description. It sits in the same function that the channel-state changes touch, so it is a closely related fix and not an unrelated change. The mock, test, and rmt5_peripheral_esp comment changes support the requested mock and state-rule behavior. The ESP32-C6 timing and ESP32-S3 image_flash results are evidence claims, not code changes, and they do not affect this assessment.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Fix failing CI checks
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
github-actionsBot
added
sanitized
Title, body and conversation screened; review text requires separate screening.
and removed
sanitized
Title, body and conversation screened; review text requires separate screening.
labels
Nov 21, 2026
Change in examples/Blink per target. The left number is this PR's image flash / attributed RAM in bytes; the colored delta is the change from the merge base (red ↑ is larger, green ↓ is smaller, Same is unchanged).
Target
FLASH [bytes]
RAM [bytes]
attiny85
2,460 (Same)
136 (Same)
esp32c3
324,350 ($\color{red}\uparrow$ 22)
13,794 (Same)
esp32c6
354,708 (Same)
17,885 (Same)
esp32dev
287,803 ($\color{red}\uparrow$ 16)
18,747 (Same)
esp8266
264,671 (Same)
6,808 (Same)
nrf52840_dk
68,208 (Same)
19,468 (Same)
rp2040
103,212 (Same)
8,624 (Same)
stm32f103c8
22,928 (Same)
1,789 (Same)
teensy41
47,104 (Same)
21,738 (Same)
uno
3,600 (Same)
134 (Same)
No comparison (build missing on one side): esp32s3
github-actionsBot
added
sanitized
Title, body and conversation screened; review text requires separate screening.
and removed
sanitized
Title, body and conversation screened; review text requires separate screening.
labels
Nov 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5359. Part of #5356.
Why
The RMT5 engine ran
rmt_enable()before every transmission andrmt_disable()on completion. The next frame then reused the same channel on the same pin, so the pair was pure overhead. A cycle-counter profile on an ESP32-C6 (35 WS2812, forced-RMT legacy path) put it at 13 µs to enable plus 32 µs to disable and release, per frame.What
ChannelState::enabled).deleteHwChannel(). It disables the channel first becausermt_del_channel()rejects an enabled channel, and it refuses to delete if the disable fails.reclaimPin()clears the flag becauserebindTxPin()disables the channel forrmt_tx_switch_gpio().CONFIG_PM_ENABLEthe channel is still disabled after each frame. Otherwisermt_enable()'s PM lock would block light sleep for as long as a strip exists.mDMAChannelsInUseinconfigureChannel()when callback registration fails.Evidence
RMT5 driver - reused channel stays enabled across framesfails:getEnableCount()is 4 after 4 frames, and the test expects 1.reused channel reclaims a rerouted pinfails ifreclaimPin()does not clear the flag.bash autoresearch esp32c6 --legacy --rmt+ci.autoresearch.test_timing_drift, same session:The AutoResearch run passed 4/4 tests.
image_flash: unchanged locally (320383 B, same as master), so the baseline is not touched.Summary by CodeRabbit