USBMSD SD card Hello World for Mbed platforms

Dependencies:   mbed USBMSD_SD USBDevice

Revision:
19:148a0b8d23bc
Parent:
18:08b207d10056
Child:
20:50bf1cd2e2fe
--- a/USBDevice/USBMSD/USBMSD.cpp	Sun Dec 11 15:22:50 2011 +0000
+++ b/USBDevice/USBMSD/USBMSD.cpp	Sun Dec 11 15:42:23 2011 +0000
@@ -20,6 +20,11 @@
 #include "USBMSD.h"
 #include "USBBusInterface.h"
 
+#define DISK_OK         0x00
+#define NO_INIT         0x01
+#define NO_DISK         0x02
+#define WRITE_PROTECT   0x04
+
 #define CBW_Signature               0x43425355
 #define CSW_Signature               0x53425355
 
@@ -90,18 +95,22 @@
     return success;
 }
 
-
+DigitalOut l1(LED1); 
 bool USBMSD::connect() {
 
     //disk initialization
-    disk_initialize();
+    if (disk_status() & NO_INIT) {
+        if (disk_initialize()) {
+            return false;
+        }
+    }
 
     // get number of blocks
     BlockCount = disk_sectors();
-    
+
     // get memory size
     MemorySize = disk_size();
-    
+
     if (BlockCount >= 0) {
         BlockSize = MemorySize / BlockCount;
         if (BlockSize != 0) {
@@ -212,8 +221,11 @@
         page[addr%BlockSize + i] = buf[i];
 
     // if the array is filled, write it in memory
-    if (!((addr + size)%BlockSize))
-        disk_write((const char *)page, addr/BlockSize);
+    if (!((addr + size)%BlockSize)) {
+        if (!(disk_status() & WRITE_PROTECT)) {
+            disk_write((const char *)page, addr/BlockSize);
+        }
+    }
 
     addr += size;
     length -= size;