Skip to content

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

Closed
@and3rson

Description

@and3rson

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions