v2.x: Fix RMT mutex unlock using incorrect channel number in rmtDeinit #10034
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.
Description of Change
This pull request fixes crashes caused by
rmtDeinit
function by improving how the RMT channel is handled.int channel = rmt->channel;
at the beginning ofrmtDeinit
.channel
consistently throughout the function, including for mutex operations.This change mirrors the approach used in the other RMT hal functions such as
rmtLoop
,rmtWrite
,rmtWriteBlocking
and others, ensuring consistency across the codebase.Previously, the line
g_rmt_objects[from].channel = 0;
would setrmt->channel
to 0 beforeRMT_MUTEX_UNLOCK(rmt->channel)
was called. This caused the mutex to always be unlocked with an incorrect 0 as channel number, leading to crashes for channels > 0.Tests scenarios
Tested on Lolin32 with Arduino-esp32 core v2.0.16, PlatformIO, VS Code, on Linux.
By calling:
This crashed the ESP32 before the pull request (even with proper error checking), and no longer crashes after the changes of the pull request
Related links
There doesn't seem to be any issues discussing this problem