Skip to content

clockless_rmt_esp32 FastLED.show() hang fix - #1651

Merged
zackees merged 1 commit into
FastLED:masterfrom
davidlmorris:master
Aug 7, 2024
Merged

zackees merged 1 commit into
FastLED:masterfrom
davidlmorris:master

Conversation

@davidlmorris

Copy link
Copy Markdown
Contributor

clockless_rmt_esp32 FastLED.show() infrequent hang fix

See issue 1438 (#1438) and others. FastLED.show() does not return (hangs) very infrequently, sometimes many hours after starting usually while under load.

See https://github.com/davidlmorris/FastLED_Hang_Fix_Demo for a demonstration of this problem (noting that the hang will happen extremely infrequently).

The FastLed RMT driver makes extensive use of interrupts. The comments in the FastLED driver hint at least one per 32 bits of data out. The driver does all the sending in one hit so that even with multiple controllers (as we have in this demo) it is only when the last one is called does it finally does the work. I am uncertain what might happen if only one controller that is not the last one is called. (Something for a future experiment?). On a send, it waits 50 microseconds to signal a start, then starts the channels for each controller. It then sets a semaphore which is then released when the final channel on the final controller is complete. It appears that rarely something goes wrong here, and presumably, that interrupt is swallowed by the Esp32 system. The result is that ESP32RMTController::showPixels() waits forever for the semaphore to be released (which it never will be) so we have a hang. Note that this hang will occur minutes or hours into a run, depending on other factors (like load or power), and is essentially out of the control of the FastLED driver.

The quick and dirty fix is simply to assign some timeout value to the semaphore take rather than portMAX_DELAY (line 204 for version 3.6.0 and line 223 for version 3.7.0).

We do this in the modified FastLED lib forked here by defining FASTLED_RMT_MAX_TICKS_FOR_GTX_SEM to a value like (2000/portTICK_PERIOD_MS) before we call FastLED.h (see clockless_rmt_esp32.h).

Alternatively, we can call GiveGTX_sem(); which has been added to clockless_rmt_esp32.cpp so we can programmatically decide on the wait time.

clockless_rmt_esp32 FastLED.show() hang fix
@zackees

zackees commented Aug 4, 2024

Copy link
Copy Markdown
Member

Thanks for this, looks like a good work around a very detailed description (thanks!)

Looking for @samguyer for final approval.

@samguyer

samguyer commented Aug 5, 2024

Copy link
Copy Markdown
Contributor

@davidlmorris I am running the CICD tests, but this change looks good to me. I have been intending to look more closely at the whole synchronization strategy for the ESP32 driver, but so far I haven't had time. So, this is a welcome fix!

@davidlmorris

Copy link
Copy Markdown
Contributor Author

Hi and thank you both for your comments.

I've been playing with the test code this morning trying to trigger hang-ups more frequently. Doing this seems seems risk 'Guru meditations'. I have some updated versions here https://github.com/davidlmorris/FastLED_Hang_Fix_Demo.

One other thing worth mentioning is that by default this change does nothing. That is, the GTX_sem semaphore by default has a timeout of portMAX_DELAY, so a FastLED program needs to set FASTLED_RMT_MAX_TICKS_FOR_GTX_SEM to something less than that to activate this fix. It might be worth considering reversing this so that we default to say (2000/portTICK_PERIOD_MS) and have an option for portMAX_DELAY since there will be many application developers who are unaware of this issue. (I am happy to make this change if you want - but my suggestion is to fold this in first and fix the default later).

@zackees
zackees merged commit e0a3418 into FastLED:master Aug 7, 2024
softhack007 added a commit to softhack007/FastLED that referenced this pull request Aug 15, 2024
commit 69c3ba1
Author: Zachary Vorhies <[email protected]>
Date:   Mon Aug 12 18:45:19 2024 -0600

    Update README.md

commit 89b7439
Author: Zachary Vorhies <[email protected]>
Date:   Mon Aug 12 18:44:14 2024 -0600

    Update README.md

commit 0aba52b
Author: Zachary Vorhies <[email protected]>
Date:   Mon Aug 12 18:39:11 2024 -0600

    Update README.md

commit 9d7fa8d
Author: Zachary Vorhies <[email protected]>
Date:   Mon Aug 12 18:38:13 2024 -0600

    Update README.md

commit 1ee23e7
Author: Zachary Vorhies <[email protected]>
Date:   Mon Aug 12 17:51:34 2024 -0600

    Update README.md

commit df1c932
Author: Zachary Vorhies <[email protected]>
Date:   Mon Aug 12 17:51:04 2024 -0600

    Update README.md

commit 7b0128a
Author: Zachary Vorhies <[email protected]>
Date:   Mon Aug 12 17:43:54 2024 -0600

    Update README.md

commit ca2a79e
Author: Zachary Vorhies <[email protected]>
Date:   Mon Aug 12 17:31:05 2024 -0600

    Update README.md

commit 1cd2be0
Author: Zachary Vorhies <[email protected]>
Date:   Mon Aug 12 17:29:13 2024 -0600

    Update README.md

commit a2cf6cc
Author: zackees <[email protected]>
Date:   Wed Aug 7 11:36:55 2024 -0700

    Add Arduino Library Lint badge to README.md

commit 5e8c292
Author: zackees <[email protected]>
Date:   Wed Aug 7 11:34:58 2024 -0700

    Add Arduino Library Lint job to workflow

commit d216435
Author: zackees <[email protected]>
Date:   Wed Aug 7 11:33:48 2024 -0700

    fix arduino_library_lint.yml issue

commit c77eb3a
Author: zackees <[email protected]>
Date:   Wed Aug 7 11:30:31 2024 -0700

    Add arduino library lint workflow for linting Arduino code

commit f004f57
Author: Zachary Vorhies <[email protected]>
Date:   Wed Aug 7 11:19:06 2024 -0700

    Update release_notes.md

commit 6eb07ce
Author: Zachary Vorhies <[email protected]>
Date:   Wed Aug 7 11:13:31 2024 -0700

    Update release_notes.md

commit 0c18319
Author: zackees <[email protected]>
Date:   Wed Aug 7 11:09:18 2024 -0700

    release 3.7.1 bugfix

commit e0a3418
Merge: 3c7197e 59d7404
Author: Zachary Vorhies <[email protected]>
Date:   Wed Aug 7 11:00:46 2024 -0700

    Merge pull request FastLED#1651 from davidlmorris/master

    clockless_rmt_esp32 FastLED.show() hang fix

    I'm doing a bugfix release and including this library to address the hang in the RMT driver.

    If there are problems then we can just do another release.

commit 3c7197e
Author: Zachary Vorhies <[email protected]>
Date:   Wed Aug 7 10:49:40 2024 -0700

    Update RELEASE.md

commit a6876a8
Author: Zachary Vorhies <[email protected]>
Date:   Wed Aug 7 10:46:48 2024 -0700

    Update RELEASE.md

commit c1e9b30
Author: Zachary Vorhies <[email protected]>
Date:   Wed Aug 7 10:45:22 2024 -0700

    Create RELEASE.md

commit 85650d9
Merge: 4444758 1e2cdd4
Author: Zachary Vorhies <[email protected]>
Date:   Sun Aug 4 20:06:45 2024 -0700

    Merge pull request FastLED#1652 from FastLED/fix-esp32-s3-rmt-esp-idf-5

    adds support for ESP32S3 RMT for esp-idf 5.X.X

commit 1e2cdd4
Author: Zachary Vorhies <[email protected]>
Date:   Sun Aug 4 18:57:52 2024 -0600

    adds support for ESP32S3 RMT for esp-idf 5.X.X

commit 59d7404
Author: David L. Morris <[email protected]>
Date:   Sun Aug 4 11:12:23 2024 +0800

    clockless_rmt_esp32 FastLED.show() hang fix

    clockless_rmt_esp32 FastLED.show() hang fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants