SdFat: Meaning Error Codes on Mount Failed

Hi,

I started having a problem with otherwise very reliable SD Cards. I’m using SanDisk Ultra A1 SD Cards and had no problems at all for a long time now. For a few weeks, I started testing my code on the new ESP32-S3. Here I started to get Write errors after 5-10h of running.

The weird thing is:

  • the same code/setup works fine with Intenso 8GB Cards for over 24h.
  • the SD Card work fine on ESP32, Teensy, etc.
  • When the SD Card reports a Write Error I’m unable to make the SD Card work again until I plug it into a Laptop SD Card reader once. after that, the sd card works again.

This is what i tried:

First, the SD Write fails. here is some info I get from the File Obj. after the write error

[31849169] file.dlog: name="LOG06.TXT", position=491554816, size=491554816, werrors=1, wtime=31847964, isOpen=1
[31849170] file.err: restarting system

1.) The system reboots if a write error is detected to try to just remount the sd. this does not work and i get this at mount

[3495] jFS_SdFat.err: msg=mount failed
[3495] jFS_SdFat.err: code=1, data=0

2.) unplug and replug the sd card without power cycle the Microcontroller, then rebooting the microcontroller per software. result is

[5059] jFS_SdFat.err: msg=mount failed
[5059] jFS_SdFat.err: code=17, data=FF

3.) complete power cycle of microcontroller and SD Card.At this point the sd and microcontroller should be in the state where all works again but i get the same error as 2.)

4.) I unplug sd, put in a sd card reader in windows and the sd is readable no problem.

5.) sd card plugged back into the microcontroller first startup does not work again mount fails. after a second power cycle, the sd works again.

Does this ring a bell ? Is there a lookup table or other info what the code and data values mean at mount error?

I’m doing the 0xFF SPI Sends at boot to reset the sd card. after 10x 0xFF send i still get no 0xFF response. Here the code for reference


static void storage_reset_sd() 
{
	LogD("storage.sd: msg=reset start");

	//reset / unmount sd card
	// https://forum.arduino.cc/t/resolved-how-can-i-reboot-an-sd-card/349700
	pinMode(PIN_SPI_CS_SD, OUTPUT);
	digitalWrite(PIN_SPI_CS_SD, HIGH);
	delay(100);
	
	SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0));
	digitalWrite(PIN_SPI_CS_SD, LOW);
	for(int i = 0; i < 10; i++)
	{
		byte v = SPI.transfer(0xFF);
		if(v == 0xFF)
		{
			LogD("storage.sd: reset_count=%d", i);
			break;
		}
	}
	digitalWrite(PIN_SPI_CS_SD, HIGH);
	SPI.endTransaction();

	LogD("storage.sd: msg=reset end");

}

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 21 (11 by maintainers)

Most upvoted comments

Looks like ESP-S3 SPI has a bug fix:

There is a newer bugfix release of this ESP-IDF version. The latest bugfix release is v4.4.1

You may not be using SPI for WiFi. Looks like ESP-S3 has a different structure so I can’t be sure what each of the four SPI ports are used for.

https://docs.espressif.com/projects/esp-idf/en/v4.4/esp32s3/api-reference/peripherals/spi_master.html

Overview of ESP32-S3’s SPI peripherals

ESP32-S3 integrates 4 SPI peripherals.

SPI0 and SPI1 are used internally to access the ESP32-S3’s attached flash memory. Both controllers share the same SPI bus signals, and there is an arbiter to determine which can access the bus.

Currently, SPI Master driver does not support SPI1 bus.

SPI2 and SPI3 are general purpose SPI controllers. They are open to users. SPI2 and SPI3 have independent signal buses with the same respective names. SPI2 has 6 CS lines. SPI3 has 3 CS lines. Each CS line can be used to drive one SPI slave.