LittleFS port to Teensy/SPIFlash

Wondering can we read those flash chips soldered to bottom of T4.1 using SPI?
Something like: if (!myfs.begin(51, SPI2)) ?
tried it but didn't work for me. Got all 0's for chip id like before so begining to wonder if its my setup.
 
Quick update resolved issue with the JVSIM chip using serialflash. Bad ground. After erasing I got this from the rawbenchmark sketch:
Code:
Raw SerialFlash Hardware Test

Read Chip Identification:
  JEDEC ID:     EF 70 18
  Part Nummber: (unknown chip)
  Memory Size:  16777216 bytes
  Block Size:   65536 bytes

Reading Chip...

Writing 32 signatures

Double Checking All Signatures:
  all 8192 signatures read ok

Checking Signature Pairs
  all 4095 signature pairs read ok

Checking Read-While-Write (Program Suspend)
  write 256 bytes at 512
  write time was 397 microseconds.
  read-while-writing: 00 00 00 00 15 F5 95 4B 
  test passed, good read while writing

Checking Read-While-Erase (Erase Suspend)
  erase time was 168034 microseconds.
  erase correctly erased 65536 bytes
  read-while-erasing: 00 00 00 00 15 F5 95 4B 
  test passed, good read while erasing

All Tests Passed  :-)

Test data was written to your chip.  You must run
EraseEverything before using this chip for files.
Ran Erase-Anything again and tried LittleFs again:
Code:
LittleFS Test
started
opened test.txt
wrote to file

opened file for read
read 20 bytes
This is a test....

done printing, now close the file

try writing more
opened test.txt again for writing
after write

opened file for read
read 34 bytes
This is a test....
another test

printDirectory
--------------
test.txt		34

create folder
  success

printDirectory
--------------
myfolder / 
test.txt		34

write to file in folder
opened myfolder/morestuff.txt for write

printDirectory
--------------
myfolder / 
	morestuff.txt		39
test.txt		34

**************************************

SPI Flash
flash begin
Flash ID: 00 00 00
error initializing
still not even reading the FLASH ID.
 
Out of curiosity I soldered up a brand new T4.0 and a new propshield and ran LittleFS to test flash again. Interesting that I am getting ram disk info even though there is no extmem? So where is it putting the ram disk?

Anyway this time it worked:
Code:
LittleFS Test
started
opened test.txt
wrote to file

opened file for read
read 20 bytes
This is a test....

done printing, now close the file

try writing more
opened test.txt again for writing
after write

opened file for read
read 34 bytes
This is a test....
another test

printDirectory
--------------
test.txt		34

create folder
  success

printDirectory
--------------
myfolder / 
test.txt		34

write to file in folder
opened myfolder/morestuff.txt for write

printDirectory
--------------
myfolder / 
	morestuff.txt		39
test.txt		34

**************************************

SPI Flash
flash begin
Flash ID: EF 40 17
Flash size is 8.00 Mbyte
attemping to mount existing media
success
started ok

try to read a file already stored on the flash
opened file for read
read 25 bytes
adding more to the file


printDirectory
--------------
test.txt		25

write some more data to the file
adding to file
  waited 202 us

printDirectory
--------------
test.txt		50

read the file again from the flash
opened file for read
read 50 bytes
adding more to the file
adding more to the file
So not sure why the other Winbond chip is not working correctly. Going to solder up another one any way.
 
tried it but didn't work for me. Got all 0's for chip id like before so beginning to wonder if its my setup.
Me too, and then I double checked a few things...

That is, first thought is I need to setup the right SPI pins, so I added:
Code:
  SPI2.setMOSI(50);
  SPI2.setMISO(54);
  SPI2.setSCK(49);
  SPI2.begin();

Still does not work. Thought maybe the FlexSPI setup is screwing it up, so I returned as soon as I called that startup still does not work..

Then I wondered about the other IO pins... And then figured it.... is screwed ...

That is if you look at pins assigned to SPI2, for those bottom Pins, you see:

screenshot2.jpg

And now for example if you look at the schematic for the flashmemory, this case from the Propshield you will see:
screenshot3.jpg
If you compare correctly 51 is correct for Pin 1 to memory chip.
Now look at 49 which is logical pin2... It shows up as SCK2, where as on the chip it is DO... I.e. they don't align.

Wonder why IMXRT would setup the pins for FlexSPI which has LPSPI not to have the pins match up.

Unless I am missing something. I already rerang out my pins on my T4.1 with castellated adapter and the pins match what I expected. I may try jumpering from T4.1 SPI2 pins to prop shield and see if they work.
 
Update to my SPI2 message above. I used jumpers from SPI2 pins on my extended T4.1 board to the appropriate pins on the Propshield and
Code:
void setup() {
//  pinMode(13, OUTPUT);
//  digitalWrite(13, HIGH);
  SPI.begin();
  while (!Serial) ; // wait
  Serial.println("LittleFS Test"); delay(5);
//  if (!myfs.begin(buf, sizeof(buf))) {
  SPI2.setMOSI(50);
  SPI2.setMISO(54);
  SPI2.setSCK(49);
  SPI2.begin();
  if (!myfs.begin(51, SPI2)) {

And it ran:
Code:
LittleFS Test

flash begin

Flash ID: EF 40 17
Flash size is 8.00 Mbyte
attemping to mount existing media
success
started
opened test.txt
wrote to file
  waited 205 us

opened file for read
read 54 bytes
This is a test....
another test
This is a test....
...
So I believe my SPI data is correct.
 
Me too, and then I double checked a few things...

That is, first thought is I need to setup the right SPI pins, so I added:
Code:
SPI2.setMOSI(50);
SPI2.setMISO(54);
SPI2.setSCK(49);
SPI2.begin();
Still does not work. Thought maybe the FlexSPI setup is screwing it up, so I returned as soon as I called that startup still does not work..

Then I wondered about the other IO pins... And then figured it.... is screwed
Think I was trying to use SPI2 when I was playing with NAND chip and came to the same conclusion as you.

Unless I am missing something. I already rerang out my pins on my T4.1 with castellated adapter and the pins match what I expected. I may try jumpering from T4.1 SPI2 pins to prop shield and see if they work
Good luck - never had much luck with castelated boards.
 
Well have another update to the my JVSIM test sketch.

Added
Code:
  pinMode(6, INPUT_PULLUP);
to setup after looking at the propshield schematic and the serialflash sketch and guess what - it is now working:
Code:
LittleFS Test
started
opened test.txt
wrote to file

opened file for read
read 20 bytes
This is a test....

done printing, now close the file

try writing more
opened test.txt again for writing
after write

opened file for read
read 34 bytes
This is a test....
another test

printDirectory
--------------
test.txt		34

create folder
  success

printDirectory
--------------
myfolder / 
test.txt		34

write to file in folder
opened myfolder/morestuff.txt for write

printDirectory
--------------
myfolder / 
	morestuff.txt		39
test.txt		34

**************************************

SPI Flash
flash begin
Flash ID: EF 70 18
Flash size is 16.00 Mbyte
attemping to mount existing media
success
started ok

try to read a file already stored on the flash
opened file for read
read 25 bytes
adding more to the file


printDirectory
--------------
test.txt		25

write some more data to the file
adding to file
  waited 144 us

printDirectory
--------------
test.txt		50

read the file again from the flash
opened file for read
read 50 bytes
adding more to the file
adding more to the file
Good thing to keep in mind going forward. Now I don't have to solder up another flash chip :)
 
Still seeing printDirectory(myfs.open("/"), 0); as broken.

Went back to prior edited mjs513 code and removed the inital tests - so just using file3 for the 10 files to come and go in loop():
Code:
#include <LittleFS.h>

LittleFS_RAM myfs;
char buf[200000];

File file3;

void setup() {
	pinMode(13, OUTPUT);
	digitalWrite(13, HIGH);
	while (!Serial) ; // wait
	Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
	Serial.println("LittleFS Test : RAMDISK DIRS"); delay(5);

	if (!myfs.begin(buf, sizeof(buf))) {
		Serial.println("Error starting ramdisk");
		while (1) ;
	}

	printDirectory();
}



void printDirectory() {
	Serial.println("printDirectory RAMDISK\n--------------");
	printDirectory(myfs.open("/"), 0);
	Serial.println();
}

void printDirectory(File dir, int numTabs) {
	//dir.whoami();
	while (true) {

		static int count = 0;
		if (++count > 20) while (1) ;

		File entry =  dir.openNextFile();
		if (! entry) {
			// no more files
			//Serial.println("**nomorefiles**");
			break;
		}
		for (uint8_t i = 0; i < numTabs; i++) {
			Serial.print('\t');
		}

		if (entry.isDirectory()) {
			Serial.print("DIR\t");
		} else {
			Serial.print("FILE\t");
		}
		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();
	}
}

uint32_t lCnt = 0;
uint32_t cCnt = 0;
char szLoop[] = "#_file.txt";
void loop() {
	digitalToggleFast(13);
	lCnt++;
	int ii;
	byte nNum = lCnt % 10;
	szLoop[0] = '0' + nNum;
	if ( cCnt >= 3 && myfs.exists(szLoop) ) {
		Serial.print('\n');
		printDirectory();
		file3 = myfs.open(szLoop);
		ii = 0;
		char mm;
		while ( file3.available() ) {
			file3.read( &mm , 1 );
			if ( '@' != mm ) Serial.print( "Bad Byte!\n");
		}
		file3.close();
		myfs.remove(szLoop);
	}
	else {
		file3 = myfs.open(szLoop, FILE_WRITE);
		if ( nNum == 0 ) {
			nNum = 10;
			cCnt++;
			if ( cCnt >= 5 ) cCnt = 0;
		}
		Serial.print('\n');
		printDirectory();
		delay(100);
		char mm = '@';
		for ( ii = 0; ii < nNum * 100; ii++ ) {
			file3.write( &mm , 1 );
		}
		file3.close();
		Serial.print('.');
		delay(100);
	}
}

That does more calls to printDirectory(); to see where it fails during the process.

Above on T_4.0 failing as follows:
Code:
T:\tCode\littleFS\RamD_dir\RamD_dir.ino Nov  6 2020 15:26:49
LittleFS Test : RAMDISK DIRS
printDirectory RAMDISK
--------------


printDirectory RAMDISK
--------------
FILE	1_file.txt		0

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		0

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		200
FILE	3_file.txt		0

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		200
FILE	3_file.txt		300
FILE	4_file.txt		0

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		200
FILE	3_file.txt		300
FILE	4_file.txt		400
FILE	5_file.txt		0

Glanced at LittleFS code and not seeing anything ... assuming the 'malloc() for f or d' put into new object are freed - which .close seems to do.

Turning on debugPrints for CLOSE in :: T:\tCode\libraries\LittleFS-main\src\LittleFS.h
Seems to show matching .close for all files - though not sure the reason for a second call to close a closed file?
Code:
T:\tCode\littleFS\RamD_dir\RamD_dir.ino Nov  6 2020 15:54:55
LittleFS Test : RAMDISK DIRS
printDirectory RAMDISK
--------------

  close dir, this=202061b8, lfs=20001258  end of close
  end of close

printDirectory RAMDISK
--------------
FILE	1_file.txt		0
  close file, this=20206448, lfs=20001258  end of close
  end of close

  close dir, this=20206300, lfs=20001258  end of close
  end of close
  close file, this=20206220, lfs=20001258  end of close
.  end of close

printDirectory RAMDISK
--------------
FILE	1_file.txt		100
  close file, this=20206460, lfs=20001258  end of close
  end of close
FILE	2_file.txt		0
  close file, this=20206460, lfs=20001258  end of close
  end of close

  close dir, this=20206370, lfs=20001258  end of close
  end of close
  close file, this=202062c8, lfs=20001258  end of close
.  end of close

printDirectory RAMDISK
--------------
FILE	1_file.txt		100
  close file, this=20206448, lfs=20001258  end of close
  end of close
FILE	2_file.txt		200
  close file, this=20206448, lfs=20001258  end of close
  end of close
FILE	3_file.txt		0
  close file, this=20206448, lfs=20001258  end of close
  end of close

  close dir, this=20206300, lfs=20001258  end of close
  end of close
  close file, this=20206220, lfs=20001258  end of close
.  end of close

printDirectory RAMDISK
--------------
FILE	1_file.txt		100
  close file, this=20206460, lfs=20001258  end of close
  end of close
FILE	2_file.txt		200
  close file, this=20206460, lfs=20001258  end of close
  end of close
FILE	3_file.txt		300
  close file, this=20206460, lfs=20001258  end of close
  end of close
FILE	4_file.txt		0
  close file, this=20206460, lfs=20001258  end of close
  end of close

  close dir, this=20206370, lfs=20001258  end of close
  end of close
  close file, this=202062c8, lfs=20001258  end of close
.  end of close

printDirectory RAMDISK
--------------
FILE	1_file.txt		100
  close file, this=20206448, lfs=20001258  end of close
  end of close
FILE	2_file.txt		200
  close file, this=20206448, lfs=20001258  end of close
  end of close
FILE	3_file.txt		300
  close file, this=20206448, lfs=20001258  end of close
  end of close
FILE	4_file.txt		400
  close file, this=20206448, lfs=20001258  end of close
  end of close
FILE	5_file.txt		0
  close file, this=20206448, lfs=20001258  end of close
  end of close

It doesn't help - but should printDirectory() close the open here? :: printDirectory(myfs.open("/"), 0);
 
Had a feeling but is that what we really want it do to - should there be a test to limit it to extmem only?

This is quick and dirty starting? - abuses 200KB DTCM RAM everyone (T_3.5 or better) has which would otherwise go unused :)
 
This is quick and dirty starting? - abuses 200KB DTCM RAM everyone (T_3.5 or better) has which would otherwise go unused :)

Ok.

anyway back to your sketch, out of curiosity I modified my sketch slightly to add in a bunch more files just to see if there is some sort of file limit, but doesn't look like it:
Code:
D:\Users\Merli\Documents\Arduino\littlefs_teensy_test3\littlefs_teensy_test3.ino Nov  6 2020 19:47:30
LittleFS Timer Test
printDirectory
--------------

Using println and printf to printoutput file
opened PRINTOUTPUT1.txt
opened PRINTOUTPUT2.txt
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		628
FILE	PRINTOUTPUT2.txt		630

-------------------------------
File1 contents:
-------------------------------
File1 size: 628
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcde
ghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghi
klmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107

-------------------------------
File3 byte conversion test:
-------------------------------

Data_0: true
Data_1: 1.3574999571
Data_2: 314159
Data_3: 142
19
The Quick Brown Fox
Init Done - array loaded
...... ...... ......
create folder
  success


2nd Directory contents:
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		628
FILE	PRINTOUTPUT2.txt		630
DIR	structuredData / 
	FILE	logger.txt		480


true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox

printDirectory
--------------
FILE	PRINTOUTPUT1.txt		628
FILE	PRINTOUTPUT2.txt		630
FILE	file10		16
FILE	file1		32
FILE	file20		16
FILE	file2		32
FILE	file30		16
FILE	file3		32
DIR	structuredData / 
	FILE	logger.txt		480
DIR	test1 / 
DIR	test2 / 
DIR	test3 / 

printDirectory
--------------
FILE	PRINTOUTPUT1.txt		628
FILE	PRINTOUTPUT2.txt		630
FILE	file10		16
FILE	file1		32
FILE	file20		16
FILE	file2		32
FILE	file30		16
FILE	file3		32
DIR	structuredData / 
	FILE	logger.txt		480
DIR	test1 / 
	FILE	file1		16
DIR	test2 / 
	FILE	file2		16
DIR	test3 / 
	FILE	file3		16

file /test3/file3 removed!
directory /test3 removed!
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		628
FILE	PRINTOUTPUT2.txt		630
FILE	file10		16
FILE	file1		32
FILE	file20		16
FILE	file2		32
FILE	file30		16
FILE	file3		32
DIR	structuredData / 
	FILE	logger.txt		480
DIR	test1 / 
	FILE	file1		16
 
@defragster
In regards to your sketch try changing
Code:
    if (++count > 20) while (1) ;
to
Code:
    if (++count > 1000) while (1) ;
in the
Code:
void printDirectory(File dir, int numTabs) {
function - seems to work but then hangs eventually so not sure what that count is doing.

<opps did EDIT not QUOTE >
 
Ok.

anyway back to your sketch, out of curiosity I modified my sketch slightly to add in a bunch more files just to see if there is some sort of file limit, but doesn't look like it:
...

Quick edit to limit to two files #1 and #2 (fails after the same count of 14 FILE's shown with 4):
Code:
	int ii;
	byte nNum = lCnt % 2+1;

Fails after 14 file prints? and above fails after 'FILE 5_file.txt 0' print of 15th file?:
Code:
T:\tCode\littleFS\RamD_dir\RamD_dir.ino Nov  6 2020 17:21:21
LittleFS Test : RAMDISK DIRS
printDirectory RAMDISK
--------------


printDirectory RAMDISK
--------------
FILE	2_file.txt		0

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		0
FILE	2_file.txt		200

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		200

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		400

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		200
FILE	2_file.txt		400

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		200
FILE	2_file.txt		600

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		300
FILE	2_file.txt		600

Same "15" if changed to ALPHA naming:
Code:
	byte nNum = lCnt % 26;
	szLoop[0] = 'A' + nNum;

output:
Code:
T:\tCode\littleFS\RamD_dir\RamD_dir.ino Nov  6 2020 17:27:12
LittleFS Test : RAMDISK DIRS
printDirectory RAMDISK
--------------


printDirectory RAMDISK
--------------
FILE	B_file.txt		0

.
printDirectory RAMDISK
--------------
FILE	B_file.txt		100
FILE	C_file.txt		0

.
printDirectory RAMDISK
--------------
FILE	B_file.txt		100
FILE	C_file.txt		200
FILE	D_file.txt		0

.
printDirectory RAMDISK
--------------
FILE	B_file.txt		100
FILE	C_file.txt		200
FILE	D_file.txt		300
FILE	E_file.txt		0

.
printDirectory RAMDISK
--------------
FILE	B_file.txt		100
FILE	C_file.txt		200
FILE	D_file.txt		300
FILE	E_file.txt		400
FILE	F_file.txt		0
 
If i change that line to:
Code:
    if (++count > 50) while (1) ;
on output I am seeing:
Code:
D:\Users\Merli\Documents\Arduino\tim-littlefs_ram_test\tim-littlefs_ram_test.ino Nov  6 2020 20:31:42
LittleFS Test : RAMDISK DIRS
printDirectory RAMDISK
--------------
**nomorefiles**


printDirectory RAMDISK
--------------
FILE	1_file.txt		0
**nomorefiles**

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		0
**nomorefiles**

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		200
FILE	3_file.txt		0
**nomorefiles**

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		200
FILE	3_file.txt		300
FILE	4_file.txt		0
**nomorefiles**

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		200
FILE	3_file.txt		300
FILE	4_file.txt		400
FILE	5_file.txt		0
**nomorefiles**

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		200
FILE	3_file.txt		300
FILE	4_file.txt		400
FILE	5_file.txt		500
FILE	6_file.txt		0
**nomorefiles**

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		200
FILE	3_file.txt		300
FILE	4_file.txt		400
FILE	5_file.txt		500
FILE	6_file.txt		600
FILE	7_file.txt		0
**nomorefiles**

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		200
FILE	3_file.txt		300
FILE	4_file.txt		400
FILE	5_file.txt		500
FILE	6_file.txt		600
FILE	7_file.txt		700
FILE	8_file.txt		0
**nomorefiles**

.
printDirectory RAMDISK
--------------
FILE	1_file.txt		100
FILE	2_file.txt		200
FILE	3_file.txt		300
FILE	4_file.txt		400
FILE	5_file.txt		500
then it stops.

If i delete that line completely it runs indefinitely and keeps repeating the pattern. Heres the sketch that I used to get the data above:
Code:
#include <LittleFS.h>

LittleFS_RAM myfs;
char buf[200000];

File file3;

void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  while (!Serial) ; // wait
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  Serial.println("LittleFS Test : RAMDISK DIRS"); delay(5);

  if (!myfs.begin(buf, sizeof(buf))) {
    Serial.println("Error starting ramdisk");
    while (1) ;
  }

  printDirectory();
}



void printDirectory() {
  Serial.println("printDirectory RAMDISK\n--------------");
  printDirectory(myfs.open("/"), 0);
  Serial.println();
}

void printDirectory(File dir, int numTabs) {
  //dir.whoami();
  while (true) {

    static int count = 0;
[B][COLOR="#FF0000"]    if (++count > 50) while (1) ;
[/COLOR][/B]
    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      Serial.println("**nomorefiles**");
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }

    if (entry.isDirectory()) {
      Serial.print("DIR\t");
    } else {
      Serial.print("FILE\t");
    }
    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();
  }
}

uint32_t lCnt = 0;
uint32_t cCnt = 0;
char szLoop[] = "#_file.txt";
void loop() {
  digitalToggleFast(13);
  lCnt++;
  int ii;
  byte nNum = lCnt % 10;
  szLoop[0] = '0' + nNum;
  if ( cCnt >= 3 && myfs.exists(szLoop) ) {
    Serial.print('\n');
    printDirectory();
    file3 = myfs.open(szLoop);
    ii = 0;
    char mm;
    while ( file3.available() ) {
      file3.read( &mm , 1 );
      if ( '@' != mm ) Serial.print( "Bad Byte!\n");
    }
    file3.close();
    myfs.remove(szLoop);
  }
  else {
    file3 = myfs.open(szLoop, FILE_WRITE);
    if ( nNum == 0 ) {
      nNum = 10;
      cCnt++;
      if ( cCnt >= 5 ) cCnt = 0;
    }
    Serial.print('\n');
    printDirectory();
    delay(100);
    char mm = '@';
    for ( ii = 0; ii < nNum * 100; ii++ ) {
      file3.write( &mm , 1 );
    }
    file3.close();
    Serial.print('.');
    delay(100);
  }
}
 
I've added QSPI support.

