LittleFS port to Teensy/SPIFlash

Using the current version of MTP with mods for RAM and SPIFlash:
Capture4.PNG

Right now this is a proof of concept. Extending now to QSPI should be easy.
 
@all, wmxz,

what do I need to install or update? I want to try these things, too .. :)

@wmxz with your Sketch from your other Thread (vtable), I get the following:
Code:
In file included from C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:35:0,
                 from C:\Users\Frank\Documents\Arduino\sketch_nov19a\sketch_nov19a.ino:2:
C:\Arduino\hardware\teensy\avr\cores\teensy4/FS.h:49:7: error: redefinition of 'class File'
 class File : public Stream {
       ^
In file included from C:\Users\Frank\Documents\Arduino\libraries\SdFat\src/FatLib/FatLib.h:27:0,
                 from C:\Users\Frank\Documents\Arduino\libraries\SdFat\src/SdFat.h:33,
                 from C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:27,
                 from C:\Users\Frank\Documents\Arduino\sketch_nov19a\sketch_nov19a.ino:2:
C:\Users\Frank\Documents\Arduino\libraries\SdFat\src/FatLib/ArduinoFiles.h:122:7: error: previous definition of 'class File'
 class File : public FatFile, public Stream {
       ^
In file included from C:\Users\Frank\Documents\Arduino\sketch_nov19a\sketch_nov19a.ino:2:0:
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:43:22: error: 'FsFile' does not name a type
   #define SDFAT_FILE FsFile
                      ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:61:15: note: in expansion of macro 'SDFAT_FILE'
  SDFile(const SDFAT_FILE &file) : sdfatfile(file), filename(nullptr) { }
               ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:43:22: error: 'FsFile' does not name a type
   #define SDFAT_FILE FsFile
                      ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:139:2: note: in expansion of macro 'SDFAT_FILE'
  SDFAT_FILE sdfatfile;
  ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In constructor 'SDFile::SDFile(const int&)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:61:35: error: class 'SDFile' does not have any field named 'sdfatfile'
  SDFile(const SDFAT_FILE &file) : sdfatfile(file), filename(nullptr) { }
                                   ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In destructor 'virtual SDFile::~SDFile()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:65:7: error: 'sdfatfile' was not declared in this scope
   if (sdfatfile) sdfatfile.close();
       ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual void SDFile::whoami()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:71:27: error: 'getRefcount' was not declared in this scope
    (int)this, getRefcount());
                           ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual size_t SDFile::write(const void*, size_t)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:75:10: error: 'sdfatfile' was not declared in this scope
   return sdfatfile.write(buf, size);
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual int SDFile::peek()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:78:10: error: 'sdfatfile' was not declared in this scope
   return sdfatfile.peek();
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual int SDFile::available()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:81:10: error: 'sdfatfile' was not declared in this scope
   return sdfatfile.available();
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual void SDFile::flush()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:84:3: error: 'sdfatfile' was not declared in this scope
   sdfatfile.flush();
   ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual size_t SDFile::read(void*, size_t)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:87:10: error: 'sdfatfile' was not declared in this scope
   return sdfatfile.read(buf, nbyte);
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual bool SDFile::truncate(uint64_t)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:90:10: error: 'sdfatfile' was not declared in this scope
   return sdfatfile.truncate(size);
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual bool SDFile::seek(uint64_t, int)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:93:31: error: 'sdfatfile' was not declared in this scope
   if (mode == SeekSet) return sdfatfile.seekSet(pos);
                               ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:94:31: error: 'sdfatfile' was not declared in this scope
   if (mode == SeekCur) return sdfatfile.seekCur(pos);
                               ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:95:31: error: 'sdfatfile' was not declared in this scope
   if (mode == SeekEnd) return sdfatfile.seekEnd(pos);
                               ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual uint64_t SDFile::position()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:99:10: error: 'sdfatfile' was not declared in this scope
   return sdfatfile.curPosition();
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual uint64_t SDFile::size()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:102:10: error: 'sdfatfile' was not declared in this scope
   return sdfatfile.size();
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual void SDFile::close()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:109:3: error: 'sdfatfile' was not declared in this scope
   sdfatfile.close();
   ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual SDFile::operator bool()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:112:10: error: 'sdfatfile' was not declared in this scope
   return sdfatfile.isOpen();
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual const char* SDFile::name()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:118:5: error: 'sdfatfile' was not declared in this scope
     sdfatfile.getName(filename, MAX_FILENAME_LEN);
     ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual boolean SDFile::isDirectory()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:127:10: error: 'sdfatfile' was not declared in this scope
   return sdfatfile.isDirectory();
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual File SDFile::openNextFile(uint8_t)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:43:22: error: 'FsFile' was not declared in this scope
   #define SDFAT_FILE FsFile
                      ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:130:3: note: in expansion of macro 'SDFAT_FILE'
   SDFAT_FILE file = sdfatfile.openNextFile();
   ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:131:7: error: 'file' was not declared in this scope
   if (file) return File(new SDFile(file));
       ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual void SDFile::rewindDirectory()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:135:3: error: 'sdfatfile' was not declared in this scope
   sdfatfile.rewindDirectory();
   ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: At global scope:
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:44:22: error: 'SdFs' does not name a type
   #define SDFAT_BASE SdFs
                      ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:190:2: note: in expansion of macro 'SDFAT_BASE'
  SDFAT_BASE sdfs;
  ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'bool SDClass::begin(uint8_t)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:152:11: error: 'sdfs' was not declared in this scope
    return sdfs.begin(SdioConfig(FIFO_SDIO));
           ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:152:33: error: 'FIFO_SDIO' was not declared in this scope
    return sdfs.begin(SdioConfig(FIFO_SDIO));
                                 ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:152:42: error: 'SdioConfig' was not declared in this scope
    return sdfs.begin(SdioConfig(FIFO_SDIO));
                                          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:156:10: error: 'sdfs' was not declared in this scope
   return sdfs.begin(SdSpiConfig(csPin, SHARED_SPI, SD_SCK_MHZ(16)));
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:156:40: error: 'SHARED_SPI' was not declared in this scope
   return sdfs.begin(SdSpiConfig(csPin, SHARED_SPI, SD_SCK_MHZ(16)));
                                        ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:156:66: error: 'SdSpiConfig' was not declared in this scope
   return sdfs.begin(SdSpiConfig(csPin, SHARED_SPI, SD_SCK_MHZ(16)));
                                                                  ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual File SDClass::open(const char*, uint8_t)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:43:22: error: 'FsFile' was not declared in this scope
   #define SDFAT_FILE FsFile
                      ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:163:3: note: in expansion of macro 'SDFAT_FILE'
   SDFAT_FILE file = sdfs.open(filepath, flags);
   ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:164:7: error: 'file' was not declared in this scope
   if (file) return File(new SDFile(file));
       ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual bool SDClass::exists(const char*)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:168:10: error: 'sdfs' was not declared in this scope
   return sdfs.exists(filepath);
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual bool SDClass::mkdir(const char*)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:171:10: error: 'sdfs' was not declared in this scope
   return sdfs.mkdir(filepath);
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual bool SDClass::rename(const char*, const char*)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:174:10: error: 'sdfs' was not declared in this scope
   return sdfs.rename(oldfilepath, newfilepath);
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual bool SDClass::remove(const char*)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:177:10: error: 'sdfs' was not declared in this scope
   return sdfs.remove(filepath);
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual bool SDClass::rmdir(const char*)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:180:10: error: 'sdfs' was not declared in this scope
   return sdfs.rmdir(filepath);
          ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual uint64_t SDClass::usedSize()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:183:21: error: 'sdfs' was not declared in this scope
   return (uint64_t)(sdfs.clusterCount() - sdfs.freeClusterCount())
                     ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'virtual uint64_t SDClass::totalSize()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:187:20: error: 'sdfs' was not declared in this scope
   return (uint64_t)sdfs.clusterCount() * (uint64_t)sdfs.bytesPerCluster();
                    ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: At global scope:
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:204:7: error: redefinition of 'class Sd2Card'
 class Sd2Card
       ^
In file included from C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:27:0,
                 from C:\Users\Frank\Documents\Arduino\sketch_nov19a\sketch_nov19a.ino:2:
C:\Users\Frank\Documents\Arduino\libraries\SdFat\src/SdFat.h:499:7: error: previous definition of 'class Sd2Card'
 class Sd2Card : public SdSpiCard {
       ^
In file included from C:\Users\Frank\Documents\Arduino\sketch_nov19a\sketch_nov19a.ino:2:0:
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'bool SdVolume::init(Sd2Card&)':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:218:13: error: 'class SDClass' has no member named 'sdfs'
   return SD.sdfs.vol() != nullptr;
             ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'uint8_t SdVolume::fatType()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:221:13: error: 'class SDClass' has no member named 'sdfs'
   return SD.sdfs.vol()->fatType();
             ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'uint32_t SdVolume::blocksPerCluster()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:224:13: error: 'class SDClass' has no member named 'sdfs'
   return SD.sdfs.vol()->sectorsPerCluster();
             ^
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h: In member function 'uint32_t SdVolume::clusterCount()':
C:\Arduino\hardware\teensy\avr\libraries\SD-Juse_Use_SdFat\src/SD.h:227:13: error: 'class SDClass' has no member named 'sdfs'
   return SD.sdfs.vol()->clusterCount();
             ^
C:\Users\Frank\Documents\Arduino\sketch_nov19a\sketch_nov19a.ino: In member function 'File mSD_Base::sd_open(uint32_t, const char*, uint32_t)':
sketch_nov19a:11: error: could not convert '0' from 'int' to 'File'
     else return 0;
                 ^
Mehrere Bibliotheken wurden für "SdFat.h" gefunden
 Benutzt: C:\Users\Frank\Documents\Arduino\libraries\SdFat
 Nicht benutzt: C:\Users\Frank\Documents\Arduino\libraries\SdFat-master
 Nicht benutzt: C:\Arduino\hardware\teensy\avr\libraries\SdFat-beta
 
@Frank B
Just ran @WMXZ's sketch as well and it works for me. Make sure you have the latest changes to the core files and the latest for LittleFS and SD libraries. I am also using Paul's SDFat lib from his fork.

EDIT: forgot - welcome to the party :)
 
Morning all, will Sync up again. Hopefully soon will be semi-stable enough to do another beta build of it.
 
Ok, seems to compile now :)
The trick was to use Pauls fork of SdFat.

I get a bunch of warnings:
C:\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h. Future versions will remove Time.h" [-Wcpp]
#warning "Please include TimeLib.h, not Time.h. Future versions will remove Time.h"

Is a fix planned?
 
@Frank B - glad you figured out the trick. Next beta release will probably have SDFat-beta in it - my guess.

As far as I know there is not fix planned, thats up to @WMXZ
 
I think I synced everything, but build problems... (mtp_test)
Code:
C:\arduino-1.8.13\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
D:\GitHub\mtp_responder-for-LittleFs\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:38:25: error: conflicting declaration 'LittleFS_RAM ramfs [5]'
   LittleFS_RAM ramfs[nsd]; // needs to be declared if LittleFS is used in storage.h
                         ^
In file included from C:\Users\kurte\Documents\Arduino\libraries\MTP_t4\src/MTP.h:36:0,
                 from D:\GitHub\mtp_responder-for-LittleFs\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:3:
C:\Users\kurte\Documents\Arduino\libraries\MTP_t4\src/Storage.h:45:21: note: previous declaration as 'LittleFS_RAM ramfs'
 extern LittleFS_RAM ramfs;
                     ^
D:\GitHub\mtp_responder-for-LittleFs\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino: In function 'void storage_configure(MTPStorage_SD*, const char**, const int*, const int*, SDClass*, int)':
D:\GitHub\mtp_responder-for-LittleFs\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:51:54: error: no matching function for call to 'MTPStorage_SD::setStorageNumbers(const char**&, const int*&, const int*&, const int&)'
     storage->setStorageNumbers(sd_str, cs, stype, nsd);
                                                      ^
In file included from C:\Users\kurte\Documents\Arduino\libraries\MTP_t4\src/MTP.h:36:0,
                 from D:\GitHub\mtp_responder-for-LittleFs\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:3:
C:\Users\kurte\Documents\Arduino\libraries\MTP_t4\src/Storage.h:173:8: note: candidate: virtual void MTPStorage_SD::setStorageNumbers(const char**, const int*, int)
   void setStorageNumbers(const char **sd_str, const int *cs, int num) override;
        ^
C:\Users\kurte\Documents\Arduino\libraries\MTP_t4\src/Storage.h:173:8: note:   candidate expects 3 arguments, 4 provided
D:\GitHub\mtp_responder-for-LittleFs\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:66:20: error: no match for 'operator[]' (operand types are 'LittleFS_RAM' and 'int')
           if(!ramfs[1].begin(RAM_DISK_STORAGE)) { Serial.println("No storage"); while(1);}
                    ^
D:\GitHub\mtp_responder-for-LittleFs\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:67:20: error: no match for 'operator[]' (operand types are 'LittleFS_RAM' and 'int')
           if(!ramfs[2].begin(buf1, sizeof(buf1))) { Serial.println("No storage"); while(1);}
                    ^
D:\GitHub\mtp_responder-for-LittleFs\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:91:36: error: no match for 'operator[]' (operand types are 'LittleFS_RAM' and 'int')
           uint32_t volCount = ramfs[ii].totalSize();
                                    ^
D:\GitHub\mtp_responder-for-LittleFs\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:92:47: error: no match for 'operator[]' (operand types are 'LittleFS_RAM' and 'int')
           uint32_t volFree  = volCount - ramfs[ii].usedSize();
                                               ^
Multiple libraries were found for "SD.h"
 Used: C:\Users\kurte\Documents\Arduino\libraries\SD
 Not used: C:\arduino-1.8.13\libraries\SD
 Not used: C:\arduino-1.8.13\hardware\teensy\avr\libraries\SD
Multiple libraries were found for "MTP.h"
 Used: C:\Users\kurte\Documents\Arduino\libraries\MTP_t4
 Not used: C:\Users\kurte\Documents\Arduino\libraries\MTP_t4_littlefs
Using library MTP_t4 at version 1.0.0-beta.1 in folder: C:\Users\kurte\Documents\Arduino\libraries\MTP_t4 
Using library SD at version 2.0.0 in folder: C:\Users\kurte\Documents\Arduino\libraries\SD 
Using library SdFat-beta at version 2.0.0-beta.8 in folder: C:\arduino-1.8.13\hardware\teensy\avr\libraries\SdFat-beta 
Using library SPI at version 1.0 in folder: C:\arduino-1.8.13\hardware\teensy\avr\libraries\SPI 
Using library LittleFS at version 1.0.0 in folder: C:\Users\kurte\Documents\Arduino\libraries\LittleFS 
Using library USB2 at version 0.9.0-beta.1 in folder: C:\Users\kurte\Documents\Arduino\libraries\USB2 
Using library Time at version 1.6 in folder: C:\arduino-1.8.13\hardware\teensy\avr\libraries\Time 
Error compiling for board Teensy 4.1.
 
@KurtE
The new version is meant as a replacement for MTP_t4. At some point, after we play a bit, and see what other changes @WMXZ has up his sleeve will probably issue a PR.

So basically delete your copy of MTP_t4.
 
Thanks, did that now it builds...

I edited the area in sketch:
Code:
#if DO_LITTLEFS==1
  const char *sd_str[]={"sdio","RAM0","RAM1","Propshield",/* "Winbond0",*/ "QSPI0"};     // edit to reflect your configuration
  const int typeStore[]={0,1,1,2,/*2,*/3};
  const int cs[] = {BUILTIN_SDCARD, 256, 256, 6, /*10,*/257};  // edit to reflect your configuration
Got rid of the second winbnd as I am setup with T4.1 with Flash/PSRAM, plugged into Propshield with SD in built in SD.

It built, but nothing shows up on PC nor anything in output in Serial terminal...
Will debug later... More on other diversions.
 
First - nothing ever appeared in Serial Monitor for me either if printed from the Sketch. Probably have to do the mod for MTP + Serial. Was never brave enough to try it :)

Anyway back to the the main issue. Just used your configuration with my setup since it pretty much mirrors yours and seems to be working for me. This is what I see.
Capture.PNG

This is my sketch just in case but going to check that the repo has the correct changes.
Code:
#include "Arduino.h"

#include "MTP.h"
#include "usb1_mtp.h"

#if HAVE_LITTLEFS==1        // is defined in storage.h
  #define DO_LITTLEFS 1     // set to zero if not wanted // needs LittleFS installed as library
  #define RAM_DISK_STORAGE (2'000'000)
  DMAMEM char buf1[400000];
#else
  #define DO_LITTLEFS 0
#endif


