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)
Fork of SDFileSystem by
Revision 3:722f622d057a, committed 2013-04-16
- Comitter:
- earlz
- Date:
- Tue Apr 16 05:23:18 2013 +0000
- Parent:
- 2:c8f66dc765d4
- Commit message:
- Added tried_again functionality because for some reason it never works the first time
Changed in this revision
SDFileSystem.cpp | Show annotated file Show diff for this revision Revisions of this file |
SDFileSystem.h | Show annotated file Show diff for this revision Revisions of this file |
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; }
diff -r c8f66dc765d4 -r 722f622d057a SDFileSystem.h --- a/SDFileSystem.h Thu Nov 29 10:56:21 2012 +0000 +++ b/SDFileSystem.h Tue Apr 16 05:23:18 2013 +0000 @@ -77,6 +77,7 @@ SPI _spi; DigitalOut _cs; int cdv; + int tried_again; }; #endif