USB Mass Storage Device Block Device

Dependents:   mini_piano_player play_wav BlueCrutch FTHR_USBMSD_Demo_27

Fork of USBMSD_SD by Greg Steiert

Revision:
5:13fed87fb66f
Parent:
4:6b2f29de40d3
--- a/USBMSD_BD.cpp	Fri Feb 23 23:25:58 2018 +0000
+++ b/USBMSD_BD.cpp	Sat Feb 24 18:04:35 2018 +0000
@@ -119,9 +119,8 @@
 
 #define SD_DBG             0
 
-USBMSD_BD::USBMSD_BD(BlockDevice* bd, bd_size_t ssize) {
+USBMSD_BD::USBMSD_BD(BlockDevice* bd) {
     _bd = bd;
-    _ssize = ssize;
     //no init
     _status = 0x01;
     
@@ -129,6 +128,8 @@
 }
 
 int USBMSD_BD::disk_initialize() {
+    _bd->init();
+    _ssize = _bd->get_erase_size();
     _sectors = _bd->size() / _ssize;
     
     // OK
@@ -141,7 +142,8 @@
 {
     bd_addr_t addr = (bd_addr_t)sector*_ssize;
     bd_size_t size = (bd_size_t)count*_ssize;
-    int err = _bd->program(buff, addr, size);
+    int err = _bd->erase(addr, size);
+    err = _bd->program(buff, addr, size);
     return err;
 }
 
@@ -156,7 +158,7 @@
 int USBMSD_BD::disk_status() { return _status; }
 int USBMSD_BD::disk_sync() { return 0; }
 uint64_t USBMSD_BD::disk_sectors() { return _sectors; }
-uint64_t USBMSD_BD::disk_size() { return (*_bd).size(); }
+uint64_t USBMSD_BD::disk_size() { return _bd->size(); }
 
 
 // PRIVATE FUNCTIONS