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

ESP32 using SD card with HSPI works at full speed under 1.0.6, fails or runs very slowly under 2.0.2 #6295

Closed
1 task done
avillacis opened this issue Feb 16, 2022 · 5 comments
Assignees

Comments

@avillacis
Copy link

Board

ESP32 Dev Module

Device Description

YUBOX Node

Hardware Configuration

#define SD_SCK GPIO_NUM_14
#define SD_MISO GPIO_NUM_12
#define SD_MOSI GPIO_NUM_13
#define SD_SS GPIO_NUM_15

Version

v2.0.2

IDE Name

Arduino IDE 1.8.19

Operating System

Fedora 35 x86_64

Flash frequency

80 MHz

PSRAM enabled

no

Upload speed

921600

Description

When using the sketch provided below using version 2.0.2 of Arduino-ESP32, the attempted I/O to the SD card is faulty or very slow, and riddled with error messages. Under 1.0.6, the same sketch runs correctly on the same board and the same SD card.

Under a different board using ESP32-S2 the issue is even worse - the card completely fails to mount. However, this report is ESP32 only because only ESP32 is testable under both 1.0.6 and 2.0.2.

The sketch initializes an SPI object in HSPI mode, with the pins shown as follows:
#define SD_SCK GPIO_NUM_14
#define SD_MISO GPIO_NUM_12
#define SD_MOSI GPIO_NUM_13
#define SD_SS GPIO_NUM_15

Other than that, and the conditional defines for ESP32-S2, the sketch is the same as the official example for testing SD card I/O in SPI mode. Under both 1.0.6 and 2.0.2 the sketch was compiled in full verbose mode.

Sketch

/*
 * Connect the SD card to the following pins:
 *
 * SD Card | ESP32
 *    D2       -
 *    D3       SS
 *    CMD      MOSI
 *    VSS      GND
 *    VDD      3.3V
 *    CLK      SCK
 *    VSS      GND
 *    D0       MISO
 *    D1       -
 */
#include "FS.h"
#include "SD.h"
#include "SPI.h"

#if CONFIG_IDF_TARGET_ESP32

// Pines SD para YUBOX Node
#define SD_SCK  GPIO_NUM_14
#define SD_MISO GPIO_NUM_12
#define SD_MOSI GPIO_NUM_13
#define SD_SS   GPIO_NUM_15

#elif CONFIG_IDF_TARGET_ESP32S2

// Pines SD para YUBOX One
#define SD_SCK  GPIO_NUM_33
#define SD_MISO GPIO_NUM_39
#define SD_MOSI GPIO_NUM_38
#define SD_SS   GPIO_NUM_42

#else
#error Pines de control no definidos para board objetivo!
#endif

SPIClass * hspi = NULL;

void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    Serial.printf("Listing directory: %s\r\n", dirname);

    File root = fs.open(dirname);
    if(!root){
        Serial.println("Failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
            Serial.print("  DIR : ");
            Serial.println(file.name());
            if(levels){
                listDir(fs, file.path(), levels -1);
//                listDir(fs, file.name(), levels -1);
            }
        } else {
            Serial.print("  FILE: ");
            Serial.print(file.name());
            Serial.print("  SIZE: ");
            Serial.println(file.size());
        }
        file = root.openNextFile();
    }
}

void createDir(fs::FS &fs, const char * path){
    Serial.printf("Creating Dir: %s\r\n", path);
    if(fs.mkdir(path)){
        Serial.println("Dir created");
    } else {
        Serial.println("mkdir failed");
    }
}

void removeDir(fs::FS &fs, const char * path){
    Serial.printf("Removing Dir: %s\r\n", path);
    if(fs.rmdir(path)){
        Serial.println("Dir removed");
    } else {
        Serial.println("rmdir failed");
    }
}

void readFile(fs::FS &fs, const char * path){
    Serial.printf("Reading file: %s\r\n", path);

    File file = fs.open(path);
    if(!file){
        Serial.println("Failed to open file for reading");
        return;
    }

    Serial.print("Read from file: ");
    while(file.available()){
        Serial.write(file.read());
    }
    file.close();
}

void writeFile(fs::FS &fs, const char * path, const char * message){
    Serial.printf("Writing file: %s\r\n", path);

    File file = fs.open(path, FILE_WRITE);
    if(!file){
        Serial.println("Failed to open file for writing");
        return;
    }
    if(file.print(message)){
        Serial.println("File written");
    } else {
        Serial.println("Write failed");
    }
    file.close();
}

void appendFile(fs::FS &fs, const char * path, const char * message){
    Serial.printf("Appending to file: %s\r\n", path);

    File file = fs.open(path, FILE_APPEND);
    if(!file){
        Serial.println("Failed to open file for appending");
        return;
    }
    if(file.print(message)){
        Serial.println("Message appended");
    } else {
        Serial.println("Append failed");
    }
    file.close();
}

void renameFile(fs::FS &fs, const char * path1, const char * path2){
    Serial.printf("Renaming file %s to %s\r\n", path1, path2);
    if (fs.rename(path1, path2)) {
        Serial.println("File renamed");
    } else {
        Serial.println("Rename failed");
    }
}

void deleteFile(fs::FS &fs, const char * path){
    Serial.printf("Deleting file: %s\r\n", path);
    if(fs.remove(path)){
        Serial.println("File deleted");
    } else {
        Serial.println("Delete failed");
    }
}

void testFileIO(fs::FS &fs, const char * path){
    File file = fs.open(path);
    static uint8_t buf[512];
    size_t len = 0;
    uint32_t start = millis();
    uint32_t end = start;
    if(file){
        len = file.size();
        size_t flen = len;
        start = millis();
        while(len){
            size_t toRead = len;
            if(toRead > 512){
                toRead = 512;
            }
            file.read(buf, toRead);
            len -= toRead;
        }
        end = millis() - start;
        Serial.printf("%u bytes read for %u ms\r\n", flen, end);
        file.close();
    } else {
        Serial.println("Failed to open file for reading");
    }


    file = fs.open(path, FILE_WRITE);
    if(!file){
        Serial.println("Failed to open file for writing");
        return;
    }

    size_t i;
    start = millis();
    for(i=0; i<2048; i++){
        file.write(buf, 512);
    }
    end = millis() - start;
    Serial.printf("%u bytes written for %u ms\r\n", 2048 * 512, end);
    file.close();
}

void setup(){
    Serial.begin(115200);
    delay(2000);

    hspi = new SPIClass(/*HSPI*/);
    hspi->begin(SD_SCK, SD_MISO, SD_MOSI, SD_SS);
}

//#define SD_SPI_FREQ 1000000
#define SD_SPI_FREQ 4000000
//#define SD_SPI_FREQ 25000000

bool testSD()
{
    Serial.printf("Trying mount of SD card at freq %u...\r\n", SD_SPI_FREQ);
    if(!SD.begin(SD_SS, *hspi, SD_SPI_FREQ)) {
        Serial.println("Card Mount Failed");
        return false;
    }
    uint8_t cardType = SD.cardType();

    if(cardType == CARD_NONE){
        Serial.println("No SD card attached");
        return false;
    }

    Serial.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        Serial.println("MMC");
    } else if(cardType == CARD_SD){
        Serial.println("SDSC");
    } else if(cardType == CARD_SDHC){
        Serial.println("SDHC");
    } else {
        Serial.println("UNKNOWN");
    }

    uint64_t cardSize = SD.cardSize() / (1024 * 1024);
    Serial.printf("SD Card Size: %lluMB\r\n", cardSize);

    listDir(SD, "/", 0);
    createDir(SD, "/mydir");
    listDir(SD, "/", 0);
    removeDir(SD, "/mydir");
    listDir(SD, "/", 2);
    writeFile(SD, "/hello.txt", "Hello ");
    appendFile(SD, "/hello.txt", "World!\n");
    readFile(SD, "/hello.txt");
    deleteFile(SD, "/foo.txt");
    renameFile(SD, "/hello.txt", "/foo.txt");
    readFile(SD, "/foo.txt");
    testFileIO(SD, "/test.txt");
    Serial.printf("Total space: %lluMB\r\n", SD.totalBytes() / (1024 * 1024));
    Serial.printf("Used space: %lluMB\r\n", SD.usedBytes() / (1024 * 1024));

    return true;
}

void loop(){
  bool ok;

  ok = testSD();
  if (ok) {
    Serial.println("OK");
  } else {
    Serial.println("FAIL");
  }
  delay(5000);
}

Debug Message

FAULTY BEHAVIOR UNDER 2.0.2 HERE:
--- Miniterm on /dev/ttyUSB0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Trying mount of SD card at freq 4000000...
[  2512][W][sd_diskio.cpp:104] sdWait(): Wait Failed
[  2512][W][sd_diskio.cpp:512] ff_sd_initialize(): sdWait fail ignored, card initialize continues
[  2514][W][sd_diskio.cpp:180] sdCommand(): crc error
[  2618][W][sd_diskio.cpp:186] sdCommand(): token error [59] 0x5
SD Card Type: SDSC
SD Card Size: 486MB
Listing directory: /
[  2698][W][sd_diskio.cpp:174] sdCommand(): no token received
[  2798][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x7
[  2798][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  2798][W][sd_diskio.cpp:174] sdCommand(): no token received
[  2904][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Creating Dir: /mydir
[  2910][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  2910][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  2912][W][sd_diskio.cpp:174] sdCommand(): no token received
[  3017][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  3017][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  3017][W][sd_diskio.cpp:174] sdCommand(): no token received
[  3122][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  3122][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
mkdir failed
Listing directory: /
[  3134][W][sd_diskio.cpp:174] sdCommand(): no token received
[  3234][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  3234][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  3234][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  3240][W][sd_diskio.cpp:174] sdCommand(): no token received
[  3345][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Removing Dir: /mydir
[  3351][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  3351][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  3353][W][sd_diskio.cpp:174] sdCommand(): no token received
[  3458][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  3458][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  3458][E][vfs_api.cpp:235] rmdir(): /mydir does not exists or is a file
rmdir failed
Listing directory: /
[  3476][W][sd_diskio.cpp:174] sdCommand(): no token received
[  3576][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  3576][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  3576][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  3582][W][sd_diskio.cpp:174] sdCommand(): no token received
[  3687][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Writing file: /hello.txt
[  3693][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  3693][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  3695][W][sd_diskio.cpp:174] sdCommand(): no token received
[  3800][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  3800][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  3800][W][sd_diskio.cpp:174] sdCommand(): no token received
[  3905][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  3905][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  3905][W][sd_diskio.cpp:174] sdCommand(): no token received
[  4010][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  4010][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  4010][E][vfs_api.cpp:308] VFSFileImpl(): fopen(/sd/hello.txt) failed
Failed to open file for writing
Appending to file: /hello.txt
[  4028][W][sd_diskio.cpp:174] sdCommand(): no token received
[  4128][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  4128][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  4128][W][sd_diskio.cpp:174] sdCommand(): no token received
[  4233][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  4233][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  4233][W][sd_diskio.cpp:174] sdCommand(): no token received
[  4338][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  4338][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  4338][W][sd_diskio.cpp:174] sdCommand(): no token received
[  4443][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  4443][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  4443][E][vfs_api.cpp:308] VFSFileImpl(): fopen(/sd/hello.txt) failed
Failed to open file for appending
Reading file: /hello.txt
[  4461][W][sd_diskio.cpp:174] sdCommand(): no token received
[  4561][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  4561][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  4561][W][sd_diskio.cpp:174] sdCommand(): no token received
[  4666][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  4666][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  4666][E][vfs_api.cpp:102] open(): /sd/hello.txt does not exist, no permits for creation
Failed to open file for reading
Deleting file: /foo.txt
[  4686][W][sd_diskio.cpp:174] sdCommand(): no token received
[  4786][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  4786][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  4786][W][sd_diskio.cpp:174] sdCommand(): no token received
[  4891][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  4891][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  4891][E][vfs_api.cpp:173] remove(): /foo.txt does not exists or is directory
Delete failed
Renaming file /hello.txt to /foo.txt
[  4910][W][sd_diskio.cpp:174] sdCommand(): no token received
[  5010][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  5010][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  5010][W][sd_diskio.cpp:174] sdCommand(): no token received
[  5115][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  5115][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  5115][E][vfs_api.cpp:134] rename(): /hello.txt does not exists
Rename failed
Reading file: /foo.txt
[  5132][W][sd_diskio.cpp:174] sdCommand(): no token received
[  5232][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  5232][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  5232][W][sd_diskio.cpp:174] sdCommand(): no token received
[  5337][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  5337][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  5337][E][vfs_api.cpp:102] open(): /sd/foo.txt does not exist, no permits for creation
Failed to open file for reading
[  5356][W][sd_diskio.cpp:174] sdCommand(): no token received
[  5456][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  5456][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  5456][W][sd_diskio.cpp:174] sdCommand(): no token received
[  5561][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  5561][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  5561][E][vfs_api.cpp:102] open(): /sd/test.txt does not exist, no permits for creation
Failed to open file for reading
[  5580][W][sd_diskio.cpp:174] sdCommand(): no token received
[  5680][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  5680][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  5680][W][sd_diskio.cpp:174] sdCommand(): no token received
[  5785][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  5785][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  5785][W][sd_diskio.cpp:174] sdCommand(): no token received
[  5890][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  5890][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  5890][W][sd_diskio.cpp:174] sdCommand(): no token received
[  5995][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  5995][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[  5995][E][vfs_api.cpp:308] VFSFileImpl(): fopen(/sd/test.txt) failed
Failed to open file for writing
[  6013][W][sd_diskio.cpp:174] sdCommand(): no token received
[  6113][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[  6113][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
Total space: 0MB
[  6123][W][sd_diskio.cpp:174] sdCommand(): no token received
[  6223][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Used space: 486MB
OK
Trying mount of SD card at freq 4000000...
SD Card Type: SDSC
SD Card Size: 486MB
Listing directory: /
[ 11223][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 11227][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 11232][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 11238][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 11343][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Creating Dir: /mydir
[ 11343][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 11345][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 11351][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 11456][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 11456][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 11456][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 11561][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 11561][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
mkdir failed
Listing directory: /
[ 11573][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 11673][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 11673][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 11673][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 11679][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 11784][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Removing Dir: /mydir
[ 11790][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 11790][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 11792][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 11897][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 11897][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 11897][E][vfs_api.cpp:235] rmdir(): /mydir does not exists or is a file
rmdir failed
Listing directory: /
[ 11915][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 12015][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 12015][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 12015][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 12021][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 12126][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Writing file: /hello.txt
[ 12132][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 12132][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 12134][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 12239][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 12239][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 12239][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 12344][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 12344][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 12344][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 12449][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 12449][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 12449][E][vfs_api.cpp:308] VFSFileImpl(): fopen(/sd/hello.txt) failed
Failed to open file for writing
Appending to file: /hello.txt
[ 12467][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 12567][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 12567][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 12567][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 12672][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 12672][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 12672][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 12777][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 12777][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 12777][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 12882][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 12882][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 12882][E][vfs_api.cpp:308] VFSFileImpl(): fopen(/sd/hello.txt) failed
Failed to open file for appending
Reading file: /hello.txt
[ 12900][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 13000][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 13000][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 13000][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 13105][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 13105][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 13105][E][vfs_api.cpp:102] open(): /sd/hello.txt does not exist, no permits for creation
Failed to open file for reading
Deleting file: /foo.txt
[ 13124][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 13225][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 13225][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 13225][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 13330][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 13330][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 13330][E][vfs_api.cpp:173] remove(): /foo.txt does not exists or is directory
Delete failed
Renaming file /hello.txt to /foo.txt
[ 13349][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 13449][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 13449][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 13449][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 13554][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 13554][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 13554][E][vfs_api.cpp:134] rename(): /hello.txt does not exists
Rename failed
Reading file: /foo.txt
[ 13571][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 13671][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 13671][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 13671][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 13776][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 13776][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 13776][E][vfs_api.cpp:102] open(): /sd/foo.txt does not exist, no permits for creation
Failed to open file for reading
[ 13795][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 13895][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 13895][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 13895][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 14000][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 14000][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 14000][E][vfs_api.cpp:102] open(): /sd/test.txt does not exist, no permits for creation
Failed to open file for reading
[ 14019][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 14119][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 14119][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 14119][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 14224][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 14224][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 14224][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 14329][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 14329][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 14329][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 14434][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 14434][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 14434][E][vfs_api.cpp:308] VFSFileImpl(): fopen(/sd/test.txt) failed
Failed to open file for writing
[ 14452][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 14552][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Total space: 486MB
[ 14552][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Used space: 486MB
OK
Trying mount of SD card at freq 4000000...
SD Card Type: SDSC
SD Card Size: 486MB
Listing directory: /
[ 19564][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 19568][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 19573][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 19579][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 19684][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Creating Dir: /mydir
[ 19684][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 19686][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 19692][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 19797][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 19797][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 19797][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 19902][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 19902][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
mkdir failed
Listing directory: /
[ 19914][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 20014][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 20014][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 20014][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 20020][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 20125][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Removing Dir: /mydir
[ 20131][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 20131][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 20133][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 20238][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 20238][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 20238][E][vfs_api.cpp:235] rmdir(): /mydir does not exists or is a file
rmdir failed
Listing directory: /
[ 20256][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 20356][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 20356][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 20356][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 20362][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 20467][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Writing file: /hello.txt
[ 20473][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 20473][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 20475][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 20580][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 20580][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 20580][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 20685][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 20685][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 20685][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 20790][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 20790][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 20790][E][vfs_api.cpp:308] VFSFileImpl(): fopen(/sd/hello.txt) failed
Failed to open file for writing
Appending to file: /hello.txt
[ 20808][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 20908][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 20908][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 20908][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 21013][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 21013][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 21013][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 21118][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 21118][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 21118][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 21223][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 21223][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 21223][E][vfs_api.cpp:308] VFSFileImpl(): fopen(/sd/hello.txt) failed
Failed to open file for appending
Reading file: /hello.txt
[ 21241][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 21341][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 21341][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 21341][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 21446][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 21446][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 21446][E][vfs_api.cpp:102] open(): /sd/hello.txt does not exist, no permits for creation
Failed to open file for reading
Deleting file: /foo.txt
[ 21465][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 21566][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 21566][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 21566][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 21671][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 21671][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 21671][E][vfs_api.cpp:173] remove(): /foo.txt does not exists or is directory
Delete failed
Renaming file /hello.txt to /foo.txt
[ 21690][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 21790][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 21790][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 21790][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 21895][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 21895][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 21895][E][vfs_api.cpp:134] rename(): /hello.txt does not exists
Rename failed
Reading file: /foo.txt
[ 21912][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 22012][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 22012][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 22012][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 22117][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 22117][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 22117][E][vfs_api.cpp:102] open(): /sd/foo.txt does not exist, no permits for creation
Failed to open file for reading
[ 22136][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 22236][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 22236][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 22236][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 22341][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 22341][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 22341][E][vfs_api.cpp:102] open(): /sd/test.txt does not exist, no permits for creation
Failed to open file for reading
[ 22360][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 22460][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 22460][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 22460][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 22565][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 22565][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 22565][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 22670][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 22670][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 22670][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 22775][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
[ 22775][W][sd_diskio.cpp:186] sdCommand(): token error [17] 0x5
[ 22775][E][vfs_api.cpp:308] VFSFileImpl(): fopen(/sd/test.txt) failed
Failed to open file for writing
[ 22793][W][sd_diskio.cpp:174] sdCommand(): no token received
[ 22893][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Total space: 486MB
[ 22893][W][sd_diskio.cpp:186] sdCommand(): token error [13] 0x5
Used space: 486MB
OK


TOLERABLE BEHAVIOR UNDER 1.0.6 HERE:
--- Miniterm on /dev/ttyUSB0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Trying mount of SD card at freq 4000000...
[W][sd_diskio.cpp:101] sdWait(): Wait Failed
[E][sd_diskio.cpp:123] sdSelectCard(): Select Failed
[W][sd_diskio.cpp:175] sdCommand(): crc error
[W][sd_diskio.cpp:181] sdCommand(): token error [59] 0x5
SD Card Type: SDSC
SD Card Size: 486MB
Listing directory: /
  FILE: /test.txt  SIZE: 0
  FILE: /foo.txt  SIZE: 13
Creating Dir: /mydir
Dir created
Listing directory: /
  FILE: /test.txt  SIZE: 0
  FILE: /foo.txt  SIZE: 13
  DIR : /mydir
Removing Dir: /mydir
Dir removed
Listing directory: /
  FILE: /test.txt  SIZE: 0
  FILE: /foo.txt  SIZE: 13
Writing file: /hello.txt
File written
Appending to file: /hello.txt
Message appended
Reading file: /hello.txt
Read from file: Hello World!
Deleting file: /foo.txt
File deleted
Renaming file /hello.txt to /foo.txt
File renamed
Reading file: /foo.txt
Read from file: Hello World!
0 bytes read for 0 ms
1048576 bytes written for 8024 ms
Total space: 486MB
Used space: 1MB
OK
Trying mount of SD card at freq 4000000...
SD Card Type: SDSC
SD Card Size: 486MB
Listing directory: /
  FILE: /test.txt  SIZE: 1048576
  FILE: /foo.txt  SIZE: 13
Creating Dir: /mydir
Dir created
Listing directory: /
  FILE: /test.txt  SIZE: 1048576
  FILE: /foo.txt  SIZE: 13
  DIR : /mydir
Removing Dir: /mydir
Dir removed
Listing directory: /
  FILE: /test.txt  SIZE: 1048576
  FILE: /foo.txt  SIZE: 13
Writing file: /hello.txt
File written
Appending to file: /hello.txt
Message appended
Reading file: /hello.txt
Read from file: Hello World!
Deleting file: /foo.txt
File deleted
Renaming file /hello.txt to /foo.txt
File renamed
Reading file: /foo.txt
Read from file: Hello World!
1048576 bytes read for 4467 ms
1048576 bytes written for 7874 ms
Total space: 486MB
Used space: 1MB
OK
Trying mount of SD card at freq 4000000...
SD Card Type: SDSC
SD Card Size: 486MB
Listing directory: /
  FILE: /test.txt  SIZE: 1048576
  FILE: /foo.txt  SIZE: 13
Creating Dir: /mydir
Dir created
Listing directory: /
  FILE: /test.txt  SIZE: 1048576
  FILE: /foo.txt  SIZE: 13
  DIR : /mydir
Removing Dir: /mydir
Dir removed
Listing directory: /
  FILE: /test.txt  SIZE: 1048576
  FILE: /foo.txt  SIZE: 13
Writing file: /hello.txt
File written
Appending to file: /hello.txt
Message appended
Reading file: /hello.txt
Read from file: Hello World!
Deleting file: /foo.txt
File deleted
Renaming file /hello.txt to /foo.txt
File renamed
Reading file: /foo.txt
Read from file: Hello World!
1048576 bytes read for 4467 ms
1048576 bytes written for 8039 ms
Total space: 486MB
Used space: 1MB
OK

Other Steps to Reproduce

I have searched existing bug reports. I have found and applied #6162 manually on top of 2.0.2. My tests for 2.0.2 use this attempted fix, without much success. Therefore, I think the pull will not fix the issue, at least for me.

The comment at #6189 (comment) appears to be the same issue as mine, but there is no verbose information to check whether this is so.

#5900 might be relevant to this bug, but lacks much information other than an attempt to use HSPI.

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

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@avillacis avillacis added the Status: Awaiting triage Issue is waiting for triage label Feb 16, 2022
@avillacis
Copy link
Author

If I revert #5988 under Arduino-ESP32 2.0.2, the behavior is apparently back to being tolerable, even with #6162 still applied:

--- Miniterm on /dev/ttyUSB0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
Trying mount of SD card at freq 4000000...
[  2512][W][sd_diskio.cpp:104] sdWait(): Wait Failed
[  2512][W][sd_diskio.cpp:512] ff_sd_initialize(): sdWait fail ignored, card initialize continues
[  2514][W][sd_diskio.cpp:180] sdCommand(): crc error
[  2618][W][sd_diskio.cpp:186] sdCommand(): token error [59] 0x5
SD Card Type: SDSC
SD Card Size: 486MB
Listing directory: /
  FILE: test.txt  SIZE: 1048576
  FILE: foo.txt  SIZE: 13
Creating Dir: /mydir
Dir created
Listing directory: /
  FILE: test.txt  SIZE: 1048576
  FILE: foo.txt  SIZE: 13
  DIR : mydir
Removing Dir: /mydir
Dir removed
Listing directory: /
  FILE: test.txt  SIZE: 1048576
  FILE: foo.txt  SIZE: 13
Writing file: /hello.txt
File written
Appending to file: /hello.txt
Message appended
Reading file: /hello.txt
Read from file: Hello World!
Deleting file: /foo.txt
File deleted
Renaming file /hello.txt to /foo.txt
File renamed
Reading file: /foo.txt
Read from file: Hello World!
1048576 bytes read for 4479 ms
1048576 bytes written for 7873 ms
Total space: 486MB
Used space: 1MB
OK
Trying mount of SD card at freq 4000000...
SD Card Type: SDSC
SD Card Size: 486MB
Listing directory: /
  FILE: test.txt  SIZE: 1048576
  FILE: foo.txt  SIZE: 13
Creating Dir: /mydir
Dir created
Listing directory: /
  FILE: test.txt  SIZE: 1048576
  FILE: foo.txt  SIZE: 13
  DIR : mydir
Removing Dir: /mydir
Dir removed
Listing directory: /
  FILE: test.txt  SIZE: 1048576
  FILE: foo.txt  SIZE: 13
Writing file: /hello.txt
File written
Appending to file: /hello.txt
Message appended
Reading file: /hello.txt
Read from file: Hello World!
Deleting file: /foo.txt
File deleted
Renaming file /hello.txt to /foo.txt
File renamed
Reading file: /foo.txt
Read from file: Hello World!
1048576 bytes read for 4479 ms
1048576 bytes written for 8067 ms
Total space: 486MB
Used space: 1MB
OK

@VojtechBartoska VojtechBartoska removed the Status: Awaiting triage Issue is waiting for triage label Feb 17, 2022
@P-R-O-C-H-Y
Copy link
Member

Please try master branch of Arduino-Esp32. Its already fixed. Fix will be included in release 2.0.3. Thanks

@avillacis
Copy link
Author

Please try master branch of Arduino-Esp32. Its already fixed. Fix will be included in release 2.0.3. Thanks

Could you please tell me which particular commit(s) or merged pull request(s) are supposed to fix this? I explicitly remarked that I manually applied #6162 and it did not fix the bug for me. I also commented that manually reverting #5988 on top of 2.0.2 does fix the bug for me.

@avillacis
Copy link
Author

Please try master branch of Arduino-Esp32. Its already fixed. Fix will be included in release 2.0.3. Thanks

Could you please tell me which particular commit(s) or merged pull request(s) are supposed to fix this? I explicitly remarked that I manually applied #6162 and it did not fix the bug for me. I also commented that manually reverting #5988 on top of 2.0.2 does fix the bug for me.

Answering myself, I have just noticed #6103 , so I am going to test this and #6162 together with #5988 .

@avillacis
Copy link
Author

Answering myself, I have just noticed #6103 , so I am going to test this and #6162 together with #5988 .

Confirmed that the referenced pulls fix my bug. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants