A re-written SDFileSystem library with improved compatibility, CRC support, and card removal/replacement support.

Dependencies:   FATFileSystem

Dependents:   xadow_m0_SD_Hello roam_v1 roam_v2 Polytech_tours ... more

Revision:
24:a52e682a1ce4
Parent:
23:6bb3c1987511
Child:
25:923df4ee70c4
--- a/SDFileSystem.cpp	Wed Apr 13 16:51:25 2016 +0000
+++ b/SDFileSystem.cpp	Tue May 24 15:50:26 2016 +0000
@@ -149,6 +149,7 @@
 {
     char token;
     unsigned int resp;
+    Timer timer;
 
     //Make sure there's a card in the socket before proceeding
     checkSocket();
@@ -199,13 +200,13 @@
             return m_Status;
         }
 
-        //Try to initialize the card using ACMD41(0x00100000)
-        for (int i = 0; i < 1000; i++) {
+        //Try to initialize the card using ACMD41(0x40100000) for up to 2 seconds
+        timer.start();
+        do {
             token = commandTransaction(ACMD41, 0x40100000);
-            if (token != 0x01) {
-                break;
-            }
-        }
+        } while (token == 0x01 && timer.read_ms() < 2000);
+        timer.stop();
+        timer.reset();
 
         //Check if the card initialized
         if (token != 0x00) {
@@ -250,13 +251,13 @@
             return m_Status;
         }
 
-        //Try to initialize the card using ACMD41(0x00100000)
-        for (int i = 0; i < 1000; i++) {
+        //Try to initialize the card using ACMD41(0x40100000) for up to 2 seconds
+        timer.start();
+        do {
             token = commandTransaction(ACMD41, 0x40100000);
-            if (token != 0x01) {
-                break;
-            }
-        }
+        } while (token == 0x01 && timer.read_ms() < 2000);
+        timer.stop();
+        timer.reset();
 
         //Check if the card initialized
         if (token == 0x00) {
@@ -269,13 +270,13 @@
             else
                 m_Spi.frequency(m_FREQ);
         } else {
-            //Try to initialize the card using CMD1(0x00100000)
-            for (int i = 0; i < 1000; i++) {
+            //Try to initialize the card using CMD1(0x00100000) for up to 2 seconds
+            timer.start();
+            do {
                 token = commandTransaction(CMD1, 0x00100000);
-                if (token != 0x01) {
-                    break;
-                }
-            }
+            } while (token == 0x01 && timer.read_ms() < 2000);
+            timer.stop();
+            timer.reset();
 
             //Check if the card initialized
             if (token == 0x00) {