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

SD_MMC crashes because of time issue in driver #10835

Closed
1 task done
josef2600 opened this issue Jan 9, 2025 · 1 comment
Closed
1 task done

SD_MMC crashes because of time issue in driver #10835

josef2600 opened this issue Jan 9, 2025 · 1 comment
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@josef2600
Copy link

Board

ESP32-S3

Device Description

Devkit

Hardware Configuration

in 4-bit:
SD_MMC.setPins(SD_MMC_CLK, SD_MMC_CMD, SD_MMC_D0, SD_MMC_D1, SD_MMC_D2, SD_MMC_D3)
or 1-bit:
SD_MMC.setPins(SD_MMC_CLK, SD_MMC_CMD, SD_MMC_D0)

Version

v3.1.0

IDE Name

Arduino IDE

Operating System

win10

Flash frequency

80

PSRAM enabled

yes

Upload speed

256000

Description

i was getting alot of errors on many SD cards. even sometimes for initializing them i get error. so i searched and find this:
sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x107
(espressif/esp-idf#12968)
in it they say we should increase the time out to fix it:
esp-idf/components/driver/sdmmc

/sdmmc_host.c

the const uint32_t data_timeout_ms = 100; should be over 500ms or 1000ms.
problem is i cant fined that file. can you please fix it?
for example, in 16GB it wont write at all, but recognize it. the speed doesn't matter. i set it to 10Mhz and 40MHz. no change. and on my old 8GB sd cards, it wont even initialize. but if i put a 32GB , it all works. read and write works.

Sketch

#include "FS.h"
#include "SD_MMC.h"
#include <SPI.h>

#define DATA0_SD1P  17
#define DATA1_SD1P  15
#define DATA2_SD1P  20
#define DATA3_SD1P  9
#define CMD_SD1P  7
#define CLK_SD1P  19

uint8_t mybufff[1024*64];

#define SD_MMC_CLK CLK_SD1P 
#define SD_MMC_CMD CMD_SD1P
#define SD_MMC_D0 DATA0_SD1P
#define SD_MMC_D1 DATA1_SD1P
#define SD_MMC_D2 DATA2_SD1P
#define SD_MMC_D3 DATA3_SD1P

static bool prepSD_MMC()
{
  bool res = false;
  if(!SD_MMC.setPins(SD_MMC_CLK, SD_MMC_CMD, SD_MMC_D0, SD_MMC_D1, SD_MMC_D2, SD_MMC_D3))
  //if(!SD_MMC.setPins(SD_MMC_CLK, SD_MMC_CMD, SD_MMC_D0))
  {
    Serial.println("SD card Pin change failed!");
    return false;
  }
  delay(100);
  res = SD_MMC.begin("/sdcard", false, 1); //mode1bit==false
  //res = SD_MMC.begin("/sdcard", true, true, 10000);
  if (res) Serial.println("SD card Pin set in 4-bit mode success!");
  else Serial.println("No SD card attached");
  
  if (res)
  {
    res = true;
    Serial.println("SD card initialized successfull");
    Serial.print("SD card type=");
    switch (SD_MMC.cardType())
    {
      case CARD_NONE:
        Serial.println("None");
        break;
      case CARD_MMC:
        Serial.println("MMC");
        break;
      case CARD_SD:
        Serial.println("SD");
        break;
      case CARD_SDHC:
        Serial.println("SDHC");
        break;
      case CARD_UNKNOWN:
        Serial.println("Unknown");
        break;
      default:
        Serial.println("Unknown");
    }
    Serial.print("Card size:   "); Serial.print((uint32_t)(SD_MMC.cardSize() / 1000000)); Serial.println("MB");
    Serial.print("Total bytes: "); Serial.print((uint32_t)(SD_MMC.totalBytes() / 1000000)); Serial.println("MB");
    Serial.print("Used bytes:  "); Serial.print((uint32_t)(SD_MMC.usedBytes() / 1000000)); Serial.println("MB");
  }
  else
  {
    Serial.println("SD card mount failed");
    res = false;
  }
  return res;
}


void setup()
{
  Serial.begin(115200); // Used for info/debug
  while (!Serial)
    delay(100);
  delay(1000);
}

void loop()
{
  Serial.println( "" );
  prepSD_MMC();
  delay(500);
  File myfile = SD_MMC.open("/bench.dat", FILE_WRITE);
  delay(100);
  
  for (int i = 0; i < sizeof(mybufff); i++)
  {
    mybufff[i] = 1 + i;
  }
  mybufff[sizeof(mybufff) - 1] = 0;
  
  
   if (myfile.write(mybufff, sizeof(mybufff)) != sizeof(mybufff))
  {
    Serial.println("write failed");
    myfile.close();
    delay(50000);
  }
  else
  {
    myfile.close();
    Serial.println("write successfull");
  }
  delay(50000);
  
}

Debug Message

for 16GB:
SD card Pin set in 4-bit mode success!
SD card initialized successfull
SD card type=SDHC
Card size:   15523MB
Total bytes: 15514MB
Used bytes:  7MB
E (4289) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x107
E (4290) diskio_sdmmc: sdmmc_read_blocks failed (0x107)
write failed
E (4301) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x107
E (4301) diskio_sdmmc: sdmmc_read_blocks failed (0x107)


for 8GB:
E (2618) sdmmc_sd: sdmmc_init_sd_scr: send_scr (1) returned 0x107
E (2619) vfs_fat_sdmmc: sdmmc_card_init failed (0x107).
No SD card attached
SD card mount failed
write failed



for 32GB:
SD card Pin set in 4-bit mode success!
SD card initialized successfull
SD card type=SDHC
Card size:   31956MB
Total bytes: 31943MB
Used bytes:  84MB
write successfull

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

The file where we this needs to be changed is part of ESP-IDF and is not available (yet) as configuration value. We do not change files in ESP-IDF ourselves, so I suggest that you post in the IDF issue you linked above with hopes that this will be implemented sooner. Once that change is in the supported by Arduino IDF versions, we can add support for it on our end.

I'm closing this for now. Please open a new issue when we can actually implement it here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

No branches or pull requests

2 participants