Bayley Wang / SDFileSystem2

Dependencies:   FATFileSystem2

Fork of SDFileSystem by mbed official

Revision:
10:5d493744b422
Parent:
9:4f72b0753ab6
--- a/SDFileSystem.cpp	Sat May 19 10:02:05 2018 +0000
+++ b/SDFileSystem.cpp	Sun Sep 30 18:03:44 2018 +0000
@@ -125,7 +125,7 @@
 
     // Set default to 100kHz for initialisation and 1MHz for data transfer
     _init_sck = 100000;
-    _transfer_sck = 20000000;
+    _transfer_sck = 25000000;
 }
 
 #define R1_IDLE_STATE           (1 << 0)
@@ -247,15 +247,31 @@
         return -1;
     }
     
-    for (uint32_t b = block_number; b < block_number + count; b++) {
+    if (count == 1) {
         // set read address for single block (CMD17)
-        if (_cmd(17, b * cdv) != 0) {
+        if (_cmd(17, block_number * cdv) != 0) {
             return 1;
         }
         
         // receive the data
         _read(buffer, 512);
         buffer += 512;
+        
+        return 0;
+    }
+    
+    for (uint32_t b = block_number; b < block_number + count; b++) {
+        // set read address for single block (CMD17)
+        if (_cmd(18, b * cdv) != 0) {
+            return 1;
+        }
+        
+        // receive the data
+        do {
+            _read(buffer, 512);
+            buffer += 512;
+        } while (--count);
+        _cmd(12, 0);
     }
 
     return 0;