Skip to content

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

Closed
@LeoYan

Description

@LeoYan

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions