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.h - Application is not notified that file::flush() failed #6303

Closed
1 task done
ChristopheLaurent opened this issue Feb 18, 2022 · 7 comments
Closed
1 task done
Assignees
Labels
Type: Feature request Feature request for Arduino ESP32

Comments

@ChristopheLaurent
Copy link

Related area

SD card

Hardware specification

LilyGo ESP32 board with SD slot

Is your feature request related to a problem?

My application can write data in a file on this SD card without any problem using my_file.printf().
If I remove the SD card while writing, there is no error. I noticed that the size returned by my_file.printf() > 0 even if nothing was wrote on the SD card since the card was physically removed. The error occurs later when my application calls my_file.flush(). I can then see on serial monitor:
[E][sd_diskio.cpp:123] sdSelectCard(): Select Failed
I wish my application to react on this error instead of going on silently.
I did not find any public API in SD.h to inform my application that my_file.flush() raised an error.

Describe the solution you'd like

I'd like SD class to keep track of such a failure in a SD.h public property.

Describe alternatives you've considered

No response

Additional context

I've seen issue SD card status check bug #6081, but I don't think this is related to my issue.

I have checked existing list of Feature requests and the Contribution Guide

  • I confirm I have checked existing list of Feature requests and Contribution Guide.
@ChristopheLaurent ChristopheLaurent added the Type: Feature request Feature request for Arduino ESP32 label Feb 18, 2022
@VojtechBartoska
Copy link
Collaborator

Can you please take a look on this issue, @P-R-O-C-H-Y ?

@tobozo
Copy link
Contributor

tobozo commented Feb 22, 2022

@ChristopheLaurent does this snippet from sd_diskio.cpp produce the expected behaviour?

bool sdSelectCard(uint8_t pdrv)
{
    ardu_sdcard_t * card = s_cards[pdrv];
    digitalWrite(card->ssPin, LOW);
    bool s = sdWait(pdrv, 300);
    static unsigned int failcount = 0;
    if (!s) {
		if (failcount == 0){
			log_e("Select Failed on first attempt!!!");
			//digitalWrite(card->ssPin, HIGH);
			//return false;
		} else {
			log_e("Select Failed");
			digitalWrite(card->ssPin, HIGH);
			return false;
		}
		failcount ++;
    }
    return true;
}

@P-R-O-C-H-Y
Copy link
Member

P-R-O-C-H-Y commented Feb 22, 2022

Hi @ChristopheLaurent, can you please provide more informations, that were typed in issue template?
The most important is what version of Arduino-ESP32 are you using?

@ChristopheLaurent
Copy link
Author

Hi @P-R-O-C-H-Y , I was still using V1.0.6 according to file /cores/esp32/core_version.h and I realized that implementation of sdSelectCard() in sd_diskio.cpp changed since V1.0.6 . So I decided to move to V2 but it does not build with PlatformIO due to known issue #619 . Do you think that my original issue about SD card is already solved in V2 ? If not I prefer to stay on 1.0.6 until main V2 branch is fixed for PlatformIO.

@ChristopheLaurent
Copy link
Author

ChristopheLaurent commented Feb 22, 2022

Hi @tobozo, I guess it would help but I would prefer your failcount to be a private property of SD class with a public accessor instead of a static variable. Also I don't understand why we would need a special logic on your failcount to reset ss pin ?

@P-R-O-C-H-Y
Copy link
Member

P-R-O-C-H-Y commented Feb 22, 2022

Hi @P-R-O-C-H-Y , I was still using V1.0.6 according to file /cores/esp32/core_version.h and I realized that implementation of sdSelectCard() in sd_diskio.cpp changed since V1.0.6 . So I decided to move to V2 but it does not build with PlatformIO due to known issue #619 . Do you think that my original issue about SD card is already solved in V2 ? If not I prefer to stay on 1.0.6 until main V2 branch is fixed for PlatformIO.

I don't know about issues with SD card on 1.0.6 version. But this version is no longer supported.
In 2.0.2 there were issues, which are already fixed in master branch. So for now is better for you to stay on 1.0.6 and wait until 2.0.3 is released (will be soon). But anyway if you are using platformio, Arduino-esp32 is not updated on their side yet. I will suggest you to follow the issue you mentioned to update Arduino-esp32.

@ChristopheLaurent
Copy link
Author

Tanks a lot for your wise support @P-R-O-C-H-Y . I just managed to build using 2.0.2 on PlatformIO and even run to some extent, but my application get stuck using GxEPD, the graphic driver for e-paper screen. So I'm going back to 1.0.6 for the time being, and I will wait a couple of months until everything is stabilized, then try again. Best Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature request Feature request for Arduino ESP32
Projects
None yet
Development

No branches or pull requests

4 participants