don't create MSD if sdcard is not present
authorJim Morris <morris@wolfman.com>
Fri, 11 Oct 2013 05:30:58 +0000 (22:30 -0700)
committerJim Morris <morris@wolfman.com>
Fri, 11 Oct 2013 05:31:47 +0000 (22:31 -0700)
src/main.cpp

index 999f068..bf59c53 100644 (file)
@@ -51,7 +51,7 @@ SDCard sd(P0_9, P0_8, P0_7, P0_6);      // this selects SPI1 as the sdcard as it
 
 USB u;
 USBSerial usbserial(&u);
-USBMSD msc(&u, &sd);
+USBMSD *msc;
 DFU dfu(&u);
 
 SDFAT mounter("sd", &sd);
@@ -74,7 +74,7 @@ int main() {
         leds[i] = (i & 1) ^ 1;
     }
 
-    sd.disk_initialize();
+    bool sdok= (sd.disk_initialize() == 0);
 
     Kernel* kernel = new Kernel();
 
@@ -99,7 +99,11 @@ int main() {
 
     // Create and initialize USB stuff
     u.init();
-    kernel->add_module( &msc );
+    if(sdok) { // only do this if there is an sd disk
+        msc= new USBMSD(&u, &sd);
+        kernel->add_module( msc );
+    }
+
     kernel->add_module( &usbserial );
     if( kernel->config->value( second_usb_serial_enable_checksum )->by_default(false)->as_bool() ){
         kernel->add_module( new USBSerial(&u) );