Skip to content

lock SPI only when writing #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2025
Merged

Conversation

dhalbert
Copy link
Contributor

@dhalbert dhalbert commented Aug 21, 2025

Before this fix, the DotStar object grabbed the SPI lock forever. This is a problem on Espressif boards, which use a FreeRTOS mutex as the lock. See adafruit/circuitpython#10561 (comment) for details.

The fix is only to grab the SPI lock when actually writing. We could do this with adafruit_bus_device, but we don't need other aspects of that library, and we can save space just by doing the locking in the two places where it's needed.

There isn't a reason to test that self._spi.try_lock() succeeds or fails, since it should always succeed. The SPI object is not used by anyone else.

Tested on a FunHouse. It fixes the crash described in adafruit/circuitpython#10520. I also tested to make sure the DotStars are still functional.

@dhalbert dhalbert requested a review from a team August 21, 2025 20:20
Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for figuring this out and finding the fix!

I tested successfully on Fun House 9.2.8 and 10.0.0-beta.2

@FoamyGuy FoamyGuy merged commit 4b0ba64 into adafruit:main Aug 21, 2025
1 check passed
@dhalbert dhalbert deleted the spi-lock-managment branch August 21, 2025 22:33
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.

Only grab SPI lock as needed; do not hold forever Fun House hard crash when send data to IO
2 participants