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

Files at this revision

API Documentation at this revision

Comitter:
neilt6
Date:
Wed Feb 24 17:46:31 2016 +0000
Parent:
21:d10a519c0910
Child:
23:6bb3c1987511
Commit message:
Fixed timer hang bug in disk_initialize()

Changed in this revision

SDCRC.cpp Show annotated file Show diff for this revision Revisions of this file
SDCRC.h 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
SDFileSystem.h Show annotated file Show diff for this revision Revisions of this file
--- a/SDCRC.cpp	Fri Dec 11 16:30:36 2015 +0000
+++ b/SDCRC.cpp	Wed Feb 24 17:46:31 2016 +0000
@@ -1,5 +1,5 @@
 /* SD/MMC File System Library
- * Copyright (c) 2015 Neil Thiessen
+ * Copyright (c) 2016 Neil Thiessen
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
--- a/SDCRC.h	Fri Dec 11 16:30:36 2015 +0000
+++ b/SDCRC.h	Wed Feb 24 17:46:31 2016 +0000
@@ -1,5 +1,5 @@
 /* SD/MMC File System Library
- * Copyright (c) 2015 Neil Thiessen
+ * Copyright (c) 2016 Neil Thiessen
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
--- a/SDFileSystem.cpp	Fri Dec 11 16:30:36 2015 +0000
+++ b/SDFileSystem.cpp	Wed Feb 24 17:46:31 2016 +0000
@@ -1,5 +1,5 @@
 /* SD/MMC File System Library
- * Copyright (c) 2015 Neil Thiessen
+ * Copyright (c) 2016 Neil Thiessen
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,7 +19,12 @@
 #include "pinmap.h"
 #include "SDCRC.h"
 
-SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name, PinName cd, SwitchType cdtype, int hz) : FATFileSystem(name), m_Spi(mosi, miso, sclk), m_Cs(cs, 1), m_Cd(cd), m_FREQ(hz)
+SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name, PinName cd, SwitchType cdtype, int hz)
+    : FATFileSystem(name),
+      m_Spi(mosi, miso, sclk),
+      m_Cs(cs, 1),
+      m_Cd(cd),
+      m_FREQ(hz)
 {
     //Initialize the member variables
     m_CardType = CARD_NONE;
@@ -194,13 +199,13 @@
             return m_Status;
         }
 
-        //Send ACMD41(0x40100000) repeatedly for up to 1 second to initialize the card
-        m_Timer.start();
-        do {
+        //Try to initialize the card using ACMD41(0x00100000)
+        for (int i = 0; i < 1000; i++) {
             token = commandTransaction(ACMD41, 0x40100000);
-        } while (token == 0x01 && m_Timer.read_ms() < 1000);
-        m_Timer.stop();
-        m_Timer.reset();
+            if (token != 0x01) {
+                break;
+            }
+        }
 
         //Check if the card initialized
         if (token != 0x00) {
@@ -236,13 +241,13 @@
             return m_Status;
         }
 
-        //Try to initialize the card using ACMD41(0x00100000) for 1 second
-        m_Timer.start();
-        do {
-            token = commandTransaction(ACMD41, 0x00100000);
-        } while (token == 0x01 && m_Timer.read_ms() < 1000);
-        m_Timer.stop();
-        m_Timer.reset();
+        //Try to initialize the card using ACMD41(0x00100000)
+        for (int i = 0; i < 1000; i++) {
+            token = commandTransaction(ACMD41, 0x40100000);
+            if (token != 0x01) {
+                break;
+            }
+        }
 
         //Check if the card initialized
         if (token == 0x00) {
@@ -255,13 +260,13 @@
             else
                 m_Spi.frequency(m_FREQ);
         } else {
-            //Try to initialize the card using CMD1(0x00100000) for 1 second
-            m_Timer.start();
-            do {
+            //Try to initialize the card using CMD1(0x00100000)
+            for (int i = 0; i < 1000; i++) {
                 token = commandTransaction(CMD1, 0x00100000);
-            } while (token == 0x01 && m_Timer.read_ms() < 1000);
-            m_Timer.stop();
-            m_Timer.reset();
+                if (token != 0x01) {
+                    break;
+                }
+            }
 
             //Check if the card initialized
             if (token == 0x00) {
--- a/SDFileSystem.h	Fri Dec 11 16:30:36 2015 +0000
+++ b/SDFileSystem.h	Wed Feb 24 17:46:31 2016 +0000
@@ -1,5 +1,5 @@
 /* SD/MMC File System Library
- * Copyright (c) 2015 Neil Thiessen
+ * Copyright (c) 2016 Neil Thiessen
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.