1+ #include < Arduino.h>
2+
13#include " storage.hpp"
24#include < FFat.h>
35#include < USB.h>
79#include < esp_partition.h>
810#include < string>
911
10- #if ARDUINO_USB_CDC_ON_BOOT == 1
11- #define HWSerial Serial0
12- #define USBSerial Serial
13- #else
14- #define HWSerial Serial
15- #include < USBCDC.h>
16- USBCDC USBSerial;
17- #endif
18-
1912#if defined(ARDUINO_USB_MODE)
2013static_assert (ARDUINO_USB_MODE == 0 , " USB must be in OTG mode" );
2114#endif
@@ -110,7 +103,7 @@ std::size_t Storage::size()
110103
111104bool Storage::begin (const bool formatFsOnFail, const char *const partitionLabel)
112105{
113- ESP_LOGI (TAG, " Starting storage..." );
106+ ESP_LOGD (TAG, " Starting storage..." );
114107 partition = check_ffat_partition (partitionLabel);
115108
116109 if (!partition)
@@ -129,6 +122,7 @@ bool Storage::begin(const bool formatFsOnFail, const char *const partitionLabel)
129122 }
130123 ESP_LOGI (TAG, " Storage has a size of %u bytes." , size ());
131124 ESP_LOGI (TAG, " Storage mounted at '%s'." , basePath.c_str ());
125+ fileSystemIsReady = true ;
132126
133127 // setup USB Mass Storage Class
134128 usbMsc.vendorID (" TTS" ); // max 8 chars
@@ -138,14 +132,11 @@ bool Storage::begin(const bool formatFsOnFail, const char *const partitionLabel)
138132 // Set callback
139133 usbMsc.onRead (usbMsc_onRead);
140134 usbMsc.onWrite (usbMsc_onWrite);
141- // usbMsc is ready for read/write
142- usbMsc.mediaPresent (true );
143- if (!usbMsc.begin (FFat.totalBytes () / blockSize, blockSize))
135+ if (!usbMsc.begin (size () / blockSize, blockSize))
144136 {
145137 ESP_LOGE (TAG, " USB MSC initialization failed!" );
146138 return false ;
147139 }
148- fileSystemIsReady = true ;
149140
150141 // subscribe to USB events
151142 USB.onEvent (ARDUINO_USB_STARTED_EVENT, callbackUsbStarted);
0 commit comments