Skip to content
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

SD.begin() calls functions that don't acquire SPI and thus is not thread-safe #9438

Closed
1 task done
and3rson opened this issue Mar 30, 2024 · 1 comment · Fixed by #9468
Closed
1 task done

SD.begin() calls functions that don't acquire SPI and thus is not thread-safe #9438

and3rson opened this issue Mar 30, 2024 · 1 comment · Fixed by #9468
Assignees
Labels
Area: Libraries Issue is related to Library support. Status: Test needed Issue needs testing

Comments

@and3rson
Copy link
Contributor

and3rson commented Mar 30, 2024

Board

ESP32-S3

Device Description

ESP32-S3-WROOM-1-N16R8

Hardware Configuration

TFT & SD card sharing SPI bus (SPI modes 3 and 0)

Version

v2.0.14

IDE Name

PlatformIO

Operating System

n/a

Flash frequency

40MHz

PSRAM enabled

yes

Upload speed

115200

Description

When calling SD.begin() from one task while drawing to TFT display from another task, visual glitches occur on display due to sdcard_init not instancing AcquireSPI.

sdcard_mount, on the other hand, does acquire SPI.

Temporary workaround to still use SD card, albeit without high-level interface:

SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
uint8_t pdrv = sdcard_init(SDCARD_CS, &SPI, 4000000);
SPI.endTransaction();
sdcard_mount(pdrv, "/sd", 5, false);

Same behavior is observed with sdcard_uninit. Suggested fix is to add AcquireSPI lock(card) into sdcard_mount and sdcard_uninit.

Sketch

n/a

Debug Message

n/a

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@and3rson and3rson added the Status: Awaiting triage Issue is waiting for triage label Mar 30, 2024
@P-R-O-C-H-Y P-R-O-C-H-Y self-assigned this Apr 2, 2024
@P-R-O-C-H-Y P-R-O-C-H-Y added Status: Test needed Issue needs testing Area: Libraries Issue is related to Library support. and removed Status: Awaiting triage Issue is waiting for triage labels Apr 2, 2024
@P-R-O-C-H-Y
Copy link
Member

Hi @and3rson, I have been testing that and the only place where AcquireSPI lock is missing is in the sdcard_uninit.
I have opened a PR so you can take a look. Can you also try with that change if that solves your issue? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Libraries Issue is related to Library support. Status: Test needed Issue needs testing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants