SDFileSystem

Dependencies:   FATFileSystem

Dependents:   EMIRv2

Fork of SDFileSystem by mbed official

Files at this revision

API Documentation at this revision

Comitter:
alpov
Date:
Sat Mar 29 10:45:18 2014 +0000
Parent:
3:7b35d1709458
Commit message:
added timeouts to read and write, fixed lockup when no card present

Changed in this revision

FATFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7b35d1709458 -r 079bf96a6aad FATFileSystem.lib
--- a/FATFileSystem.lib	Mon Mar 17 14:34:01 2014 +0000
+++ b/FATFileSystem.lib	Sat Mar 29 10:45:18 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/FATFileSystem/#e960e2b81a3c
+http://mbed.org/teams/mbed-official/code/FATFileSystem/#e960e2b81a3c
diff -r 7b35d1709458 -r 079bf96a6aad SDFileSystem.cpp
--- a/SDFileSystem.cpp	Mon Mar 17 14:34:01 2014 +0000
+++ b/SDFileSystem.cpp	Sat Mar 29 10:45:18 2014 +0000
@@ -199,6 +199,8 @@
 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)
@@ -350,7 +352,13 @@
     _cs = 0;
     
     // read until start byte (0xFF)
-    while (_spi.write(0xFF) != 0xFE);
+    int timeout = SD_COMMAND_TIMEOUT;
+    while (_spi.write(0xFF) != 0xFE && --timeout);
+    if (timeout == 0) {
+        _cs = 1;
+        _spi.write(0xFF);
+        return 1;
+    }
     
     // read data
     for (int i = 0; i < length; i++) {
@@ -387,7 +395,13 @@
     }
     
     // wait for write to finish
-    while (_spi.write(0xFF) == 0);
+    int timeout = SD_COMMAND_TIMEOUT;
+    while (_spi.write(0xFF) == 0 && --timeout);
+    if (timeout == 0) {
+        _cs = 1;
+        _spi.write(0xFF);
+        return 1;
+    }
     
     _cs = 1;
     _spi.write(0xFF);