Fork of SD file system with changes to prevent stalling if card is missing during initialization. Also uses a FAT file system that exposes the FILINFO of the current file, so true file sizes can be obtained, among other things
Dependencies: FATFileSystemWithFilinfo
Fork of SDFileSystem by
Revision 5:7bdd92175879, committed 2014-10-30
- Comitter:
- uci1
- Date:
- Thu Oct 30 06:29:26 2014 +0000
- Parent:
- 4:821cb4545836
- Child:
- 6:5acb3869b993
- Commit message:
- prevent stalling if SD card fails to initialize
Changed in this revision
| SDFileSystem.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/SDFileSystem.cpp Thu Oct 30 06:27:23 2014 +0000
+++ b/SDFileSystem.cpp Thu Oct 30 06:29:26 2014 +0000
@@ -147,22 +147,23 @@
_spi.write(0xFF);
}
+ int ret = SDCARD_FAIL;
+
// send CMD0, should return with all zeros except IDLE STATE set (bit 0)
if (_cmd(0, 0) != R1_IDLE_STATE) {
debug("No disk, or could not put SD card in to SPI idle state\n");
- return SDCARD_FAIL;
}
// send CMD8 to determine whther it is ver 2.x
int r = _cmd8();
if (r == R1_IDLE_STATE) {
- return initialise_card_v2();
+ ret = initialise_card_v2();
} else if (r == (R1_IDLE_STATE | R1_ILLEGAL_COMMAND)) {
- return initialise_card_v1();
+ ret = initialise_card_v1();
} else {
debug("Not in idle state after sending CMD8 (not an SD card?)\n");
- return SDCARD_FAIL;
}
+ return ret;
}
int SDFileSystem::initialise_card_v1() {
@@ -199,6 +200,9 @@
int SDFileSystem::disk_initialize() {
int i = initialise_card();
debug_if(SD_DBG, "init card = %d\n", i);
+ if (i==SDCARD_FAIL) {
+ return 1;
+ }
_sectors = _sd_sectors();
// Set block length to 512 (CMD16)
