USB u __attribute__ ((section ("AHBSRAM0")));
USBSerial usbserial __attribute__ ((section ("AHBSRAM0"))) (&u);
-USBMSD msc __attribute__ ((section ("AHBSRAM0"))) (&u, &sd);
-//USBMSD *msc= NULL;
+USBMSD *msc= NULL;
DFU dfu __attribute__ ((section ("AHBSRAM0"))) (&u);
SDFAT mounter __attribute__ ((section ("AHBSRAM0"))) ("sd", &sd);
kernel->use_leds= !kernel->config->value( disable_leds_checksum )->by_default(false)->as_bool();
// attempt to be able to disable msd in config
- // if(!kernel->config->value( disable_msd_checksum )->by_default(false)->as_bool()){
- // msc= new USBMSD(&u, &sd);
- // }else{
- // msc= NULL;
- // kernel->streams->printf("MSD is disabled\r\n");
- // }
+ if(!kernel->config->value( disable_msd_checksum )->by_default(false)->as_bool()){
+ // HACK to zero the memory USBMSD uses as it and its objects seem to not initialize properly in the ctor
+ size_t n= sizeof(USBMSD);
+ void *v = AHB0.alloc(n);
+ memset(v, 0, n); // clear the allocated memory
+ msc= new(v) USBMSD(&u, &sd); // allocate object using zeroed memory
+ }else{
+ msc= NULL;
+ kernel->streams->printf("MSD is disabled\r\n");
+ }
bool sdok= (sd.disk_initialize() == 0);
// Create and initialize USB stuff
u.init();
- //if(sdok) { // only do this if there is an sd disk
- // msc= new USBMSD(&u, &sd);
- // kernel->add_module( msc );
- //}
- // if(msc != NULL){
- // kernel->add_module( msc );
- // }
+ if(sdok && msc != NULL){
+ kernel->add_module( msc );
+ }
- 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) );