Skip to content

libraries/SD: there is conflict when sharing the same SPI bus in multi tasks (Solved) #8534

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

Closed
LeoYan opened this issue Aug 15, 2023 · 2 comments
Assignees
Milestone

Comments

@LeoYan
Copy link

LeoYan commented Aug 15, 2023

Board

ESP32 Dev Module

Device Description

on the SPI bus connected the follows:

  1. SD card module
  2. OLED 128x32

Hardware Configuration

use the standard SPI pins connect to OLED and SD

Version

v2.0.9

IDE Name

Arduino IDE

Operating System

macOS big sur

Flash frequency

40MHz

PSRAM enabled

no

Upload speed

115200

Description

Issue:

  • libraries/SD: there is conflict when sharing the same SPI bus in multi tasks. The OLED will show messy when check the SD status.

Solution:

libraries/SD: in ff_sd_status() of diskio.c, add ‘AcquireSPI card_locked()’ before to prevent …there is conflict when sharing the same SPI bus in multi tasks


DSTATUS ff_sd_status(uint8_t pdrv)
{

>     ardu_sdcard_t * card = s_cards[pdrv];
>     AcquireSPI card_locked(card);

    if(sdTransaction(pdrv, SEND_STATUS, 0, NULL))
    {
        log_e("Check status failed");
        return STA_NOINIT;
    }
    return s_cards[pdrv]->status;
}

Sketch

task1(){
  while(1){
    OLED.show();
    delay(20);
  }
}

taks2(){
  ...
  f.open("");
  f.read();
  ...
}

Debug Message

- the Backtrace:


0x4010cbb4: sdTransaction(unsigned char, char, unsigned int, unsigned int*) at */build/../components/arduino/libraries/SD/src/sd_diskio.cpp:245
0x4010cbe6: ff_sd_status(unsigned char) at */build/../components/arduino/libraries/SD/src/sd_diskio.cpp:619
0x40112ff6: ff_disk_status at ~/SDK/esp-idf/components/fatfs/diskio/diskio.c:66
0x4011348e: find_volume at ~/SDK/esp-idf/components/fatfs/src/ff.c:3244
0x40114249: f_open at ~/SDK/esp-idf/components/fatfs/src/ff.c:3567
...
0x40203ead: fs::FS::exists(char const*) at */build/../components/arduino/libraries/FS/src/FS.cpp:242


### Other Steps to Reproduce

_No response_

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

- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@LeoYan LeoYan added the Status: Awaiting triage Issue is waiting for triage label Aug 15, 2023
@P-R-O-C-H-Y P-R-O-C-H-Y added Status: Pending Merge Pull Request is ready to be merged and removed Status: Awaiting triage Issue is waiting for triage labels Aug 16, 2023
@P-R-O-C-H-Y P-R-O-C-H-Y self-assigned this Aug 16, 2023
@P-R-O-C-H-Y
Copy link
Member

@LeoYan Thank you from finding this out and providing a fix. I have opened a PR linked to this issue.
This issue will be closed after merging the fix automatically.

@LeoYan
Copy link
Author

LeoYan commented Aug 24, 2023

thanks

@P-R-O-C-H-Y P-R-O-C-H-Y added Status: Solved and removed Status: Pending Merge Pull Request is ready to be merged labels Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants