Slight modification to SDFileSystem so that if the first initialization doesn't do the trick it tries doing it again (which so far has fixed every issue for me)

Dependencies:   FATFileSystem

Fork of SDFileSystem by mbed official

Revision:
3:722f622d057a
Parent:
2:c8f66dc765d4
diff -r c8f66dc765d4 -r 722f622d057a SDFileSystem.cpp
--- a/SDFileSystem.cpp	Thu Nov 29 10:56:21 2012 +0000
+++ b/SDFileSystem.cpp	Tue Apr 16 05:23:18 2013 +0000
@@ -122,6 +122,7 @@
 SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name) :
     FATFileSystem(name), _spi(mosi, miso, sclk), _cs(cs) {
     _cs = 1;
+    tried_again=0;
 }
 
 #define R1_IDLE_STATE           (1 << 0)
@@ -152,6 +153,11 @@
     
     // send CMD0, should return with all zeros except IDLE STATE set (bit 0)
     if (_cmd(0, 0) != R1_IDLE_STATE) {
+        if(!tried_again)
+        {
+            tried_again=1;
+            return initialise_card(); //for good luck, try it again? 
+        }
         debug("No disk, or could not put SD card in to SPI idle state\n");
         return SDCARD_FAIL;
     }