https://github.com/PaulStoffregen/LittleFS/commit/7af59290ffe0f78408758e931bb948f6d01b6d91

But something isn't quite right. It's sort-of working in a couple quick tests, then corrupts the filesystem and every other attempt needs to reformat.

Haven't tried it yet but looking at the begin we had a slightly different set up when we did the spiffs library for the T4:
Code:
	  FLEXSPI2_FLSHA2CR0 = 0x4000;
	  FLEXSPI2_FLSHA2CR1 = FLEXSPI_FLSHCR1_CSINTERVAL(2)
		| FLEXSPI_FLSHCR1_TCSH(3) | FLEXSPI_FLSHCR1_TCSS(3);
	  FLEXSPI2_FLSHA2CR2 = FLEXSPI_FLSHCR2_AWRSEQID(6) | FLEXSPI_FLSHCR2_AWRSEQNUM(0)
		| FLEXSPI_FLSHCR2_ARDSEQID(5) | FLEXSPI_FLSHCR2_ARDSEQNUM(0);

		
	  // cmd index 7 = read ID bytes
	  FLEXSPI2_LUT28 = LUT0(CMD_SDR, PINS1, 0x9F) | LUT1(READ_SDR, PINS1, 1);

	  printStatusRegs();

	  // ----------------- FLASH only ----------------------------------------------

	  // cmd index 8 = read Status register #1 SPI
	  FLEXSPI2_LUT32 = LUT0(CMD_SDR, PINS1, 0x05) | LUT1(READ_SDR, PINS1, 1);

	  // cmd index 9 = read Status register #2 SPI
	  FLEXSPI2_LUT36 = LUT0(CMD_SDR, PINS1, 0x35) | LUT1(READ_SDR, PINS1, 1);

	  //cmd index 10 = exit QPI mode
	  FLEXSPI2_LUT40 = LUT0(CMD_SDR, PINS4, 0xFF);

	  //cmd index 11 = write enable QPI
	  FLEXSPI2_LUT44 = LUT0(CMD_SDR, PINS4, 0x06);

	  //cmd index 12 = sector erase
	  FLEXSPI2_LUT48 = LUT0(CMD_SDR, PINS4, 0x20) | LUT1(ADDR_SDR, PINS4, 24);

	  //cmd index 13 = page program
	  FLEXSPI2_LUT52 = LUT0(CMD_SDR, PINS4, 0x02) | LUT1(ADDR_SDR, PINS4, 24);
	  FLEXSPI2_LUT53 = LUT0(WRITE_SDR, PINS4, 1);

	  //cmd index 14 = set read parameters
	  FLEXSPI2_LUT56 = LUT0(CMD_SDR, PINS4, 0xc0) | LUT1(CMD_SDR, PINS4, 0x20);

	  //cmd index 15 = enter QPI mode
	  FLEXSPI2_LUT60 = LUT0(CMD_SDR, PINS1, 0x38);
	  
	  // reset the chip
	  flexspi_ip_command(10,flashBaseAddr); //exit QPI
	  flexspi_ip_command(1, flashBaseAddr); //reset enable
	  flexspi_ip_command(2, flashBaseAddr); //reset
	  delayMicroseconds(50);

	  flexspi_ip_read(7, flashBaseAddr, flashID, sizeof(flashID) ); // flash begins at offset 0x01000000

	#if 0
	  Serial.print("FLASH ID:");
	  for (unsigned i = 0; i < sizeof(flashID); i++) Serial.printf(" %02X", flashID[i]);
	  Serial.printf("\n");
	  Serial.printf("at 0x %x\n", flashBaseAddr);
	#endif
	
	

	  if(flashID[0] != 0xEF && (flashID[1] != 0x40 || flashID[1] != 0x70)) {
		  Serial.println("No FLASH INSTALLED!!!!");
		  exit(1);
	  }
	  //TODO!!!!! set QPI enable bit in status reg #2 if not factory set!!!!!
	  //if( flashID[1] == 0x70){
		uint8_t val[0];
		flexspi_ip_read(9, flashBaseAddr, &val, 1 );	

		val[0] |= 1<<1;

		FLEXSPI2_LUT28 = LUT0(CMD_SDR, PINS1, 0x50);
		flexspi_ip_command(7, flashBaseAddr);

		  FLEXSPI2_LUT28 = LUT0(CMD_SDR, PINS1, 0x31) | LUT1(WRITE_SDR, PINS1, 1);
		  flexspi_ip_write(7, flashBaseAddr, val, 1);
	  //}
	  
	  //  Serial.println("ENTER QPI MODE");
	  flexspi_ip_command(15, flashBaseAddr);

	  //patch LUT for QPI:
	  // cmd index 8 = read Status register #1
	  FLEXSPI2_LUT32 = LUT0(CMD_SDR, PINS4, 0x05) | LUT1(READ_SDR, PINS4, 1);
	  // cmd index 9 = read Status register #2
	  FLEXSPI2_LUT36 = LUT0(CMD_SDR, PINS4, 0x35) | LUT1(READ_SDR, PINS4, 1);
	  
	  flexspi_ip_command(14, flashBaseAddr);
we built on what was already in for the PSRAM in the startup. Don't know if it really matters.
 
Ok just gave it a try with my test sketch that I used with RAM but getting inconsistent results, heres the output for 2 loads:
Code:
D:\Users\Merli\Documents\Arduino\littlefs_teensy_test3\littlefs_teensy_test3.ino Nov  6 2020 22:46:34
LittleFS Timer Test
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 27596 us
  waited 121 us
  waited 26775 us
  waited 122 us
attemping to mount freshly formatted media
success
printDirectory
--------------

Using println and printf to printoutput file
  waited 108 us
opened PRINTOUTPUT1.txt
  waited 108 us
opened PRINTOUTPUT2.txt
  waited 26863 us
  waited 358 us
  waited 27726 us
  waited 357 us
  waited 357 us
  waited 357 us
  waited 197 us
  waited 90 us
  waited 200 us
  waited 90 us
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		628
FILE	PRINTOUTPUT2.txt		630

-------------------------------
File1 contents:
-------------------------------
File1 size: 628
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcde
ghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghi
klmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107

-------------------------------
File3 byte conversion test:
-------------------------------

Data_0: true
Data_1: 1.3574999571
Data_2: 314159
Data_3: 142
19
The Quick Brown Fox
Init Done - array loaded
...... ...... ......
create folder
  waited 25876 us
  waited 81 us
  waited 129 us
  success

  waited 101 us
  waited 27657 us
  waited 357 us
  waited 318 us
  waited 90 us

2nd Directory contents:
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		628
FILE	PRINTOUTPUT2.txt		630
DIR	structuredData / 
	FILE	logger.txt		480


true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
  waited 96 us
  waited 95 us
  waited 95 us
  waited 99 us
  waited 99 us
  waited 99 us
  waited 92 us
  waited 27603 us
  waited 199 us
  waited 97 us
  waited 96 us
  waited 100 us
  waited 98 us
  waited 98 us

  waited 87 us
  waited 26784 us
  waited 254 us
  waited 96 us
  waited 96 us
  waited 99 us
  waited 99 us
  waited 99 us
  waited 26794 us
  waited 81 us
  waited 112 us
  waited 28485 us
  waited 319 us
  waited 26834 us
  waited 94 us
  waited 118 us
  waited 27775 us
  waited 94 us
  waited 119 us
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		628
FILE	PRINTOUTPUT2.txt		0
FILE	file10		16
FILE	file1		0
FILE	file20		16
FILE	file2		0
FILE	file30		0
FILE	file3		0
DIR	test1 / 
DIR	test2 / 
DIR	test3 / 

  waited 95 us
  waited 95 us
  waited 96 us
  waited 99 us
  waited 98 us
  waited 98 us
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		628
FILE	PRINTOUTPUT2.txt		0
FILE	file10		16
FILE	file1		0
FILE	file20		16
FILE	file2		0
FILE	file30		0
FILE	file3		0
DIR	test1 / 
	FILE	file1		16
DIR	test2 / 
	FILE	file2		16
DIR	test3 / 
	FILE	file3		16

  waited 79 us
file /test3/file3 removed!
  waited 98 us
  waited 108 us
directory /test3 removed!
  waited 79 us
  waited 97 us
  waited 108 us
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		628
FILE	PRINTOUTPUT2.txt		0
FILE	file10		16
FILE	file20		16
FILE	file30		0
DIR	test1 / 
	FILE	file1		16
	
	---------------------------------

D:\Users\Merli\Documents\Arduino\littlefs_teensy_test3\littlefs_teensy_test3.ino Nov  6 2020 22:49:53

LittleFS Timer Test

QSPI flash begin

Flash ID: EF 40 18
Flash size is 16.00 Mbyte
attemping to mount existing media

success

printDirectory
--------------

FILE	PRINTOUTPUT1.txt		1256

FILE	file10		16

FILE	file20		32

FILE	file30		80



Using println and printf to printoutput file

opened PRINTOUTPUT1.txt

opened PRINTOUTPUT2.txt

  waited 26995 us
  waited 358 us
  waited 358 us
  waited 360 us
  waited 361 us
  waited 359 us
  waited 26888 us
  waited 358 us
  waited 358 us
  waited 359 us
  waited 358 us
  waited 358 us
  waited 359 us
  waited 170 us
  waited 87 us
  waited 26901 us
  waited 353 us
  waited 200 us
  waited 333 us
  waited 90 us
printDirectory
--------------

FILE	PRINTOUTPUT1.txt		1884

FILE	PRINTOUTPUT2.txt		1260

FILE	file1		48

FILE	file20		16

FILE	file2		32

FILE	file30		0

FILE	file3		32

DIR	structuredData / 

	FILE	logger.txt		960

DIR	test1 / 

	FILE	file1		48



-------------------------------

File1 contents:

-------------------------------

File1 size: 1884
abcdefghijklmnopqrstuvwxyz

Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz

Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz

Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz

Rec: 3, Float: 29.400000, Int: 101
abcde

ghijklmnopqrstuvwxyz

Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz

Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz

Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz

Rec: 7, Float: 33.400000, Int: 105
abcdefghi

klmnopqrstuvwxyz

Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz

Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvwxyz

Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz

Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmno

qrstuvwxyz

Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz

Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz

Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz

Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrs

uvwxyz

Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz

Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz

Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz

Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvw

yz

Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz

Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz

Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz

Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz

R

c: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz

Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz

Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz

Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz

Rec: 

, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz

Rec: 9, Float: 35.400000, Int: 107


-------------------------------

File3 byte conversion test:

-------------------------------



Data_0: true

Data_1: 1.3574999571

Data_2: 314159

Data_3: 142

19

The Quick Brown Fox

Init Done - array loaded

...... ...... ......

create folder

  failed



  waited 27799 us
  waited 358 us
  waited 358 us
  waited 360 us
  waited 358 us
  waited 357 us
  waited 247 us
  waited 90 us


2nd Directory contents:

printDirectory
--------------

FILE	PRINTOUTPUT1.txt		1884

FILE	PRINTOUTPUT2.txt		1260

FILE	file1		48

FILE	file20		16

FILE	file2		32

FILE	file30		0

FILE	file3		32

DIR	structuredData / 

	FILE	logger.txt		1440

DIR	test1 / 

	FILE	file1		48





true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

true, 1.3574999571, 314159, 142, The Quick Brown Fox

  waited 153 us
  waited 135 us
  waited 136 us
  waited 97 us
  waited 100 us
  waited 117 us
  waited 99 us


  waited 171 us
  waited 153 us
  waited 153 us
  waited 26885 us
  waited 95 us
  waited 118 us
  waited 26953 us
  waited 95 us
  waited 118 us
printDirectory
--------------

FILE	PRINTOUTPUT1.txt		1884

FILE	file10		16

FILE	file20		32

FILE	file30		16

DIR	structuredData / 

	FILE	logger.txt		1440

DIR	test2 / 



  waited 96 us
  waited 153 us
  waited 99 us
printDirectory
--------------

FILE	PRINTOUTPUT1.txt		1884

FILE	file10		16

FILE	file20		32

FILE	file30		16

DIR	structuredData / 

	FILE	logger.txt		1440

DIR	test2 / 

	FILE	file2		16



  waited 98 us
  waited 26854 us
  waited 354 us
  waited 358 us
  waited 114 us
directory /test3 removed!

  waited 78 us
  waited 98 us
  waited 107 us
printDirectory
--------------

FILE	PRINTOUTPUT1.txt		1884

FILE	PRINTOUTPUT2.txt		1260

FILE	file10		16

FILE	file1		80

FILE	file20		32

FILE	file2		64

FILE	file30		16

FILE	file3		64

DIR	structuredData / 

	FILE	logger.txt		1440

DIR	test1 / 

	FILE	file1		64
 
Right now it does seem to retain the formatting:
Code:
D:\Users\Merli\Documents\Arduino\littlefs_teensy_test3\littlefs_teensy_test3.ino Nov  6 2020 22:53:45

LittleFS Timer Test

QSPI flash begin

Flash ID: EF 40 18
Flash size is 16.00 Mbyte
attemping to mount existing media

success

printDirectory
--------------

FILE	PRINTOUTPUT1.txt		3140

FILE	file10		48

FILE	file20		64

FILE	file30		48

DIR	structuredData / 

	FILE	logger.txt		2400
turned power off and on a few times.

But if I do it a couple more times with the full sketch - it seems to lose Dir2 as shown in the previous post, i.e.
Code:
	FILE	file2		16
 
Paul: Good work making the diff look like a relatively small bit of code.

Bugged by the 'printDirectory' failure on RAM and SPI FLASH - wondering if that points to why QSPI fails on restart? Not sure I want to bother seeing it fail - seeing enough already. Going to read the .MD's

I edited the printDirectory() to show the storage type 'RAMDISK' - since they are customized it makes output more indicative.

I suppose there isn't a shortcut to (Q)SPI Flash format as the lfs must assume all is fresh to start for it to manage?

I went on a scavenger hunt and found the 8MB PSRAM that weren't lost - with the other 2 new 1GB NOR's - then I found the pack of 6 128Mb NAND's. I found a pair of T_4.1's I expected to build into something by now and the Beta T_4.1 with PSRAM and 16MB Flash to use without soldering - and much much more ... digkey(s)/sfun/kurte/mjs513/...
 
Testing RAMDISK on T_4.0.

The problem seems to relate to both the number of directory entries printed and also the number of times printDirectory() is called ( is does open "\" each time )

So several iterations seeing either multiple printDir() calls and few files or one call with 19 files ( A-S ) or 19 calls with No files, 20 counting the one in setup().

Went to this on an empty RAMDISK - it won't make it to 30:
Code:
		for ( int yy=0; yy<30; yy++ ) {
			Serial.print([B]yy[/B]);
			printDirectory();
		}

Runs to #19:
Code:
...
[B]19[/B]printDirectory RAMDISK
--------------

So simplifying that with setup() only code (except printDir funcs) >> This prints to 10:
Code:
	file3 = myfs.open("some.txt", FILE_WRITE);
	for ( int yy = 0; yy < 30; yy++ ) {
		Serial.print(yy);
		printDirectory();
	}
	file3.close();

>> This prints to 20:
Code:
	for ( int yy = 0; yy < 30; yy++ ) {
		Serial.print(yy);
		printDirectory();
	}

Full Code:
Code:
#include <LittleFS.h>

LittleFS_RAM myfs;
char buf[200000];

File file3;
void setup() {
	while (!Serial) ; // wait
	Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
	Serial.println("LittleFS Test : RAMDISK DIRS"); delay(5);

	if (!myfs.begin(buf, sizeof(buf))) {
		Serial.println("Error starting ramdisk");
		while (1) ;
	}

//	file3 = myfs.open("some.txt", FILE_WRITE);
[B]	for ( int yy = 0; yy < 30; yy++ ) {
		Serial.print(yy);
		printDirectory();
	}[/B]
//	file3.close();
}



void printDirectory() {
	Serial.println("printDirectory RAMDISK\n--------------");
	printDirectory(myfs.open("/"), 0);
	Serial.println();
}

void printDirectory(File dir, int numTabs) {
	//dir.whoami();
	while (true) {

		static int count = 0;
		if (++count > 20) while (1) ;

		File entry =  dir.openNextFile();
		if (! entry) {
			// no more files
			//Serial.println("**nomorefiles**");
			break;
		}
		for (uint8_t i = 0; i < numTabs; i++) {
			Serial.print('\t');
		}

		if (entry.isDirectory()) {
			Serial.print("DIR\t");
		} else {
			Serial.print("FILE\t");
		}
		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();
	}
}

void loop() {
}
 
@defragster
Try changing your printDirectory function to the following (change highlighted in RED):
Code:
void printDirectory(File dir, int numTabs) {
	//dir.whoami();
	while (true) {

		static int count = 0;
[B][COLOR="#FF0000"]		//if (++count > 20) while (1) ;
[/COLOR][/B]
		File entry =  dir.openNextFile();
		if (! entry) {
			// no more files
			//Serial.println("**nomorefiles**");
			break;
		}
		for (uint8_t i = 0; i < numTabs; i++) {
			Serial.print('\t');
		}

		if (entry.isDirectory()) {
			Serial.print("DIR\t");
		} else {
			Serial.print("FILE\t");
		}
		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();
	}
}
Think you will find that it will now work for infinite number of directory entries.
 
Oh, opps, sorry about that static count I left in the test code. A couple days ago when I was working on supporting subdirectories and keeping track of pathnames inside LittleFSFile, I needed this to break an infinite loop so I could see stuff that printed to the serial monitor. After I got it working, I completely forgot I had left this inside printDirectory(). It's only purpose is to stop your program dead in its tracks when the very small test cases I was using turned into a massive spew of too much printing due to (at that time) bugs inside the library. The low number 20 was chosen because I'm lazy and didn't feel like using my mouse to scroll back up the serial monitor window to see what (at that time) went so wrong.
 
@PaulStoffregen

As a baseline for what for what my test3 sketch yields when run on SPIFlash:
Code:
D:\Users\Merli\Documents\Arduino\littlefs_teensy_test3\littlefs_teensy_test3.ino Nov  7 2020 07:30:53
LittleFS Timer Test
flash begin
Flash ID: EF 70 18
Flash size is 16.00 Mbyte
attemping to mount existing media
success
[COLOR="#FF0000"]printDirectory
--------------
FILE	PRINTOUTPUT1.txt		628
FILE	PRINTOUTPUT2.txt		630
FILE	file1		16
FILE	file2		16
FILE	file3		16
DIR	structuredData / 
	FILE	logger.txt		480
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		16
[/COLOR]
Using println and printf to printoutput file
opened PRINTOUTPUT1.txt
opened PRINTOUTPUT2.txt
  waited 30658 us
  waited 395 us
  waited 395 us
  waited 30763 us
  waited 398 us
  waited 397 us
  waited 396 us
  waited 397 us
  waited 396 us
  waited 396 us
  waited 365 us
  waited 100 us
  waited 369 us
  waited 100 us
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		1256
FILE	PRINTOUTPUT2.txt		1260
FILE	file1		16
FILE	file2		16
FILE	file3		16
DIR	structuredData / 
	FILE	logger.txt		480
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		16

-------------------------------
File1 contents:
-------------------------------
File1 size: 1256
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcde
ghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghi
klmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmno
qrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrs
uvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107

-------------------------------
File3 byte conversion test:
-------------------------------

Data_0: true
Data_1: 1.3574999571
Data_2: 314159
Data_3: 142
19
The Quick Brown Fox
Init Done - array loaded
...... ...... ......
create folder
  failed

  waited 33624 us
  waited 397 us
  waited 397 us
  waited 397 us
  waited 314 us
  waited 101 us

2nd Directory contents:
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		1256
FILE	PRINTOUTPUT2.txt		1260
FILE	file1		16
FILE	file2		16
FILE	file3		16
DIR	structuredData / 
	FILE	logger.txt		960
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		16


true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
  waited 131 us
  waited 129 us
  waited 130 us
  waited 108 us
  waited 108 us
  waited 108 us
  waited 111 us
  waited 29429 us
  waited 393 us
  waited 321 us
  waited 111 us

  waited 150 us
  waited 150 us
  waited 150 us
  waited 27878 us
  waited 106 us
  waited 132 us
  waited 28237 us
  waited 104 us
  waited 131 us
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		1256
FILE	PRINTOUTPUT2.txt		1260
FILE	file10		16
FILE	file1		48
FILE	file20		16
FILE	file2		48
FILE	file30		16
FILE	file3		48
DIR	structuredData / 
	FILE	logger.txt		960
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		16
DIR	test2 / 
DIR	test3 / 

  waited 107 us
  waited 106 us
  waited 130 us
  waited 111 us
  waited 110 us
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		1256
FILE	PRINTOUTPUT2.txt		1260
FILE	file10		16
FILE	file1		48
FILE	file20		16
FILE	file2		48
FILE	file30		16
FILE	file3		48
DIR	structuredData / 
	FILE	logger.txt		960
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		32
DIR	test2 / 
	FILE	file2		16
DIR	test3 / 
	FILE	file3		16

  waited 88 us
file /test3/file3 removed!
  waited 109 us
  waited 121 us
directory /test3 removed!
  waited 88 us
  waited 109 us
  waited 121 us
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		1256
FILE	PRINTOUTPUT2.txt		1260
FILE	file10		16
FILE	file1		48
FILE	file20		16
FILE	file2		48
FILE	file30		16
FILE	file3		48
DIR	structuredData / 
	FILE	logger.txt		960
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		32
and no matter how many times I reload the sketch the output is repeatable.

Now if I repeat the test using QSPIFlash. On first load I will get:
Code:
D:\Users\Merli\Documents\Arduino\littlefs_teensy_test3\littlefs_teensy_test3.ino Nov  7 2020 07:32:28
LittleFS Timer Test
flash begin
Flash ID: EF 70 18
Flash size is 16.00 Mbyte
attemping to mount existing media
success
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		2512
FILE	PRINTOUTPUT2.txt		2520
FILE	file10		48
FILE	file1		112
FILE	file20		48
FILE	file2		112
FILE	file30		48
FILE	file3		112
DIR	structuredData / 
	FILE	logger.txt		1920
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		64

Using println and printf to printoutput file
opened PRINTOUTPUT1.txt
opened PRINTOUTPUT2.txt
  waited 32720 us
  waited 407 us
  waited 401 us
  waited 401 us
  waited 401 us
  waited 401 us
  waited 405 us
  waited 401 us
  waited 401 us
  waited 402 us
  waited 401 us
  waited 28205 us
  waited 394 us
  waited 392 us
  waited 395 us
  waited 394 us
  waited 393 us
  waited 393 us
  waited 393 us
  waited 396 us
  waited 396 us
  waited 394 us
  waited 393 us
  waited 393 us
  waited 392 us
  waited 393 us
  waited 163 us
  waited 99 us
  waited 171 us
  waited 99 us
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		3140
FILE	PRINTOUTPUT2.txt		3150
FILE	file10		48
FILE	file1		112
FILE	file20		48
FILE	file2		112
FILE	file30		48
FILE	file3		112
DIR	structuredData / 
	FILE	logger.txt		1920
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		64

-------------------------------
File1 contents:
-------------------------------
File1 size: 3140
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcde
ghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghi
klmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmno
qrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrs
uvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvw
yz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz
R
c: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz
Rec: 
, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Flo
t: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 
2.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.4
0000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000,
Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int
 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107

-------------------------------
File3 byte conversion test:
-------------------------------

Data_0: true
Data_1: 1.3574999571
Data_2: 314159
Data_3: 142
19
The Quick Brown Fox
Init Done - array loaded
...... ...... ......
create folder
  failed

  waited 29550 us
  waited 403 us
  waited 404 us
  waited 402 us
  waited 402 us
  waited 408 us
  waited 401 us
  waited 400 us
  waited 397 us
  waited 399 us
  waited 195 us
  waited 101 us

2nd Directory contents:
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		3140
FILE	PRINTOUTPUT2.txt		3150
FILE	file10		48
FILE	file1		112
FILE	file20		48
FILE	file2		112
FILE	file30		48
FILE	file3		112
DIR	structuredData / 
	FILE	logger.txt		2400
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		64


true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
  waited 250 us
  waited 250 us
  waited 249 us
  waited 170 us
  waited 170 us
  waited 171 us

  waited 270 us
  waited 270 us
  waited 270 us
  waited 29308 us
  waited 105 us
  waited 29239 us
  waited 394 us
  waited 398 us
  waited 398 us
  waited 328 us
  waited 29509 us
  waited 105 us
  waited 133 us
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		3140
FILE	PRINTOUTPUT2.txt		3150
FILE	file10		64
FILE	file1		144
FILE	file20		64
FILE	file2		144
FILE	file30		64
FILE	file3		144
DIR	structuredData / 
	FILE	logger.txt		2400
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		64
DIR	test2 / 
DIR	test3 / 

  waited 108 us
  waited 107 us
  waited 191 us
  waited 110 us
  waited 110 us
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		3140
FILE	PRINTOUTPUT2.txt		3150
FILE	file10		64
FILE	file1		144
FILE	file20		64
FILE	file2		144
FILE	file30		64
FILE	file3		144
DIR	structuredData / 
	FILE	logger.txt		2400
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		80
DIR	test2 / 
	FILE	file2		16
DIR	test3 / 
	FILE	file3		16

  waited 88 us
file /test3/file3 removed!
  waited 109 us
  waited 121 us
directory /test3 removed!
  waited 88 us
  waited 110 us
  waited 122 us
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		3140
FILE	PRINTOUTPUT2.txt		3150
FILE	file10		64
FILE	file1		144
FILE	file20		64
FILE	file2		144
FILE	file30		64
FILE	file3		144
DIR	structuredData / 
	FILE	logger.txt		2400
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		80
which matches what I see with SPIFlash. Now I reload the sketch:
Code:
D:\Users\Merli\Documents\Arduino\littlefs_teensy_test3\littlefs_teensy_test3.ino Nov  7 2020 07:37:16
LittleFS Timer Test
QSPI flash begin
Flash ID: EF 40 18
Flash size is 16.00 Mbyte
attemping to mount existing media
success
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		3768
FILE	file10		128
FILE	file1		160
FILE	file2		208
FILE	file30		96
FILE	file3		208
DIR	test1 / 
	FILE	file1		112

Using println and printf to printoutput file
opened PRINTOUTPUT1.txt
opened PRINTOUTPUT2.txt
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		4396
FILE	PRINTOUTPUT2.txt		3780
FILE	file1		160
FILE	file2		208
FILE	file3		208
DIR	test1 / 
	FILE	file1		112

-------------------------------
File1 contents:
-------------------------------
File1 size: 4396
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcde
ghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghi
klmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmno
qrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrs
uvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvw
yz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz
R
c: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz
Rec: 
, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Flo
t: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 
2.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.4
0000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000,
Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int
 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100

bcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcd
fghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghi
klmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcdefghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmn
pqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghijklmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqr
tuvwxyz
Rec: 9, Float: 35.400000, Int: 107

-------------------------------
File3 byte conversion test:
-------------------------------

Data_0: true
Data_1: 1.3574999571
Data_2: 314159
Data_3: 142
19
The Quick Brown Fox
Init Done - array loaded
...... ...... ......
create folder
  failed


2nd Directory contents:
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		4396
FILE	PRINTOUTPUT2.txt		3780
FILE	file1		160
FILE	file2		208
FILE	file3		208
DIR	test1 / 
	FILE	file1		112


true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox

printDirectory
--------------
FILE	PRINTOUTPUT1.txt		3768
FILE	file10		144
FILE	file20		128
FILE	file30		112
DIR	structuredData / 
	FILE	logger.txt		4320
DIR	test2 / 
DIR	test3 / 

printDirectory
--------------
FILE	PRINTOUTPUT1.txt		3768
FILE	file10		144
FILE	file20		128
FILE	file30		112
DIR	structuredData / 
	FILE	logger.txt		4320
DIR	test2 / 
	FILE	file2		16
DIR	test3 / 
	FILE	file3		16

file /test3/file3 removed!
directory /test3 removed!
[COLOR="#0000FF"]printDirectory
--------------
FILE	PRINTOUTPUT1.txt		3768
FILE	file10		144
FILE	file20		128
FILE	file30		112
DIR	structuredData / 
	FILE	logger.txt		4320[/COLOR]
Red highlighted printDirectory should match:
Code:
printDirectory
--------------
FILE	PRINTOUTPUT1.txt		3140
FILE	PRINTOUTPUT2.txt		3150
FILE	file10		64
FILE	file1		144
FILE	file20		64
FILE	file2		144
FILE	file30		64
FILE	file3		144
DIR	structuredData / 
	FILE	logger.txt		2400
FILE	test.txt		50
DIR	test1 / 
	FILE	file1		80
but it seems to loose some of the files/directories. The same thing happens on the last printDirectory, hightlighted in blue.

EDIT:
forgot to post the sketch:
Code:
#include <LittleFS.h>

//LittleFS_RAM myfs;
//LittleFS_SPIFlash myfs;
LittleFS_QSPIFlash myfs;
char buf[200000];

File file1, file2, file3;

char fname[32] = "my_file1";
int szLen = strlen( buf );
elapsedMicros my_us;
uint32_t lCnt = 0;
uint32_t cCnt = 0;

//define a struct of various data types
 struct MYDATA_t {
  bool data_0;
  float data_1; 
  long data_2; 
  int data_3;
  char data_4[32];
};

//define a struct joining MYDATA_t to an array of bytes to be stored
 union MYDATA4RAM_t {
 MYDATA_t datastruct;
 char Packet[sizeof(MYDATA_t)];
};

MYDATA4RAM_t mydata; //data to be written in memory
MYDATA4RAM_t readdata; //data read from memory


void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  pinMode(6, INPUT_PULLUP);
  while (!Serial) ; // wait
    Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  Serial.println("LittleFS Timer Test"); delay(5);
  
  //if (!myfs.begin(buf, sizeof(buf))) {
  //if(!myfs.begin(6)) {
  if(!myfs.begin()) {
    Serial.println("Error starting ramdisk");
    while (1) ;
  }

  printDirectory();

  //test of print
  Serial.println("Using println and printf to printoutput file");
  file1 = myfs.open("PRINTOUTPUT1.txt", FILE_WRITE);
  Serial.println("opened PRINTOUTPUT1.txt");
  file2 = myfs.open("PRINTOUTPUT2.txt", FILE_WRITE);
  Serial.println("opened PRINTOUTPUT2.txt");

  for(uint8_t i = 0; i < 10; i++) {
    file1.println("abcdefghijklmnopqrstuvwxyz");
    file1.printf("Rec: %d, Float: %f, Int: %d\n",i,i+26.4, i+98);
    file2.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    //eRAM.println("THIS IS A TEST");
    file2.printf("Rec: %d, Float: %f, Int: %d\n",i,i+56.4, i+198);
  }

  file1.close();
  file2.close();

  printDirectory();
  
  Serial.println("-------------------------------");
  Serial.println("File1 contents:");
  Serial.println("-------------------------------");

  file1 = myfs.open("PRINTOUTPUT1.txt");
  Serial.printf("File1 size: %d\n", file1.size());
  int filesize = file1.size();
  for(uint8_t i = 0; i <30; i++){
      char buf[256];
      int n = file1.read(buf, 256);
      //Serial.printf("read %d bytes\n", n);
      if (n > 255) n = 255;
      buf[n] = 0;
      Serial.println(buf);
      //Used this in place of a file1.eof() function
      //if((file1.position()+1) > filesize) break;
      if(file1.available() == 0) break;
  }
  file1.close();

  structuredWrite();

}
  
void structuredWrite(){
  Serial.println("-------------------------------");
  Serial.println("File3 byte conversion test:");
  Serial.println("-------------------------------");
  Serial.println();
  
  uint32_t arraySize = sizeof(MYDATA_t);
  
  //---------init data - load array
  mydata.datastruct.data_0 = true;
  Serial.print("Data_0: ");
  if (mydata.datastruct.data_0) Serial.println("true");
  if (!mydata.datastruct.data_0) Serial.println("false");
  mydata.datastruct.data_1 = 1.3575;
  Serial.print("Data_1: ");
  Serial.println(mydata.datastruct.data_1, DEC);
  mydata.datastruct.data_2 = 314159L;
  Serial.print("Data_2: ");
  Serial.println(mydata.datastruct.data_2, DEC);
  mydata.datastruct.data_3 = 142;
  Serial.print("Data_3: ");
  Serial.println(mydata.datastruct.data_3, DEC);
  //string test
  String string_test = "The Quick Brown Fox";
  int stringLen = string_test.length();
  Serial.println(stringLen);
  string_test.toCharArray(mydata.datastruct.data_4,stringLen+1);
  Serial.println(string_test);
    
  Serial.println("Init Done - array loaded");
  Serial.println("...... ...... ......");

  Serial.println("create folder");
  if (myfs.mkdir("structuredData")) {
    Serial.println("  success");
  } else {
    Serial.println("  failed");
  }
  Serial.println();

  //lets try something more interesting and complicated
  file3 = myfs.open("/structuredData/logger.txt", FILE_WRITE);
   for(int32_t i = 0; i < 10; i++) {
    file3.write(mydata.Packet, arraySize);
  }
  file3.close();

  Serial.println();
  Serial.println("2nd Directory contents:");
  printDirectory();
  Serial.println();
  
  file3 = myfs.open("/structuredData/logger.txt");
  for(uint8_t i = 0; i <30; i++){
    //if(eRAM.f_eof(file3)) //break loop on EOF
    //    break;
       int n = file3.read(readdata.Packet, arraySize);
      //Used this in place of a file1.eof() function
   
      //---------Send data to serial
      if (readdata.datastruct.data_0) Serial.print("true");
      if (!readdata.datastruct.data_0) Serial.print("false");
      Serial.print(", ");
      Serial.print(readdata.datastruct.data_1, DEC);
      Serial.print(", ");
      Serial.print(readdata.datastruct.data_2, DEC);
      Serial.print(", ");
      Serial.print(readdata.datastruct.data_3, DEC);  
      Serial.print(", ");
        for (uint8_t j = 0; j < stringLen; j++) {
          Serial.print(readdata.datastruct.data_4[j]);
        }
      Serial.println();
      if((file3.position()+1) > file3.size()) break;
      //if(file3.available() == 0) break;
  }
  
  file3.close();

  file1 = myfs.open("file1", FILE_WRITE);
  file2 = myfs.open("file2", FILE_WRITE);
  file3 = myfs.open("file3", FILE_WRITE);
  file1.println("this is a test");
  file2.println("this is a test");
  file3.println("this is a test");  
  file1.close();
  file2.close();
  file3.close();
  file1 = myfs.open("file10", FILE_WRITE);
  file2 = myfs.open("file20", FILE_WRITE);
  file3 = myfs.open("file30", FILE_WRITE);
  file1.println("this is a test");
  file2.println("this is a test");
  file3.println("this is a test");
  file1.close();
  file2.close();
  file3.close();

  //next test
  //lets make a few files and directories.
  Serial.println();
  file1 = myfs.open("file1", FILE_WRITE);
  file2 = myfs.open("file2", FILE_WRITE);
  file3 = myfs.open("file3", FILE_WRITE);
  file1.println("this is a test");
  file2.println("this is a test");
  file3.println("this is a test");
  file1.close();
  file2.close();
  file3.close();

  myfs.mkdir("test1");
  myfs.mkdir("test2");
  myfs.mkdir("test3");
  printDirectory();
  file1 = myfs.open("/test1/file1", FILE_WRITE);
  file2 = myfs.open("/test2/file2", FILE_WRITE);
  file3 = myfs.open("/test3/file3", FILE_WRITE);
  file1.println("this is a test");
  file2.println("this is a test");
  file3.println("this is a test");
  file1.close();
  file2.close();
  file3.close();


  printDirectory();

  //now lets remove them
  if(myfs.remove("/test3/file3") == true) 
          Serial.println("file /test3/file3 removed!");
  if(myfs.rmdir("test3") == true)
          Serial.println("directory /test3 removed!");
  myfs.remove("/test2/file2");
  myfs.rmdir("test2");

  printDirectory();
  
}


void printDirectory() {
  Serial.println("printDirectory\n--------------");
  printDirectory(myfs.open("/"), 0);
  Serial.println();
}

void printDirectory(File dir, int numTabs) {
  //dir.whoami();
  while (true) {
 
    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      //Serial.println("**nomorefiles**");
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }

    if(entry.isDirectory()) {
      Serial.print("DIR\t");
    } else {
      Serial.print("FILE\t");
    }
    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();
  }
}


void loop() {
}
 
Last edited:
Back
Top