Skip to content

fix: SPI transactions on esp32#20

Merged
cparata merged 1 commit intostm32duino:mainfrom
rpocklin:fix-esp32-spi-transactions
Apr 14, 2026
Merged

fix: SPI transactions on esp32#20
cparata merged 1 commit intostm32duino:mainfrom
rpocklin:fix-esp32-spi-transactions

Conversation

@rpocklin
Copy link
Copy Markdown

@rpocklin rpocklin commented Apr 14, 2026

Summary
This is an issue I was facing using this sensor on ESP32 and was recently raised by another person also: (#19)

On platforms where beginTransaction() acquires a mutex (e.g. ESP32), failing to call endTransaction() causes the second SPI call to deadlock.

IO_Read and IO_Write both called beginTransaction() but never released the bus, causing the MCU to freeze during init() firmware upload.

STM32 is unaffected as beginTransaction() is a no-op (ie. this is a non-breaking aka backwards compatible change).

This PR fixes/implements the following:

  • Bug / Feature - Add tested support for esp32 by ensuring endTransaction() is called when using SPI

Motivation
This library works perfectly on esp32 once this issue is fixed, without it, it hangs on the second transaction due to the mutex.

Validation
Tested with demo sketch in both PlatformIO v6.1.19 and Arduino IDE v2.3.8.

Closing issues
Closes #19

Copy link
Copy Markdown
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

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

Sounds good.

@fpistm fpistm requested a review from cparata April 14, 2026 07:48
@fpistm fpistm added the fix 🩹 Bug fix label Apr 14, 2026
@github-project-automation github-project-automation bot moved this from In progress to Reviewer approved in STM32duino libraries Apr 14, 2026
@cparata cparata merged commit a0146fc into stm32duino:main Apr 14, 2026
3 checks passed
@github-project-automation github-project-automation bot moved this from Reviewer approved to Done in STM32duino libraries Apr 14, 2026
@cparata
Copy link
Copy Markdown
Contributor

cparata commented Apr 14, 2026

Hi @rpocklin ,
Thank you for the PR! I released a new version of the library including this fix.
Best Regards,
Carlo

@rpocklin rpocklin deleted the fix-esp32-spi-transactions branch April 14, 2026 08:21
@rpocklin
Copy link
Copy Markdown
Author

Thanks, I just upgraded to it now - appreciate you merging it so quickly 🚀

You may have to do a separate publish for the new library version to reach the PlatformIO registry:
pio pkg publish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix 🩹 Bug fix

Projects

Development

Successfully merging this pull request may close these issues.

SPI beginTransaction() needs endTransaction() after transfer

3 participants