Skip to content

The SD is not locked on the SPI interface #11310

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

Open
1 task done
Sail-211010 opened this issue Apr 28, 2025 · 3 comments
Open
1 task done

The SD is not locked on the SPI interface #11310

Sail-211010 opened this issue Apr 28, 2025 · 3 comments
Labels
Status: Awaiting Response awaiting a response from the author

Comments

@Sail-211010
Copy link
Contributor

Board

ESP32-S3

Device Description

ESP32 series products

Hardware Configuration

Run the screen and the SD card simultaneously on one SPI

Version

latest stable Release (if not listed below)

IDE Name

Arduino IDE

Operating System

Windows 10

Flash frequency

80MHz

PSRAM enabled

yes

Upload speed

115200

Description

The underlying SD interface calls are all non-locking. Running both the screen and the SD card on the same SPI bus can only be managed with mutex-like operations at the upper program level. However, doing so at the upper level causes the screen to freeze when reading or writing to the SD card. Will this be optimized in the future? This is because SD mainly uses official libraries, and if locks are not provided, controlling this at the upper level is not very user-friendly.

Image

Image

Sketch

#define SPI_WRITE(_dat)         SPI.transfer(_dat)
#define SPI_WRITE_Word(_dat)    SPI.transfer16(_dat)

void SPI_Init()
{
  SPI.begin(EXAMPLE_PIN_NUM_SCLK,EXAMPLE_PIN_NUM_MISO,EXAMPLE_PIN_NUM_MOSI); 
}
void LCD_WriteCommand(uint8_t Cmd)  
{ 
  SPI.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
  digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);  
  digitalWrite(EXAMPLE_PIN_NUM_LCD_DC, LOW); 
  SPI_WRITE(Cmd);
  digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);  
  SPI.endTransaction();
}
void LCD_WriteData(uint8_t Data) 
{ 
  SPI.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
  digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);  
  digitalWrite(EXAMPLE_PIN_NUM_LCD_DC, HIGH);  
  SPI_WRITE(Data);  
  digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);  
  SPI.endTransaction();
}    
void LCD_WriteData_Word(uint16_t Data)
{
  SPI.beginTransaction(SPISettings(SPIFreq, MSBFIRST, SPI_MODE0));
  digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, LOW);  
  digitalWrite(EXAMPLE_PIN_NUM_LCD_DC, HIGH); 
  SPI_WRITE_Word(Data);
  digitalWrite(EXAMPLE_PIN_NUM_LCD_CS, HIGH);  
  SPI.endTransaction();
}   













  if (SD.begin(SD_CS, SPI, 2000000, "/sd", 5, true)) {
    printf("SD card initialization successful!\r\n");
  } else {
    printf("SD card initialization failed!\r\n");
  }
  uint8_t cardType = SD.cardType();
  if(cardType == CARD_NONE){
    printf("No SD card attached\r\n");
    return false;
  }

Debug Message

NULL

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.
@Sail-211010 Sail-211010 added the Status: Awaiting triage Issue is waiting for triage label Apr 28, 2025
@me-no-dev
Copy link
Member

Actually this is not true. The sd* functions are not directly called. Start looking after line 440 in sd_diskio.cpp to see the actual functions being called and where does the locking actually happen. There is something else going on on your end and if you want us to have a further look, please provide a minimal compilable example to reproduce

@me-no-dev me-no-dev added Status: Awaiting Response awaiting a response from the author and removed Status: Awaiting triage Issue is waiting for triage labels May 13, 2025
@Sail-211010
Copy link
Contributor Author

LVGL_Arduino-Half-B.zip
For example, in this case, because the screen updates in real-time, the SD card cannot be inserted when it is being called.

@Sail-211010
Copy link
Contributor Author

Sail-211010 commented May 13, 2025

@me-no-dev You can keep obtaining the capacity of the SD card in the loop, and it will fail to obtain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting Response awaiting a response from the author
Projects
None yet
Development

No branches or pull requests

2 participants