/****  Start device specific change area  ****/

  // edit SPI to reflect your configuration (following is fot T4.1)
  #define SD_MOSI 11
  #define SD_MISO 12
  #define SD_SCK  13

  #define SPI_SPEED SD_SCK_MHZ(16)  // adjust to sd card 

#if DO_LITTLEFS==1
  const char *sd_str[]={"sdio","RAM0","RAM1","Propshield",/* "Winbond0",*/ "QSPI0"};     // edit to reflect your configuration
  const int typeStore[]={0,1,1,2,/*2,*/3};
  const int cs[] = {BUILTIN_SDCARD, 256, 256, 6, /*10,*/257};  // edit to reflect your configuration
#else
  const int typeStore[]={0,0};
  const char *sd_str[]={"sdio","sd6"}; // edit to reflect your configuration
  const int cs[] = {BUILTIN_SDCARD,38}; // edit to reflect your configuration
#endif
  const int nsd = sizeof(cs)/sizeof(int);

// classes need to be declared here (in storage.h there are declared external)
SDClass sdx[nsd];
#if HAVE_LITTLEFS==1
  LittleFS_RAM ramfs[nsd]; // needs to be declared if LittleFS is used in storage.h
  LittleFS_SPIFlash spiFlash[nsd];
  LittleFS_QSPIFlash qspiFlash;
#endif

void storage_configure(MTPStorage_SD *storage, const char **sd_str, const int *cs, const int *stype, SDClass *sdx, int num)
{
    #if defined SD_SCK
      SPI.setMOSI(SD_MOSI);
      SPI.setMISO(SD_MISO);
      SPI.setSCK(SD_SCK);
    #endif

    storage->setStorageNumbers(sd_str, cs, stype, nsd);

    for(int ii=0; ii<nsd; ii++)
    { if(cs[ii] == BUILTIN_SDCARD)
      {
        if(!sdx[ii].sdfs.begin(SdioConfig(FIFO_SDIO))){Serial.println("No storage"); while(1);};
      }
      else if(cs[ii]<BUILTIN_SDCARD)
      {
        pinMode(cs[ii],OUTPUT); digitalWriteFast(cs[ii],HIGH);
        if(!sdx[ii].sdfs.begin(SdSpiConfig(cs[ii], SHARED_SPI, SPI_SPEED))) {Serial.println("No storage"); while(1);}
      }
      #if DO_LITTLEFS==1
        else if(cs[ii]==256) // LittleFS_RAM
        { 
          if(!ramfs[1].begin(RAM_DISK_STORAGE)) { Serial.println("No storage"); while(1);}
          if(!ramfs[2].begin(buf1, sizeof(buf1))) { Serial.println("No storage"); while(1);}
        }
        else if(stype[ii] == 2) {
          if(!spiFlash[ii].begin(cs[ii], SPI)) { Serial.println("No storage"); while(1);}
        }
       else if(stype[ii] == 3) {
          if(!qspiFlash.begin()) { Serial.println("No storage"); while(1);}
        }
       else {
        Serial.println("Storage Type Not supported");
        while(1) {};
       }
      
      #endif
      if(cs[ii]<256)
      {
        uint32_t volCount = sdx[ii].sdfs.clusterCount();
        uint32_t volFree  = sdx[ii].sdfs.freeClusterCount();
        uint32_t volClust = sdx[ii].sdfs.sectorsPerCluster()*512;
        Serial.printf("Storage %d %d %s %d %d %d\n",ii,cs[ii],sd_str[ii],volCount,volFree,volClust);
      }
      #if DO_LITTLEFS==1
        else if(cs[ii]==256) // LittleFS_RAM
        {
          uint32_t volCount = ramfs[ii].totalSize();
          uint32_t volFree  = volCount - ramfs[ii].usedSize();
          uint32_t volClust = 1;
          Serial.printf("Storage %d %d %s %d %d %d\n",ii,cs[ii],sd_str[ii],volCount,volFree,volClust);
        }
        else if(stype[ii] == 2) // LittleFS_RAM
        {
          uint32_t volCount = spiFlash[ii].totalSize();
          uint32_t volFree  = volCount - spiFlash[ii].usedSize();
          uint32_t volClust = 1;
          Serial.printf("Storage %d %d %s %d %d %d\n",ii,cs[ii],sd_str[ii],volCount,volFree,volClust);
        }
        else if(stype[ii] == 3) // LittleFS_RAM
        {
          uint32_t volCount = qspiFlash.totalSize();
          uint32_t volFree  = volCount - qspiFlash.usedSize();
          uint32_t volClust = 1;
          Serial.printf("Storage %d %d %s %d %d %d\n",ii,cs[ii],sd_str[ii],volCount,volFree,volClust);
        }
      #endif
    }
}
/****  End of device specific change area  ****/

MTPStorage_SD storage;
MTPD       mtpd(&storage);

void logg(uint32_t del, const char *txt)
{ static uint32_t to;
  if(millis()-to > del)
  {
    Serial.println(txt); 
    to=millis();
  }
}

void setup()
{ 
  while(!Serial && millis()<3000); 
  Serial.println("MTP_test");
  
  usb_mtp_configure();
  storage_configure(&storage, sd_str, cs, typeStore, sdx, nsd);

  #if DO_LITTLEFS==3
  //todo:  
  // store some files into disks (but only once)
  for(int ii=0; ii<10;ii++)
  { char filename[80];
    sprintf(filename,"test_%d.txt",ii);
    if(!ramfs[0].exists(filename))
    {
      File file=ramfs[0].open(filename,FILE_WRITE_BEGIN);
      file.println("This is a test line");
      file.close();
    }
  }
  #endif

  Serial.println("Setup done");
  Serial.flush();
}

void loop()
{ 
  mtpd.loop();

  //logg(1000,"loop");
  //asm("wfi"); // may wait forever on T4.x
}

EDIT: Just checked the repo is up to date. Are you sure you got the propshield CS on pin 6 of the T4.1? Can't tell you how many times I messed that one up along with the correct SPI port. Right now it is using begin(CS, SPI).
 
This is a bit unstable or I'm doing something wrong (?!?
I even had trouble to get the most simple "listfiles" example to work, until I switched fromt GCC 9 to GCC 5. (WTF? The first time GCC9 "does not work"? -> must be a problem with the code)

Maybe this is root cause for this:
No Luck with MTP. Sometimes I see a "Teensy" device, but it seems to crash if I click on it. Nothing happens. Windows-Explorer becomes slow.

I'll wait some time.. :)
I've seen somewhere "SD with 16MHz" or "Teensy 450MzZ" -
What are the reasons for slow speeds? Maybe I can help with that?
 
Hi Frank
Not sure why you are having an issue - did you update the core files to the latest version. FS.h and USB_desc been changing, same goes with the FS library.

As for the SD Card with 16Mhz, tested with my external card reader and only seems to work at 16Mhz. Think the speed for SDIO work at 33Mhz but it something that I should check :) A PR, https://github.com/PaulStoffregen/cores/pull/506, was incorporated to fix having to run the T4 at 450mhz, so if you have the latest core that should work. Right now I am running 1.53-beta4 along with all the latest changes (SD, SDFAT-beta and LittleFS libraries along with the latest core from yesterday.)

Two things on Teensy not showing up. Big one was the 450Mhz limit which is fixed in the latest core. The second issue if Teensy doesn't show could be a wrong config in the test sketch for your setup.
 
Maybe it's time to package up 1.54-beta5? I had hoped to play with MSC and bring it into USBHost_t36 and with FS/File interface, but maybe we need this now so everyone can easily sync up with the massive number of changes over the last few weeks.
 
Maybe it's time to package up 1.54-beta5? I had hoped to play with MSC and bring it into USBHost_t36 and with FS/File interface, but maybe we need this now so everyone can easily sync up with the massive number of changes over the last few weeks.

This is probably a good idea. A beta5 at this point is probably a good idea considering all the changes. Guess beta6 can have MSC/usbhost_t36.
 
This is probably a good idea. A beta5 at this point is probably a good idea considering all the changes. Guess beta6 can have MSC/usbhost_t36.

That sounds like a good plan for TD 1.54 Beta5 where all stands. That will make the MTP cleanup easier to be consistent across all the changes.

BTW: I ran Three T_4.1's for 10 hours no problem on LittleFS_RAM
Code:
//#define ROOTONLY // NORMAL is NOT DEFINED!
#define NUMDIRS 25  // When not ROOTONLY must be 1 or more
...
#define SUBADD 10	// bytes added each pass (*times file number)
#define BIGADD 100	// bytes added each pass - bigger will quickly consume more space
#define MAXNUM 26	// ALPHA A-Z is 26, less for fewer files

Those params have the RAM disk right up to FULL with the LFSintegrity file cycling process it does - lots of data writes: 3,342,608,850 and lots more reads with verify of data at all steps seems to have for sure wrapped uint32_t: 2,105,295,918 byte read
No file or directory integrity issues.
Though ODD that both of these 'disks' hold under 240KB (from directory sum across 26 dirs and the Root - but show : Bytes Used: 477184 and Bytes Used: 459520
Code:
 Total 646 files of Size 240840 Bytes
Bytes Used: 477184, Bytes Total:489984

	 Loop Count: 58428 (#fileCycle=20448874), Bytes read 2105664678, written 3342608850, #Files=646
[601.28 M](  0.02 elap) Awaiting input 0123456789RdchkFqvplmux? loops left 0 >
and a second:
Code:
 Total 632 files of Size 228800 Bytes
Bytes Used: 459520, Bytes Total:489984

	 Loop Count: 58427 (#fileCycle=20448160), Bytes read 2105295918, written 3342489850, #Files=632
[601.40 M](  0.02 elap) Awaiting input 0123456789RdchkFqvplmux? loops left 0 >
 
Also had not tried before but LittleFS_RAM works from EXTMEM.

Code:
#ifdef TEST_RAM
LittleFS_RAM myfs;
[B]EXTMEM char buf[8*1024*1024];[/B]	// USE DMAMEM for more memory than ITCM allows - or remove
//DMAMEM char buf[490000];	// USE DMAMEM for more memory than ITCM allows - or remove
char szDiskMem[] = "RAM_DISK";

I have two with 8MB PSRAM and one with 16MB
 
Using TD1.54-beta5 plus the latest and greatest MTP_t4 repository (https://github.com/WMXZ-EU/MTP_t4) and the following modified mtp_test.ino sketch with no other changes to the library itself I can get a maximum of 6 devices at 1 time showing in windows explorer:
Capture.PNG

As for all MTP directory functions work - i know copy and paste from the device definitely works. Just make sure you delete MTP_littlefs if you have it in your library folder. Dont need it anymore. Here is the modified sketch. It kind of the kitchen sink just for demo purposes.
Code:
#include "Arduino.h"
#include "SD.h"

#include "MTP.h"
#include "usb1_mtp.h"

#define HAVE_LITTLEFS 1 // set to zero if no LtttleFS is existing or to be used

#if HAVE_LITTLEFS==1        // is defined in storage.h
  #define DO_LITTLEFS 1     // set to zero if not wanted // needs LittleFS installed as library
  #define RAM_DISK_STORAGE (8'000'000)
  DMAMEM char buf[40000];

  #include "LittleFS.h"
#else
  #define DO_LITTLEFS 0
#endif


/****  Start device specific change area  ****/

  // edit SPI to reflect your configuration (following is fot T4.1)
  #define SD_MOSI 11
  #define SD_MISO 12
  #define SD_SCK  13

  #define SPI_SPEED SD_SCK_MHZ(16)  // adjust to sd card 

#if DO_LITTLEFS==1
  const char *sd_str[]={"sdio", "sd1", "RAM0", "RAM1","QSPI", "Propshield"/*, "Winbond"*/};     // edit to reflect your configuration
  const int cs[] = {BUILTIN_SDCARD, 4,130, 131, 132, 133/*, 134*/};  // edit to reflect your configuration
#else
  const char *sd_str[]={"sdio","sd6"}; // edit to reflect your configuration
  const int cs[] = {BUILTIN_SDCARD, 38}; // edit to reflect your configuration
#endif
  const int nsd = sizeof(cs)/sizeof(int);

// classes need to be declared here (in storage.h there are declared external)
SDClass sdx[nsd];
#if HAVE_LITTLEFS==1
  LittleFS_RAM ramfs0; // needs to be declared if LittleFS is used in storage.h
  LittleFS_RAM ramfs1; // needs to be declared if LittleFS is used in storage.h
  LittleFS_QSPIFlash qspifs;
  LittleFS_SPIFlash spifs0;
  LittleFS_SPIFlash spifs1;
#endif

MTPStorage_SD storage;
MTPD       mtpd(&storage);

void storage_configure()
{
    #if defined SD_SCK
      SPI.setMOSI(SD_MOSI);
      SPI.setMISO(SD_MISO);
      SPI.setSCK(SD_SCK);
    #endif

    for(int ii=0; ii<nsd; ii++)
    { if(cs[ii] == BUILTIN_SDCARD)
      {
        if(!sdx[ii].sdfs.begin(SdioConfig(FIFO_SDIO))) {Serial.println("No storage"); while(1);};
        storage.addFilesystem(sdx[ii],cs[ii],sd_str[ii]);
      }
      else if(cs[ii] < 128)
      {
        pinMode(cs[ii],OUTPUT); digitalWriteFast(cs[ii],HIGH);
        if(!sdx[ii].sdfs.begin(SdSpiConfig(cs[ii], SHARED_SPI, SPI_SPEED))) {Serial.println("No storage"); while(1);}
        storage.addFilesystem(sdx[ii],cs[ii],sd_str[ii]);
      }
      #if DO_LITTLEFS==1
        else if(cs[ii]==130) // LittleFS_RAM
        { if(!ramfs0.begin(RAM_DISK_STORAGE)) { Serial.println("No storage"); while(1);}
          storage.addFilesystem(ramfs0,cs[ii],sd_str[ii]);
        }
        else if(cs[ii]==131) // LittleFS_RAM
        { if(!ramfs1.begin(buf, sizeof(buf))) { Serial.println("No storage"); while(1);}
          storage.addFilesystem(ramfs1,cs[ii],sd_str[ii]);
        }
        else if(cs[ii]==132) // LittleFS_QSPI
        { if(!qspifs.begin()) { Serial.println("No storage"); while(1);}
          storage.addFilesystem(qspifs,cs[ii],sd_str[ii]);
        }
        else if(cs[ii]==133) //Propshield
        { if(!spifs0.begin(6)) { Serial.println("No storage"); while(1);}
          storage.addFilesystem(spifs0,cs[ii],sd_str[ii]);
        }
        else if(cs[ii]==134) //Winbond
        { if(!spifs1.begin(10)) { Serial.println("No storage"); while(1);}
          storage.addFilesystem(spifs1,cs[ii],sd_str[ii]);
        }
      #endif
      if(cs[ii] < 128 || cs[ii] == BUILTIN_SDCARD)
      {
        uint64_t totalSize = sdx[ii].totalSize();
        uint64_t usedSize  = sdx[ii].usedSize();
        Serial.printf("Storage %d %d %s ",ii,cs[ii],sd_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
      }
      #if DO_LITTLEFS==1
        else if(cs[ii]==130) // LittleFS_RAM
        {
        uint64_t totalSize = ramfs0.totalSize();
        uint64_t usedSize  = ramfs0.usedSize();
        Serial.printf("Storage %d %d %s ",ii,cs[ii],sd_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
        }
        else if(cs[ii]==131) // LittleFS_RAM
        {
        uint64_t totalSize = ramfs1.totalSize();
        uint64_t usedSize  = ramfs1.usedSize();
        Serial.printf("Storage %d %d %s ",ii,cs[ii],sd_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
        }
        else
        if(cs[ii]==132) // LittleFS_QSPI
        {
        uint64_t totalSize = qspifs.totalSize();
        uint64_t usedSize  = qspifs.usedSize();
        Serial.printf("Storage %d %d %s ",ii,cs[ii],sd_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
        }
        if(cs[ii]==133) //Propshield
        {
        uint64_t totalSize = spifs0.totalSize();
        uint64_t usedSize  = spifs0.usedSize();
        Serial.printf("Storage %d %d %s ",ii,cs[ii],sd_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
        }
        if(cs[ii]==134) // WINBOND
        {
        uint64_t totalSize = spifs1.totalSize();
        uint64_t usedSize  = spifs1.usedSize();
        Serial.printf("Storage %d %d %s ",ii,cs[ii],sd_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
        }
        
      #endif
    }
}
/****  End of device specific change area  ****/

void logg(uint32_t del, const char *txt)
{ static uint32_t to;
  if(millis()-to > del)
  {
    Serial.println(txt); 
    to=millis();
  }
}

void setup()
{ 
  while(!Serial && millis()<3000); 
  Serial.println("MTP_test");
  
  usb_mtp_configure();
  storage_configure();

  #if DO_LITTLEFS==1
  // store some files into disks (but only once)
  for(int ii=0; ii<10;ii++)
  { char filename[80];
    sprintf(filename,"test_%d.txt",ii);
    if(!ramfs0.exists(filename))
    {
      File file=ramfs0.open(filename,FILE_WRITE_BEGIN);
      file.println("This is a test line");
      file.close();
    }
  }
  #endif

  Serial.println("Setup done");
  Serial.flush();
}

void loop()
{ 
  mtpd.loop();

  //logg(1000,"loop");
  //asm("wfi"); // may wait forever on T4.x
}
 
@mjs513 - seems @KurtE got your test to work?

I've not had such results yet? No Errors - just not appearing? Pairing down the multiple arrays and such ... not yet having success ...
 
Latest fresh install of beta #5, latest github-rep from WMXZ, sketch from "examples":
My PC shows the teensy, and size of drives, but navigating to the drives "ram" or "sdio" shows a hourglass only (windows)

SD Card is freshly formatted with the official tool, and I copied a bunch of files to it.

I also see a warning in SdFat:
Code:
:\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatPartition.cpp: In member function 'bool ExFatPartition::freeChain(uint32_t)':
C:\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatPartition.cpp:328:5: warning: 'next' may be used uninitialized in this function [-Wmaybe-uninitialized]
  328 |     if ((cluster + 1) != next || status == 0) {
      |     ^~
Indeed there is a chance that it may be uninitialized, but I think that's not the problem here.
Another warning:
Code:
C:\Users\Frank\Documents\Arduino\libraries\MTP_t4-master\src\MTP.cpp: In member function 'void MTPD::write(const char*, int)':
C:\Users\Frank\Documents\Arduino\libraries\MTP_t4-master\src\MTP.cpp:875:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  875 |         if(!write_length_) dst=tx_data_buffer;   write_length_ += len;
      |         ^~
C:\Users\Frank\Documents\Arduino\libraries\MTP_t4-master\src\MTP.cpp:875:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  875 |         if(!write_length_) dst=tx_data_buffer;   write_length_ += len;
      |                                                  ^~~~~~~~~~~~~
Compiling library "USB2-master"
 
Latest fresh install of beta #5, latest github-rep from WMXZ, sketch from "examples":
My PC shows the teensy, and size of drives, but navigating to the drives "ram" or "sdio" shows a hourglass only (windows)
I had that overnight after updating FS.h etc.
It is due to Paul changing file.size() to 64 bit.
Should be solved by now (I cleaned up also mtp_test example)
 
Using the latest - at least it was 40 mins ago ...

Taking current mtp-test.ino I merged in added 'disks' like @mjs513 did in his posted sketch p#369 using the new methods?
MTP_b5.png

Notes:
Win10 GREEN - still looking bar (pic above) - stays on a long time? And taking longer to come up? But disk I/O works.
With this Seremu whatever the Serial goes true in setup before anything can print
See end of loop - I added this to show proof of life while waiting : while ( Serial.available() ) {char ch = Serial.read(); Serial.write( ch ); }
Also there entering 'r' or 'q' causes File Write to a disk in loop, and it works to write.
> but after first 'read' of file by the PC it never updates
I did a file 'drag' copy once and it worked.
Notepad (or WinKey+R) cannot access file by name "This PC\Teensy\RAM1\test_1.txt"
Notepad can 'navigate' to ""This PC\Teensy\RAM1" and see and open test_1.txt though

Code for mtp-testT.ino
Code:
#include "Arduino.h"

#include "SD.h"
#include "MTP.h"
#include "usb1_mtp.h"

#define HAVE_LITTLEFS 1 // set to zero if no LtttleFS is existing or to be used

/****  Start device specific change area  ****/

// edit SPI to reflect your configuration (following is fot T4.1)
#define SD_MOSI 11
#define SD_MISO 12
#define SD_SCK  13

#define SPI_SPEED SD_SCK_MHZ(16)  // adjust to sd card 

// SDClasses

const char *sd_str[] = {"sdio", "sd10", "QSPI"}; // edit to reflect your configuration
const int cs[] = {BUILTIN_SDCARD, 10, 132}; // edit to reflect your configuration
const int nsd = sizeof(cs) / sizeof(int);

SDClass sdx[nsd];

//LittleFS classes
#if HAVE_LITTLEFS==1
#include "LittleFS.h"
const char *lfs_str[] = {"RAM1", "RAM2"};  // edit to reflect your configuration
const int lfs_size[] = {2'000'000, 4'000'000};
const int nfs = sizeof(lfs_size) / sizeof(int);

LittleFS_RAM ramfs[nfs]; // needs to be declared if LittleFS is used in storage.h
LittleFS_QSPIFlash qspifs;
#endif

MTPStorage_SD storage;
MTPD       mtpd(&storage);

void storage_configure()
{
#if defined SD_SCK
  SPI.setMOSI(SD_MOSI);
  SPI.setMISO(SD_MISO);
  SPI.setSCK(SD_SCK);
#endif

  for (int ii = 0; ii < nsd; ii++)
  { if (cs[ii] == BUILTIN_SDCARD)
    {
      if (!sdx[ii].sdfs.begin(SdioConfig(FIFO_SDIO))) {Serial.println("No storage"); while (1);};
      storage.addFilesystem(sdx[ii], sd_str[ii]);
    }

    else if (cs[ii] == 132) // LittleFS_QSPI
    { if (!qspifs.begin()) { Serial.println("No storage"); while (1);}
      storage.addFilesystem( qspifs, sd_str[ii] );
    }
    else if (cs[ii] < BUILTIN_SDCARD)
    {
      pinMode(cs[ii], OUTPUT); digitalWriteFast(cs[ii], HIGH);
      if (!sdx[ii].sdfs.begin(SdSpiConfig(cs[ii], SHARED_SPI, SPI_SPEED))) {Serial.println("No storage"); while (1);}
      storage.addFilesystem(sdx[ii], sd_str[ii]);
    }
    uint64_t totalSize = sdx[ii].totalSize();
    uint64_t usedSize  = sdx[ii].usedSize();
    Serial.printf("Storage %d %d %s ", ii, cs[ii], sd_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
  }
#if HAVE_LITTLEFS==1
  for (int ii = 0; ii < nfs; ii++)
  {
    if (!ramfs[ii].begin(lfs_size[ii])) { Serial.println("No storage"); while (1);}
    storage.addFilesystem(ramfs[ii], lfs_str[ii]);

    uint64_t totalSize = ramfs[ii].totalSize();
    uint64_t usedSize  = ramfs[ii].usedSize();
    Serial.printf("Storage %d %s ", ii, lfs_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);

  }
#endif
}
/****  End of device specific change area  ****/

// Call back for file timestamps.  Only called for file create and sync(). needed by SDFat-beta
#include "TimeLib.h"
void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10)
{ *date = FS_DATE(year(), month(), day());
  *time = FS_TIME(hour(), minute(), second());
  *ms10 = second() & 1 ? 100 : 0;
}

void logg(uint32_t del, const char *txt)
{ static uint32_t to;
  if (millis() - to > del)
  {
    Serial.println(txt);
    to = millis();
  }
}

void setup()
{
  while (!Serial);
  Serial.println("MTP_test");

  // Set Time callback // needed for SDFat-beta
  FsDateTime::callback = dateTime;

  usb_mtp_configure();
  storage_configure();

#if HAVE_LITTLEFS==1
  // store some files into disks (but only once)
  for (int ii = 0; ii < 10; ii++)
  { char filename[80];
    sprintf(filename, "test_%d.txt", ii);
    if (!ramfs[0].exists(filename))
    {
      File file = ramfs[0].open(filename, FILE_WRITE_BEGIN);
      file.println("This is a test line");
      file.close();
    }
  }
#endif

  const char *str = "test1.txt";
  if (sdx[0].exists(str)) sdx[0].remove(str);
  File file = sdx[0].open(str, FILE_WRITE_BEGIN);
  file.println("This is a test line");
  file.close();

  Serial.println("\n**** dir of sd[0] ****");
  sdx[0].sdfs.ls();
  Serial.println();

  Serial.println("Setup done");
  Serial.flush();
}

void loop()
{
  mtpd.loop();

#if HAVE_LITTLEFS==1
  while ( Serial.available() ) {
    char ch = Serial.read();
    char buff[12];
    if ( ch == 'q' ) {
      File file3 = qspifs.open("/qspi.txt", FILE_WRITE);
      if ( 0 == file3 ) {
        Serial.printf( "\tXXX\tXXX\tXXX\tXXX\tFail File open {mkdir?}\n" );
      }
      else {
        int ii;
        for ( ii = 0; ii < 32; ii++ ) {
          file3.write( &ch , 1 );
        }
        ii = sprintf( buff, "%lu> ", micros() );
        file3.write( buff , ii );
        file3.close();
        Serial.printf( "qspiffs%s\n", buff );
      }
    }

    if ( ch == 'r' ) {
      File file3 = ramfs[1].open("/RAM0.txt", FILE_WRITE);
      if ( 0 == file3 ) {
        Serial.printf( "\tXXX\tXXX\tXXX\tXXX\tFail File open {mkdir?}\n" );
      }
      else {
        int ii;
        for ( ii = 0; ii < 32; ii++ ) {
          file3.write( &ch , 1 );
        }
        ii = sprintf( buff, "%lu> ", micros() );
        file3.write( buff , ii );
        file3.close();
        Serial.printf( "ramfs0%s\n", buff );
      }
    }
    Serial.write( ch );
  }
#else
  while ( Serial.available() ) {
    char ch = Serial.read();
    Serial.write( ch );
  }
#endif
  //logg(1000,"loop");
  //asm("wfi"); // may wait forever on T4.x
}
 
Some MTP testing issues and successes posted in MPT Thread: https://forum.pjrc.com/threads/43050-MTP-Responder-Contribution?p=260290&viewfull=1#post260290. Summary for reference
Code:
Copy/Pasting
	1. Between devices on Teensy fails and hangs from doing anything else.
	2. Disabling and enabling does not work.  Can do it but Teensy does not show up in Win Explorer after re-enabling
	3. Copying from PC to devices works for a txt and imgs. Tested with a PDF buf funny same PDF copied to 5 devices sucessfully and opened correct but when copied to the 6 (propshield flash) failed and lost Propshield in Explorer.  When I restared T4.1 file did actually copy to Propshield..  May just have been a glitch.
	4. Coping from all devices worked for me.
	
Deleting
	1. Able to delete files from all devices
	2. Can do multiple file deletions
	3. Can not delete a directory with files in it. Have to delete files first. This was on the SD Cards (external and Internal).  However it does work on qspi, ram and SPI flash
	
Move - Create Directory - Rename
	1. Created a directory on each device and renamed it successfully.
	2. After creating a directory moved a file from that device into the newly created directory no issue
	3. Restarted and everything was where it was created.
	4. Also copied file from desktop into sub directory successfully

@defragster just tried opening a file direct using Notepad++ and worked. Also double clicked on most of the files and they opened in the correct apps. At least images, txt and pdfs
 
Back
Top