LittleFS port to Teensy/SPIFlash

@mjs513 - did a build from your test - my machine shows device Teensy MTP Disk - but 'Unavailable' ...

I started with mtp-test.ino - but replaced with your posted code dropping the pin13 toggle?

It built fine : on a T_4.0 with Audio card - so something isn't set right perhaps ...

Not sure about the 'locked' - I was here late too - didn't see that and didn't try to do it ... fixed now.

Chip select is defaulted to pin 6 :) and defaults to SPI for now.
 
Here's a quick & dirty workaround which (hopefully) lets QSPI work properly.

https://github.com/PaulStoffregen/LittleFS/commit/1fa4f14828f90856b0cb566930d2870303d56d3f

Well good news and bad news. Good news it still compiles but now it got worse. Every time I recycle power I get different directory results.
Run1:
Code:
printDirectory
--------------
FILE	9px_0001.bmp		307254
FILE	9px_0003.bmp		307254
FILE	PRINTOUTPUT2.txt		3780
FILE	file1		176
FILE	file2		224
FILE	file3		224
Run 2
Code:
printDirectory
--------------
FILE	9px_0001.bmp		307254
FILE	9px_0003.bmp		307254
FILE	PRINTOUTPUT2.txt		3780
FILE	file1		176
FILE	file2		224
FILE	file30		112
FILE	file3		224
Run 3
Code:
printDirectory
--------------
FILE	9px_0001.bmp		307254
FILE	9px_0003.bmp		307254
FILE	PRINTOUTPUT2.txt		3780
FILE	file10		144
FILE	file20		128
FILE	file2		224
FILE	file3		224
and it doesn't seem to be picking up any of the directories?
 
Ugh - well, so much for that workaround!

Looks like I need to really dig into what's wrong with QSPI. Things are crazy busy here at PJRC right now, so I probably won't be able to do much for another couple days. Sorry. :(
 
Ugh - well, so much for that workaround!

Looks like I need to really dig into what's wrong with QSPI. Things are crazy busy here at PJRC right now, so I probably won't be able to do much for another couple days. Sorry. :(

Not a problem - have enough stuff to keep busy :). Think I am going to revert the changes though - worked better before.
 
I left sub dirs on before testing files - have to format and restart but dirs look still missing.

Fir output below is after running the second after restart does not show 1_dir/:
Code:
printDirectory QSPI_DISK
--------------DIR	0_dir / 
	FILE	B_file.txt		510
	FILE	C_file.txt		520
	FILE	X_file.txt		730
	FILE	Y_file.txt		740
[B]DIR	1_dir / 
	FILE	A_file.txt		600
	FILE	B_file.txt		510
	FILE	C_file.txt		520
	FILE	D_file.txt		530
	FILE	E_file.txt		540
	FILE	F_file.txt		550
	FILE	G_file.txt		560
	FILE	H_file.txt		570
	FILE	I_file.txt		580
	FILE	J_file.txt		590
	FILE	K_file.txt		600
	FILE	L_file.txt		610
	FILE	M_file.txt		620
	FILE	N_file.txt		630
	FILE	O_file.txt		640
	FILE	P_file.txt		650
	FILE	Q_file.txt		660
	FILE	R_file.txt		670
	FILE	S_file.txt		680
	FILE	T_file.txt		690
	FILE	U_file.txt		700
	FILE	V_file.txt		710
	FILE	W_file.txt		720
	FILE	X_file.txt		730
	FILE	Y_file.txt		740
	FILE	Z_file.txt		750[/B]
DIR	2_dir / 
	FILE	B_file.txt		510
	FILE	C_file.txt		520
	FILE	F_file.txt		550
	FILE	G_file.txt		560
DIR	3_dir / 
	FILE	D_file.txt		530
	FILE	E_file.txt		540
	FILE	H_file.txt		570
	FILE	I_file.txt		580
DIR	4_dir / 
	FILE	F_file.txt		550
	FILE	G_file.txt		560
	FILE	J_file.txt		590
	FILE	K_file.txt		600
DIR	6_dir / 
	FILE	J_file.txt		590
	FILE	K_file.txt		600
	FILE	N_file.txt		630
	FILE	O_file.txt		640
DIR	7_dir / 
	FILE	L_file.txt		610
	FILE	M_file.txt		620
	FILE	P_file.txt		650
	FILE	Q_file.txt		660
DIR	8_dir / 
	FILE	N_file.txt		630
	FILE	O_file.txt		640
	FILE	R_file.txt		670
	FILE	S_file.txt		680
DIR	9_dir / 
	FILE	P_file.txt		650
	FILE	Q_file.txt		660
	FILE	U_file.txt		700

And after restart:
>> ALSO 9_dir shows T_file where above does not, and root S_file is displayed::
Code:
printDirectory QSPI_DISK
--------------DIR	0_dir / 
	FILE	B_file.txt		510
	FILE	C_file.txt		520
	FILE	X_file.txt		730
	FILE	Y_file.txt		740
DIR	2_dir / 
	FILE	B_file.txt		510
	FILE	C_file.txt		520
	FILE	F_file.txt		550
	FILE	G_file.txt		560
DIR	3_dir / 
	FILE	D_file.txt		530
	FILE	E_file.txt		540
	FILE	H_file.txt		570
	FILE	I_file.txt		580
DIR	4_dir / 
	FILE	F_file.txt		550
	FILE	G_file.txt		560
	FILE	J_file.txt		590
	FILE	K_file.txt		600
DIR	5_dir / 
	FILE	H_file.txt		570
	FILE	I_file.txt		580
	FILE	L_file.txt		610
	FILE	M_file.txt		620
DIR	6_dir / 
	FILE	J_file.txt		590
	FILE	K_file.txt		600
	FILE	N_file.txt		630
	FILE	O_file.txt		640
DIR	7_dir / 
	FILE	L_file.txt		610
	FILE	M_file.txt		620
	FILE	P_file.txt		650
	FILE	Q_file.txt		660
DIR	8_dir / 
	FILE	N_file.txt		630
	FILE	O_file.txt		640
	FILE	R_file.txt		670
	FILE	S_file.txt		680
DIR	9_dir / 
	FILE	P_file.txt		650
	FILE	Q_file.txt		660
	FILE	T_file.txt		690
	FILE	U_file.txt		700
FILE	S_file.txt		680
 
With QSPI reformat using ROOT file only.

:: 'f'ormat, Repower T_4.1, enter '1' a few times and it fails Q_file.txt. Then a DIR shows No Files?
> Restart and Repower of T_4.1 both show empty DIR after these files were created
Code:
..........................................
Chip erased in 24 seconds.
Format Complete!
 MUST repower the Teensy after Format !

T:\tCode\littleFS\LFSintegrity\LFSintegrity.ino Nov 10 2020 16:11:25
LittleFS Test : File Integrity
QSPI flash begin
Flash ID: EF 40 18
Flash size is 16.00 Mbyte
attemping to mount existing media
couldn't mount media, attemping to format
  waited 26732 us
  waited 122 us
  waited 24665 us
  waited 123 us
attemping to mount freshly formatted media
success
printDirectory QSPI_DISK
--------------
 0, 1-9 '#' passes continue loop before Pause
 'r' Restart Teensy
 'd' Directory of LittleFS
 'c' Continuous Loop
 'h' Hundred loops
 'k' Thousand loops
 'f' Format then Restart : 'SPI EraseEverything'
 'v' Verbose All Dir Prints - TOGGLE
 'p' Pause after all Dir prints - TOGGLE
 '?' Help list
[  0.01] Awaiting input 0123456789rdchkfvp? loops left 0
printDirectory QSPI_DISK
--------------
:: /B_file.txt   waited 102 us
  waited 23780 us
  waited 360 us
  waited 355 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ B 
:: /C_file.txt   waited 102 us
  waited 23797 us
  waited 362 us
  waited 361 us
  waited 78 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ C 
[  0.30] Awaiting input 0123456789rdchkfvp? loops left 0
:: /D_file.txt   waited 102 us
  waited 23701 us
  waited 363 us
  waited 361 us
  waited 88 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ D 
:: /E_file.txt   waited 102 us
  waited 24620 us
  waited 362 us
  waited 361 us
  waited 100 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ E 
[  0.40] Awaiting input 0123456789rdchkfvp? loops left 0
:: /F_file.txt   waited 102 us
  waited 25822 us
  waited 360 us
  waited 361 us
  waited 112 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ F 
:: /G_file.txt   waited 102 us
  waited 23762 us
  waited 360 us
  waited 361 us
  waited 123 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ G 
[  0.43] Awaiting input 0123456789rdchkfvp? loops left 0
:: /H_file.txt   waited 102 us
  waited 25996 us
  waited 363 us
  waited 360 us
  waited 135 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ H 
:: /I_file.txt   waited 101 us
  waited 23806 us
  waited 361 us
  waited 361 us
  waited 145 us
  waited 25552 us
  waited 355 us
  waited 73 us
printDirectory QSPI_DISK --Add---- ++ I 
[  0.46] Awaiting input 0123456789rdchkfvp? loops left 0
:: /J_file.txt   waited 102 us
  waited 24679 us
  waited 362 us
  waited 361 us
  waited 156 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ J 
:: /K_file.txt   waited 102 us
  waited 25731 us
  waited 361 us
  waited 361 us
  waited 168 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ K 
[  0.49] Awaiting input 0123456789rdchkfvp? loops left 0
:: /L_file.txt   waited 103 us
  waited 26994 us
  waited 361 us
  waited 360 us
  waited 178 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ L 
:: /M_file.txt   waited 102 us
  waited 24685 us
  waited 361 us
  waited 361 us
  waited 191 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ M 
[  0.52] Awaiting input 0123456789rdchkfvp? loops left 0
:: /N_file.txt   waited 102 us
  waited 26967 us
  waited 361 us
  waited 360 us
  waited 202 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ N 
:: /O_file.txt   waited 103 us
  waited 24688 us
  waited 361 us
  waited 360 us
  waited 213 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ O 
[  0.58] Awaiting input 0123456789rdchkfvp? loops left 0
:: /P_file.txt   waited 102 us
  waited 23799 us
  waited 364 us
  waited 360 us
  waited 224 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ P 
:: /Q_file.txt   waited 24644 us
  waited 357 us
  waited 103 us
  waited 102 us
  waited 92 us
  waited 130 us
  waited 24730 us
  waited 362 us
  waited 360 us
  waited 235 us
  waited 26697 us
  waited 98 us
[B]printDirectory QSPI_DISK --[COLOR="#FF0000"]Add---- ++ Q Fail File open /Q_file.txt[/COLOR][/B]
[  0.61] Awaiting input 0123456789rdchkfvp? loops left 0
[B]printDirectory QSPI_DISK[/B]
--------------
[  0.78] Awaiting input 0123456789rdchkfvp? loops left 0

[  0.78] Awaiting input 0123456789rdchkfvp? loops left 0
printDirectory QSPI_DISK
--------------
[  0.87] Awaiting input 0123456789rdchkfvp? loops left 0
[  0.87] Awaiting input 0123456789rdchkfvp? loops left 0

Repowered - no new format - mounts exisiting media. Below is repeating those steps '1' loop and then a couple of 'd'irs showing files. Then it fails again on Q_file and then 'd'ir is empty again.
Code:
T:\tCode\littleFS\LFSintegrity\LFSintegrity.ino Nov 10 2020 16:11:25
LittleFS Test : File Integrity
QSPI flash begin
Flash ID: EF 40 18
Flash size is 16.00 Mbyte
attemping to mount existing media
success
printDirectory QSPI_DISK
--------------
 0, 1-9 '#' passes continue loop before Pause
 'r' Restart Teensy
 'd' Directory of LittleFS
 'c' Continuous Loop
 'h' Hundred loops
 'k' Thousand loops
 'f' Format then Restart : 'SPI EraseEverything'
 'v' Verbose All Dir Prints - TOGGLE
 'p' Pause after all Dir prints - TOGGLE
 '?' Help list
[  0.01] Awaiting input 0123456789rdchkfvp? loops left 0
printDirectory QSPI_DISK
--------------
:: /B_file.txt   waited 102 us
  waited 22888 us
  waited 362 us
  waited 356 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ B 
:: /C_file.txt   waited 106 us
  waited 22895 us
  waited 361 us
  waited 360 us
  waited 77 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ C 
[  0.33] Awaiting input 0123456789rdchkfvp? loops left 0
:: /D_file.txt   waited 102 us
  waited 23749 us
  waited 361 us
  waited 360 us
  waited 89 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ D 
:: /E_file.txt   waited 102 us
  waited 25625 us
  waited 364 us
  waited 361 us
  waited 100 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ E 
[  0.38] Awaiting input 0123456789rdchkfvp? loops left 0
printDirectory QSPI_DISK
--------------FILE	B_file.txt		510
FILE	C_file.txt		520
FILE	D_file.txt		530
FILE	E_file.txt		540

[  0.41] Awaiting input 0123456789rdchkfvp? loops left 0
[  0.41] Awaiting input 0123456789rdchkfvp? loops left 0
:: /F_file.txt   waited 102 us
  waited 25590 us
  waited 361 us
  waited 360 us
  waited 112 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ F 
:: /G_file.txt   waited 102 us
  waited 25643 us
  waited 364 us
  waited 361 us
  waited 122 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ G 
[  0.57] Awaiting input 0123456789rdchkfvp? loops left 0
:: /H_file.txt   waited 102 us
  waited 22883 us
  waited 360 us
  waited 361 us
  waited 138 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ H 
:: /I_file.txt   waited 102 us
  waited 23785 us
  waited 361 us
  waited 361 us
  waited 146 us
  waited 28678 us
  waited 356 us
  waited 72 us
printDirectory QSPI_DISK --Add---- ++ I 
[  0.59] Awaiting input 0123456789rdchkfvp? loops left 0
:: /J_file.txt   waited 101 us
  waited 22873 us
  waited 362 us
  waited 361 us
  waited 156 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ J 
:: /K_file.txt   waited 102 us
  waited 24741 us
  waited 362 us
  waited 361 us
  waited 167 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ K 
[  0.61] Awaiting input 0123456789rdchkfvp? loops left 0
printDirectory QSPI_DISK
--------------FILE	B_file.txt		510
FILE	C_file.txt		520
FILE	D_file.txt		530
FILE	E_file.txt		540
FILE	F_file.txt		550
FILE	G_file.txt		560
FILE	H_file.txt		570
FILE	I_file.txt		580
FILE	J_file.txt		590
FILE	K_file.txt		600

[  0.65] Awaiting input 0123456789rdchkfvp? loops left 0
[  0.65] Awaiting input 0123456789rdchkfvp? loops left 0
:: /L_file.txt   waited 102 us
  waited 25589 us
  waited 362 us
  waited 361 us
  waited 178 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ L 
:: /M_file.txt   waited 102 us
  waited 25621 us
  waited 361 us
  waited 360 us
  waited 191 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ M 
[  0.81] Awaiting input 0123456789rdchkfvp? loops left 0
:: /N_file.txt   waited 102 us
  waited 24750 us
  waited 360 us
  waited 360 us
  waited 202 us
  waited 90 us
printDirectory QSPI_DISK --Add---- ++ N 
:: /O_file.txt   waited 102 us
  waited 25930 us
  waited 360 us
  waited 360 us
  waited 213 us
  waited 91 us
printDirectory QSPI_DISK --Add---- ++ O 
[  0.84] Awaiting input 0123456789rdchkfvp? loops left 0
:: /P_file.txt   waited 102 us
  waited 23863 us
  waited 365 us
  waited 360 us
  waited 225 us
  waited 92 us
printDirectory QSPI_DISK --Add---- ++ P 
:: /Q_file.txt   waited 25480 us
  waited 356 us
  waited 102 us
  waited 102 us
  waited 92 us
  waited 130 us
  waited 23836 us
  waited 362 us
  waited 361 us
  waited 235 us
  waited 27495 us
  waited 99 us
printDirectory QSPI_DISK --Add---- ++ Q Fail File open /Q_file.txt
[  0.87] Awaiting input 0123456789rdchkfvp? loops left 0
printDirectory QSPI_DISK
--------------
[  0.97] Awaiting input 0123456789rdchkfvp? loops left 0

[  0.97] Awaiting input 0123456789rdchkfvp? loops left 0

>Side note rather than filling file with just capital letter of filename A-Z alone - that is toggled between Upper and Lower case every 13 characters to extend the integrity check in case blocks were ever swapped the odds are the period of 13 character changes would show up. That is working so far to write and verify, it ran over night with this code on RAMDISK.
 
Interesting the change was just to QSPI timing.

Running the RAM and SPI working well - so the library code seems well integrated otherwise.

@mjs513 - did you have a pullup on CS with your SPI? Using the Audio SPI flashworking here with LED toggle?

Edited the printDir to give dir and disk summary:
Code:
 10 dirs with 10 files of Size 1360 Bytes
 Total 174 files of Size 24296 Bytes

Code:
uint32_t fTot, totSize;
void printDirectory() {
	fTot = 0, totSize = 0;
	Serial.printf("printDirectory %s\n--------------", szDiskMem);
	printDirectory(myfs.open("/"), 0);
	//Serial.println();
	Serial.printf(" %Total %u files of Size %u Bytes\n", fTot, totSize);
}

void printDirectory(File dir, int numTabs) {
	//dir.whoami();
	uint32_t fSize = 0, dCnt = 0, fCnt = 0;
	while (true) {

		File entry =  dir.openNextFile();
		if (! entry) {
			// no more files
			Serial.printf("\n %u dirs with %u files of Size %u Bytes\n", dCnt, fCnt, fSize);
			fTot += fCnt;
			totSize += fSize;
			break;
		}
		for (uint8_t i = 0; i < numTabs; i++) {
			Serial.print('\t');
		}

		if (entry.isDirectory()) {
			Serial.print("DIR\t");
			dCnt++;
		} else {
			Serial.print("FILE\t");
			fCnt++;
			fSize += entry.size();
		}
		Serial.print(entry.name());
		if (entry.isDirectory()) {
			Serial.println(" / ");
			printDirectory(entry, numTabs + 1);
		} else {
			// files have sizes, directories do not
			Serial.print("\t\t");
			Serial.println(entry.size(), DEC);
		}
		entry.close();
	}
}
 
Another question/possibility?

Could it compile to handle all three?
Right now in the sketch you have:
Code:
  if (!Storage_init()) {
Could this be setup like:
Storage_init(my_buffer, sizeof(buffer)); // user want the RAM drive version.
Storage_init(6); // Assuming 6 is CS pin so SPI
Storage_init(SDCARD_BUILTIN); // use QSPI?

EDIT: if this works, obviously the SDCARD_BUILTIN is probably not the best name here but maybe pin of -1.
Also init(6, SPI1);

Would be good to be allowed as well. Pas by reference and default to SPI...

Morning all
Been obsessed with MTPresponder trying to get everything controlled from the sketch and I think I did it so you don't have to edit any .h or .cpp files. Did have to make a storage class for each storage location unfortunately to do that but it is now able to do things like @KurtE recommended. Here is the link again to updated repository with the updated test sketch:

https://github.com/mjs513/mtp_responder-for-LittleFs

But the one advantage will be easier to combine with SD MTP when that is updated as well.
 
ALCON
I forgot to post this reminder. To get the MTPResponder to work correctly you have to run the T4.x at about 450Mhz, there is a workaround but you have to modify the core - forgot what i had to do but its in the MTPResponder post.
 
WMXZ said:
Another Update
suspecting that USB transfer status is not stable at high CPU speeds
I activated alternative code in
file: usb.c
function: usb_transfer_status
changed #if 0 to #if 1

program compiled again with faster and up 600 Mhz and MTP responds correctly

@Paul: would it be wise to keep this always activated ?

@Paul - would it be possible at some point when you have time to get this into the core so we can run at 600Mhz to use MTP responder
 
I have little bit different problem I wanted to MTP with 1 sdio and 6 spi cards
So I'm trying the following
Code:
#define V2 0
#if V2 == 0
  MTPStorage_SD storage;
  MTPD       mtpd(&storage);
#else
  #define SD_MOSI 11
  #define SD_MISO 12
  #define SD_SCK  13

//  const int cs[] = {34,33,35,36,37,38,BUILTIN_SDCARD};
  const int cs[] = {BUILTIN_SDCARD,34};
  const int nsd = sizeof(cs)/sizeof(int);
  MTPStorage_SD storage[nsd];
  MTPD       mtpd(storage,nsd);

  SDClass sdx[nsd];

bool Storage_init(const int cs[], int nsd)
{ 
    if(nsd==0) return Storage_init(); // defined in storage.h

    SPI.setMOSI(SD_MOSI);
    SPI.setMISO(SD_MISO);
    SPI.setSCK(SD_SCK);

    // prepare Chip Selects
    for(int ii=0; ii<nsd;ii++)
    { if(cs[ii] < BUILTIN_SDCARD) 
      { pinMode(cs[ii],OUTPUT); digitalWriteFast(cs[ii],HIGH);
        if(!sdx[ii].sdfs.begin(SdSpiConfig(cs[ii], SHARED_SPI, SD_SCK_MHZ(33)))) 
            return false; 
        else 
            Serial.printf("uSD%d %d done\n",ii+1, cs[ii]);
      }    
      else
      {
        // initialize SDIO-disk
        if (!sdx[ii].sdfs.begin(SdioConfig(FIFO_SDIO))) return false; else Serial.println("uSD sdio done");
      }
      Serial.flush();
      delay(100);
    }

    // check disk space
    for (int ii=0; ii<nsd;ii++)
    {   uint32_t volFree  = sdx[ii].sdfs.freeClusterCount();
        uint32_t volClust = sdx[ii].sdfs.sectorsPerCluster();
        Serial.printf("%d %d %d\n",ii+1,volFree,volClust);
        Serial.flush();
    }
    return true;
}

#endif
and
Code:
#if V2==0
  if(!Storage_init()) {Serial.println("No storage"); while(1);};
#else
  if(!Storage_init(cs,nsd)) {Serial.println("No storage"); while(1);};
#endif
and in MTP.h
Code:
public:
  explicit MTPD(MTPStorageInterface* storage) : storage_(storage) {}
  explicit MTPD(MTPStorageInterface* storage, int num) : storage_(storage), num_storage(num) {}

private:
  MTPStorageInterface* storage_;
  int num_storage;
obviously V2==0 works but V2==1 , still hangs (or crashes), so work in progress.

I only mention it here to open the discussion on MTP
 
Last edited:
WMXZ said:
Another Update
suspecting that USB transfer status is not stable at high CPU speeds
I activated alternative code in
file: usb.c
function: usb_transfer_status
changed #if 0 to #if 1

program compiled again with faster and up 600 Mhz and MTP responds correctly

@Paul: would it be wise to keep this always activated ?

@Paul - would it be possible at some point when you have time to get this into the core so we can run at 600Mhz to use MTP responder

If the result of that is unknown/untested/untrusted for general usage perhaps?:
Code:
file: usb.c
function: usb_transfer_status
changed #if 0 to [B]#ifdef USB_MTPDISK[/B]
 
@WMXZ
Know most of the this its a struggle for with C++ especially with you explicit statments. But here goes.

From what I am reading you have your fist and second code blocks in the your MTP sketch (I think). Then you have:
Code:
public:
  explicit MTPD(MTPStorageInterface* storage) : storage_(storage) {}
  explicit MTPD(MTPStorageInterface* storage, int num) : storage_(storage), num_storage(num) {}

private:
  MTPStorageInterface* storage_;
  int num_storage;
but is the second form for have SPI_init defined for that format in storage.cpp as well as the first form?

If you have :
Code:
#if V2==0
  if(!Storage_init()) {Serial.println("No storage"); while(1);};
#else
  if(!Storage_init(cs,nsd)) {Serial.println("No storage"); while(1);};
#endif
it going to be the same problem I was having with defines - if you define something in the sketch it doesn't get seen in Storage.cpp :(
 
it going to be the same problem I was having with defines - if you define something in the sketch it doesn't get seen in Storage.cpp :(

Well, I know it is not working properly, mostly because MTP uses a single Storage and not an array to storages.
So the problem to resolve is where to differentiate different storages, in MTP or in Storage.
MTP allows different storages, which in the actual implementation is set to 1

OK, this is not the actual problem of LittleFS, but recently talk was about multiple FS API, so I wanted add another twist.
 
Got it. I wound up creating 3 separate storage classes, storage_ram, storage_qspi and storage_spi but stiil using your single explicit call. Figured next step was to try and combine the 3. Your post gave me an idea but may run into the problem. Will probably try tomorrow
 
Got it. I wound up creating 3 separate storage classes, storage_ram, storage_qspi and storage_spi but stiil using your single explicit call. Figured next step was to try and combine the 3. Your post gave me an idea but may run into the problem. Will probably try tomorrow

Was still showing here as unavailalble.

<edit> : put the #ifdef USB_MTPDISK in USB.c and - also dropped speed to 396


Updated from github now errors on storage unknown SPI or RAM ::
Code:
T:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:10:3: error: 'MTPStorage_SPI' does not name a type
   MTPStorage_SPI storage;
   ^
T:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:13:20: error: 'storage' was not declared in this scope
   MTPD       mtpd(&storage);
 
Was still showing here as unavailalble.

<edit> : put the #ifdef USB_MTPDISK in USB.c and - also dropped speed to 396


Updated from github now errors on storage unknown SPI or RAM ::
Code:
T:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:10:3: error: 'MTPStorage_SPI' does not name a type
   MTPStorage_SPI storage;
   ^
T:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:13:20: error: 'storage' was not declared in this scope
   MTPD       mtpd(&storage);

Two things - remember to lower the T4.1 clock speed to 450 Mhz the second thing - there are 3 places in the test sketch you have to modify to use SPI going to highlight sections in red and configure to use SPI:
Code:
#include "Arduino.h"
[COLOR="#FF0000"]#define use_spi_disk
//#define use_qspi_disk
//#define use_ram_disk[/COLOR]
EXTMEM char my_buffer[400000];

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

[COLOR="#FF0000"]  MTPStorage_SPI storage;
  //MTPStorage_QSPI storage;
  //MTPStorage_RAM storage;[/COLOR]
  MTPD       mtpd(&storage);


void logg(uint32_t del, const char *txt)
{ static uint32_t to;
  if(millis()-to > del)
  {
    //Serial.println(txt); 
#if USE_SDIO==1
    digitalWriteFast(2,!digitalReadFast(2));
#endif
    to=millis();
  }
}

void setup()
{ 
  while(!Serial && millis()<2000); 
  usb_mtp_configure();
[COLOR="#FF0000"]    //if(!Storage_init_qspi()) {Serial.println("No storage"); while(1);};
    if(!Storage_init_spi(6, SPI)) {Serial.println("No storage"); while(1);};
    //if(!Storage_init_ram(my_buffer, sizeof(my_buffer))) {Serial.println("No storage"); while(1);};[/COLOR]

  Serial.println("MTP test");

#if USE_SDIO==1
  pinMode(2,OUTPUT);
#endif

}

void loop()
{ 
  mtpd.loop();

  logg(1000,"loop");
  //asm("wfi"); // may wait forever on T4.x
}
When you see that error its a sure sign you/I forgot to change the commented lines. When I use that on my SPI chip it compiles and when I open my Teensy drive I will see:
Capture.PNG
 
Something is missing on github?

Used as presented from github for RAM it presented those errors on build
Changed the three to SPI and same fail:
Code:
:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:10:3: error: 'MTPStorage_SPI' does not name a type
   MTPStorage_SPI storage;
   ^
T:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:13:20: error: 'storage' was not declared in this scope
   MTPD       mtpd(&storage);
                    ^
T:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino: In function 'void setup()':
T:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:33:32: error: 'Storage_init_spi' was not declared in this scope
     if(!Storage_init_spi(6, SPI)) {Serial.println("No storage"); while(1);};
                                ^
Multiple libraries were found for "MTP.h"
 Used: T:\tCode\libraries\MTP_t4
 Not used: T:\tCode\libraries\MTP_t4_littlefs

Was compiled as:
Code:
set model=teensy40
set speed=396
set opt=o2std
set usb=mtp

Also made the #ifdef edit in USB.c as noted.
 
@defragster
That's strange - but probably should have expected it - been using a T4.1. Just tried it on a T4.0 using DMAMEM instead of EXTMEM and it seems to be running with out errors.

Ok - just reloaded everything to github.

What concerns me more is that you are getting that error. Am just attaching my src files to be on the safe side:
 

Attachments

  • src.zip
    27.7 KB · Views: 41
Also looks like I need AUDIO CS pin #10 for SD with T_4 - that may be why it failed before.

T_4.0 with AUDIO Rev D ::pjrc.com/store/teensy3_audio.html
MEMCS #6
SDCS #10

Been using CS = 6 for MEMCS. Also if you are using propshield you may have to pinMode(4,INPUT_PULLUP) and the same for pin 10. But - was getting the same error for Winbond chip on a breakout board.

EDIT: oops you are talking about the Audioshield - probably. You can now change the CS pin from with the sketch if you noticed :) Thanks for the suggestion @KurtE
 
Don't have a propshield out - but Audio Rev D for SPI SD card and SPI FLASH

Will try your source ZIP - but updated github still errors:
Code:
-DUSB_MTPDISK -DLAYOUT_US_ENGLISH "-IT:\\TEMP\\arduino_build_mtp-test.ino/pch" "-IT:\\arduino-1.8.13_t54\\hardware\\teensy\\avr\\cores\\teensy4" "-IT:\\tCode\\libraries\\MTP_t4\\src" "-IT:\\arduino-1.8.13_t54\\hardware\\teensy\\avr\\libraries\\SdFat-beta\\src" "-IT:\\arduino-1.8.13_t54\\hardware\\teensy\\avr\\libraries\\SPI" "-IT:\\tCode\\libraries\\USB2\\src" "-IT:\\arduino-1.8.13_t54\\hardware\\teensy\\avr\\libraries\\Time" "T:\\TEMP\\arduino_build_mtp-test.ino\\sketch\\mtp-test.ino.cpp" -o "T:\\TEMP\\arduino_build_mtp-test.ino\\sketch\\mtp-test.ino.cpp.o"
In file included from t:\arduino-1.8.13_t54\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from t:\arduino-1.8.13_t54\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from t:\arduino-1.8.13_t54\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from t:\arduino-1.8.13_t54\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from t:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\sdfat-beta\src\common\fsapiconstants.h:30,
                 from T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\SdFat-beta\src/ExFatLib/ExFatFile.h:36,
                 from T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\SdFat-beta\src/ExFatLib/ExFatVolume.h:28,
                 from T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\SdFat-beta\src/ExFatLib/ExFatLib.h:27,
                 from T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\SdFat-beta\src/SdFat.h:33,
                 from T:\tCode\libraries\MTP_t4\src/Storage.h:55,
                 from T:\tCode\libraries\MTP_t4\src/MTP.h:36,
                 from T:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:7:
T:\arduino-1.8.13_t54\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"
  ^
T:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:10:3: error: 'MTPStorage_SPI' does not name a type
   MTPStorage_SPI storage;
   ^
T:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:13:20: error: 'storage' was not declared in this scope
   MTPD       mtpd(&storage);
                    ^
T:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino: In function 'void setup()':
T:\tCode\libraries\MTP_t4_littlefs\examples\mtp-test\mtp-test.ino:33:33: error: 'Storage_init_spi' was not declared in this scope
     if(!Storage_init_spi(10, SPI)) {Serial.println("No storage"); while(1);};
                                 ^
Multiple libraries were found for "MTP.h"
 Used: T:\tCode\libraries\MTP_t4
 Not used: T:\tCode\libraries\MTP_t4_littlefs
Using library MTP_t4 at version 1.0.0-beta.1 in folder: T:\tCode\libraries\MTP_t4 
Using library SdFat-beta at version 2.0.0-beta.8 in folder: T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\SdFat-beta 
Using library SPI at version 1.0 in folder: T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\SPI 
Using library USB2 at version 0.9.0-beta.1 in folder: T:\tCode\libraries\USB2 
Using library Time at version 1.6 in folder: T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\Time 
exit status 1
[Finished in 3.4s with exit code 1]
 
@defragster
Think I found your problem:
Code:
Multiple libraries were found for "MTP.h"
 [COLOR="#FF0000"]Used: T:\tCode\libraries\MTP_t4
 Not used: T:\tCode\libraries\MTP_t4_littlefs[/COLOR]
Delete your MTP_t4 directory for now or move it out of the way. That's on my list of things to fix next :)

EDIT: that fix will probably go in tomorrow morning - you all know I am a morning person.
 
DELETED MTP_t4

Now it fails:
Code:
"T:\\TEMP\\arduino_build_mtp-test.ino/..\\arduino_cache_mtp-test.ino\\core\\core_teensy_avr_teensy40_usb_mtp,speed_396,opt_o2std,keys_en-us_4236bb8dbca77b8193cb3c4ae6edbf3a.a" "-LT:\\TEMP\\arduino_build_mtp-test.ino" -larm_cortexM7lfsp_math -lm -lstdc++
[B]T:\TEMP\arduino_build_mtp-test.ino\libraries\MTP_t4_littlefs\Storage_QSPI.cpp.o: In function `mtp_yield()':
T:\tCode\libraries\MTP_t4_littlefs\src/Storage_QSPI.cpp:59: multiple definition of `mtp_yield()'[/B]
T:\TEMP\arduino_build_mtp-test.ino\libraries\MTP_t4_littlefs\Storage.cpp.o:T:\tCode\libraries\MTP_t4_littlefs\src/Storage.cpp:95: first defined here
t:/arduino-1.8.13_t54/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
T:\TEMP\arduino_build_mtp-test.ino\libraries\MTP_t4_littlefs\Storage_QSPI.cpp.o: In function `Print::Print()':
T:\tCode\libraries\LittleFS-main\src/LittleFS.h:110: multiple definition of `mtp_lock_storage(bool)'
T:\TEMP\arduino_build_mtp-test.ino\libraries\MTP_t4_littlefs\Storage.cpp.o:T:\arduino-1.8.13_t54\hardware\teensy\avr\cores\teensy4/FS.h:125: first defined here
collect2.exe: error: ld returned 1 exit status
Using library MTP_t4_littlefs at version 1.0.0-beta.1 in folder: T:\tCode\libraries\MTP_t4_littlefs 
Using library LittleFS-main at version 1.0.0 in folder: T:\tCode\libraries\LittleFS-main 
Using library SPI at version 1.0 in folder: T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\SPI 
Using library USB2 at version 0.9.0-beta.1 in folder: T:\tCode\libraries\USB2 
Using library Time at version 1.6 in folder: T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\Time 
exit status 1
 
DELETED MTP_t4

Now it fails:
Code:
:\\TEMP\\arduino_build_mtp-test.ino/..\\arduino_cache_mtp-test.ino\\core\\core_teensy_avr_teensy40_usb_mtp,speed_396,opt_o2std,keys_en-us_4236bb8dbca77b8193cb3c4ae6edbf3a.a" "-LT:\\TEMP\\arduino_build_mtp-test.ino" -larm_cortexM7lfsp_math -lm -lstdc++
T:\TEMP\arduino_build_mtp-test.ino\libraries\MTP_t4_littlefs\Storage_QSPI.cpp.o: In function `mtp_yield()':
T:\tCode\libraries\MTP_t4_littlefs\src/Storage_QSPI.cpp:59: multiple definition of `mtp_yield()'
T:\TEMP\arduino_build_mtp-test.ino\libraries\MTP_t4_littlefs\Storage.cpp.o:T:\tCode\libraries\MTP_t4_littlefs\src/Storage.cpp:95: first defined here
t:/arduino-1.8.13_t54/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
T:\TEMP\arduino_build_mtp-test.ino\libraries\MTP_t4_littlefs\Storage_QSPI.cpp.o: In function `Print::Print()':
T:\tCode\libraries\LittleFS-main\src/LittleFS.h:110: multiple definition of `mtp_lock_storage(bool)'
T:\TEMP\arduino_build_mtp-test.ino\libraries\MTP_t4_littlefs\Storage.cpp.o:T:\arduino-1.8.13_t54\hardware\
collect2.exe: error: ld returned 1 exit status
Using library MTP_t4_littlefs at version 1.0.0-beta.1 in folder: T:\tCode\libraries\MTP_t4_littlefs 
Using library LittleFS-main at version 1.0.0 in folder: T:\tCode\libraries\LittleFS-main 
Using library SPI at version 1.0 in folder: T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\SPI 
Using library USB2 at version 0.9.0-beta.1 in folder: T:\tCode\libraries\USB2 
Using library Time at version 1.6 in folder: T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\Time 
exit status 1

Ok now I am stumped - recognize the errors but not sure why you are getting them since I can not duplicate. Can you post the sketch you are using?
 
Last edited:
Back
Top