@@ -10,6 +10,7 @@ static_assert(ARDUINO_USB_MODE == 0, "must be used when USB is in OTG mode");
1010#include < cstdint>
1111#include < esp_err.h>
1212#include < esp_partition.h>
13+ #include < iostream>
1314
1415#if ARDUINO_USB_CDC_ON_BOOT == 1
1516#define HWSerial Serial0
@@ -22,13 +23,14 @@ static USBMSC MSC;
2223static constexpr std::uint16_t blockSize = 512 ; // Should be 512
2324
2425static const esp_partition_t *partition = nullptr ;
26+ static const char *const TAG = " STORAGE" ;
2527
2628// Callback invoked when received WRITE10 command.
2729// Process data in buffer to disk's storage and
2830// return number of written bytes (must be multiple of block size)
2931static int32_t onWrite (uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t bufsize)
3032{
31- HWSerial. printf ( " MSC WRITE: lba: %u, offset: %u, bufsize: %u\n " , lba, offset, bufsize);
33+ ESP_LOGV (TAG, " MSC WRITE: lba: %u, offset: %u, bufsize: %u\n " , lba, offset, bufsize);
3234 uint32_t byteOffset = lba * blockSize + offset;
3335 // erase must be called before write
3436 ESP_ERROR_CHECK (esp_partition_erase_range (partition, byteOffset, bufsize));
@@ -41,15 +43,15 @@ static int32_t onWrite(uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t
4143// return number of copied bytes (must be multiple of block size)
4244static int32_t onRead (uint32_t lba, uint32_t offset, void *buffer, uint32_t bufsize)
4345{
44- HWSerial. printf ( " MSC READ: lba: %u, offset: %u, bufsize: %u\n " , lba, offset, bufsize);
46+ ESP_LOGV (TAG, " MSC READ: lba: %u, offset: %u, bufsize: %u\n " , lba, offset, bufsize);
4547 uint32_t byteOffset = lba * blockSize + offset;
4648 ESP_ERROR_CHECK (esp_partition_read (partition, byteOffset, buffer, bufsize));
4749 return bufsize;
4850}
4951
5052static bool onStartStop (uint8_t power_condition, bool start, bool load_eject)
5153{
52- HWSerial. printf ( " MSC START/STOP: power: %u, start: %u, eject: %u\n " , power_condition, start, load_eject);
54+ ESP_LOGV (TAG, " MSC START/STOP: power: %u, start: %u, eject: %u\n " , power_condition, start, load_eject);
5355 return true ;
5456}
5557
@@ -58,18 +60,19 @@ static bool onStartStop(uint8_t power_condition, bool start, bool load_eject)
5860 */
5961static void listFiles (const char *const dirname)
6062{
61- HWSerial. printf ( " Directory: '%s' \n " , dirname) ;
63+ std::cout << " Directory: '" << dirname << " ' " << std::endl ;
6264 File root = FFat.open (dirname);
6365 if (!root || !root.isDirectory ())
6466 {
65- HWSerial. printf ( " Error: '%s' is not a directory!\n " , dirname);
67+ ESP_LOGE (TAG, " Error: '%s' is not a directory!\n " , dirname);
6668 return ;
6769 }
6870
6971 File file = root.openNextFile ();
7072 while (file)
7173 {
72- HWSerial.printf (" %s (%s, %d Bytes)\n " , file.name (), file.isDirectory () ? " d" : " f" , file.size ());
74+ std::cout << " \t " << file.name () << " (" << (file.isDirectory () ? " d" : " f" ) << " , " << file.size () << " Bytes)"
75+ << std::endl;
7376 file = root.openNextFile ();
7477 }
7578}
@@ -129,18 +132,18 @@ void Storage::begin()
129132
130133 if (!FFat.begin (true ))
131134 { // `true` = Formatieren falls kein Dateisystem vorhanden
132- HWSerial. println ( " Failed to init files system, flash may not be formatted" );
135+ ESP_LOGE (TAG, " Failed to init files system, flash may not be formatted" );
133136 return ;
134137 }
135- HWSerial. println ( " FatFS erfolgreich gemountet." );
138+ ESP_LOGI (TAG, " FatFS erfolgreich gemountet." );
136139
137140 partition = check_ffat_partition (FFAT_PARTITION_LABEL);
138141 if (!partition)
139142 {
140- printf ( " Error with FAT partition" );
143+ ESP_LOGE (TAG, " Error with FAT partition" );
141144 return ;
142145 }
143- HWSerial. printf ( " Flash has a size of %u bytes\n " , FFat.totalBytes ());
146+ ESP_LOGI (TAG, " Flash has a size of %u bytes\n " , FFat.totalBytes ());
144147
145148 USB.onEvent (ARDUINO_USB_STARTED_EVENT, usbStartedCallback);
146149 USB.onEvent (ARDUINO_USB_STOPPED_EVENT, usbStoppedCallback);
0 commit comments