Can't get this to work: LittleFS + Teensy 4.0 + 25F040C

KrisKasprzak

Well-known member
All,

I'm trying to get LittleFS working with a Teensy 4.0 and a 25F040 with no luck. I'm using Arduino IDE 1.8.13 and Teensyduino 1.57

My chip is:
https://www.digikey.com/en/products/detail/microchip-technology/SST25PF040C-40I-SN/5844622


I realize there are very specific memory chips that can be used, maybe this chip is incompatible.

wiring

Chip Teenys pin
CE 10
SO/SIO 12 (tried 11 as well)
WP no connection
Vss GND
SI/SIO 11 (tried 12 as well)
SCK 13
HOLD no connection
VDD 3v3.

Im running the Little FS example only changing the CS pin to pin 10

I can't get the chip to be recognized. Error is:

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_modified_sketch_438428\LittleFS_SPI_Simple_Datalogger.ino Oct 2 2022 16:49:22
Initializing LittleFS ... Error starting SPI FLASH

Any help greatly appreciated.




Code:
/*
  LittleFS  datalogger
 
 This example shows how to log data from three analog sensors
 to an storage device such as a FLASH.
 
 This example code is in the public domain.
 */
#include <LittleFS.h>

// LittleFS supports creating file systems (FS) in multiple memory types.  Depending on the 
// memory type you want to use you would uncomment one of the following constructors

LittleFS_SPIFlash myfs;  // Used to create FS on SPI NOR flash chips such as the W25Q16JV*IQ/W25Q16FV,
                         // for the full list of supported NOR flash see 
                         // https://github.com/PaulStoffregen/LittleFS#nor-flash

//LittleFS_SPINAND myfs;  // Used to create FS on SPI NAND flash chips on a SPI port 
                          // such as SPI, SPI1, SPI2 etc.  For the full list of supported 
                          //  NAND Flash chips see https://github.com/PaulStoffregen/LittleFS#nand-flash

//LittleFS_SPIFram myfs;  // Used to create FS on FRAM memory chips such as the FM25V10-G.  
                          // For the full list of supported chips see https://github.com/PaulStoffregen/LittleFS#fram

//Chip select pin for SPI lash chips such as the W25N01G. For the full list of supported NAND flash see
// https://github.com/PaulStoffregen/LittleFS#nand-flash.  
// The chipSelect pin can be any digital pin.  However, if using the Teensy Audio shield chipSelect is pin 6. 
const int chipSelect = 10; 

File dataFile;  // Specifes that dataFile is of File type

int record_count = 0;
bool write_data = false;

void setup()
{

  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    // wait for serial port to connect.
  }
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);

  Serial.print("Initializing LittleFS ... ");
delay(100);
  // see if the Flash is present and can be initialized:
  // Note:  SPI is default so if you are using SPI and not SPI for instance
  //        you can just specify myfs.begin(chipSelect). 
  if (!myfs.begin(chipSelect)) {
    Serial.printf("Error starting %s\n", "SPI FLASH");
    while (1) {
      // Error, so don't do anything more - stay stuck here
    }
  }
  Serial.println("LittleFS initialized.");
  
  menu();
  
}

void loop()
{ 
  if ( Serial.available() ) {
    char rr;
    rr = Serial.read();
    switch (rr) {
      case 'l': listFiles(); break;
      case 'e': eraseFiles(); break;
      case 's':
        {
          Serial.println("\nLogging Data!!!");
          write_data = true;   // sets flag to continue to write data until new command is received
          // opens a file or creates a file if not present,  FILE_WRITE will append data to
          // to the file created.
          dataFile = myfs.open("datalog.txt", FILE_WRITE);
          logData();
        }
        break;
      case 'x': stopLogging(); break;
      case 'd': dumpLog(); break;
      case '\r':
      case '\n':
      case 'h': menu(); break;
    }
    while (Serial.read() != -1) ; // remove rest of characters.
  } 

  if(write_data) logData();
}

void logData()
{
    // make a string for assembling the data to log:
    String dataString = "";
  
    // read three sensors and append to the string:
    for (int analogPin = 0; analogPin < 3; analogPin++) {
      int sensor = analogRead(analogPin);
      dataString += String(sensor);
      if (analogPin < 2) {
        dataString += ",";
      }
    }
  
    // if the file is available, write to it:
    if (dataFile) {
      dataFile.println(dataString);
      // print to the serial port too:
      Serial.println(dataString);
      record_count += 1;
    } else {
      // if the file isn't open, pop up an error:
      Serial.println("error opening datalog.txt");
    }
    delay(100); // run at a reasonable not-too-fast speed for testing
}

void stopLogging()
{
  Serial.println("\nStopped Logging Data!!!");
  write_data = false;
  // Closes the data file.
  dataFile.close();
  Serial.printf("Records written = %d\n", record_count);
}


void dumpLog()
{
  Serial.println("\nDumping Log!!!");
  // open the file.
  dataFile = myfs.open("datalog.txt");

  // if the file is available, write to it:
  if (dataFile) {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
    }
    dataFile.close();
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  } 
}

void menu()
{
  Serial.println();
  Serial.println("Menu Options:");
  Serial.println("\tl - List files on disk");
  Serial.println("\te - Erase files on disk");
  Serial.println("\ts - Start Logging data (Restarting logger will append records to existing log)");
  Serial.println("\tx - Stop Logging data");
  Serial.println("\td - Dump Log");
  Serial.println("\th - Menu");
  Serial.println();
}

void listFiles()
{
  Serial.print("\n Space Used = ");
  Serial.println(myfs.usedSize());
  Serial.print("Filesystem Size = ");
  Serial.println(myfs.totalSize());

  printDirectory(myfs);
}

void eraseFiles()
{
  myfs.quickFormat();  // performs a quick format of the created di
  Serial.println("\nFiles erased !");
}

void printDirectory(FS &fs) {
  Serial.println("Directory\n---------");
  printDirectory(fs.open("/"), 0);
  Serial.println();
}

void printDirectory(File dir, int numSpaces) {
   while(true) {
     File entry = dir.openNextFile();
     if (! entry) {
       //Serial.println("** no more files **");
       break;
     }
     printSpaces(numSpaces);
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numSpaces+2);
     } else {
       // files have sizes, directories do not
       printSpaces(36 - numSpaces - strlen(entry.name()));
       Serial.print("  ");
       Serial.println(entry.size(), DEC);
     }
     entry.close();
   }
}

void printSpaces(int num) {
  for (int i=0; i < num; i++) {
    Serial.print(" ");
  }
}
 
KrisKasprzak said:
I can't get the chip to be recognized. Error is:

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_modif ied_sketch_438428\LittleFS_SPI_Simple_Datalogger.i no Oct 2 2022 16:49:22
Initializing LittleFS ... Error starting SPI FLASH

Hi Kris.

Sorry at this time that particular chip isn't supported by LittleFS. Right now it supports the following (extracted from LittleFS.cpp.
Code:
{{0xEF, 0x40, 0x15}, 24, 256, 32768, 0x52, 2097152, 3000, 1600000, "W25Q16JV*Q/W25Q16FV"},  // Winbond W25Q16JV*Q/W25Q16FV
{{0xEF, 0x40, 0x16}, 24, 256, 32768, 0x52, 4194304, 3000, 1600000, "W25Q32JV*Q/W25Q32FV"},  // Winbond W25Q32JV*Q/W25Q32FV
{{0xEF, 0x40, 0x17}, 24, 256, 65536, 0xD8, 8388608, 3000, 2000000, "W25Q64JV*Q/W25Q64FV"},  // Winbond W25Q64JV*Q/W25Q64FV
{{0xEF, 0x40, 0x18}, 24, 256, 65536, 0xD8, 16777216, 3000, 2000000, "W25Q128JV*Q/W25Q128FV"}, // Winbond W25Q128JV*Q/W25Q128FV
{{0xEF, 0x40, 0x19}, 32, 256, 65536, 0xDC, 33554432, 3000, 2000000, "W25Q256JV*Q"}, // Winbond W25Q256JV*Q
{{0xEF, 0x40, 0x20}, 32, 256, 65536, 0xDC, 67108864, 3500, 2000000, "W25Q512JV*Q"}, // Winbond W25Q512JV*Q
{{0xEF, 0x40, 0x21}, 32, 256, 65536, 0xDC, 134217728, 3500, 2000000, "W25Q01JV*Q"},// Winbond W25Q01JV*Q
{{0xEF, 0x70, 0x17}, 24, 256, 65536, 0xD8, 8388608, 3000, 2000000, "W25Q64JV*M (DTR)"},  // Winbond W25Q64JV*M (DTR)
{{0xEF, 0x70, 0x18}, 24, 256, 65536, 0xD8, 16777216, 3000, 2000000, "W25Q128JV*M (DTR)"}, // Winbond W25Q128JV*M (DTR)
{{0xEF, 0x70, 0x19}, 32, 256, 65536, 0xDC, 33554432, 3000, 2000000, "W25Q256JV*M (DTR)"}, // Winbond W25Q256JV*M (DTR)
{{0xEF, 0x80, 0x19}, 32, 256, 65536, 0xDC, 33554432, 3000, 2000000, "W25Q256JW*M"}, // Winbond (W25Q256JW*M)
{{0xEF, 0x70, 0x20}, 32, 256, 65536, 0xDC, 67108864, 3500, 2000000, "W25Q512JV*M (DTR)"}, // Winbond W25Q512JV*M (DTR)
{{0x1F, 0x84, 0x01}, 24, 256,  4096, 0x20, 524288, 2500, 300000, "AT25SF041"},    // Adesto/Atmel AT25SF041
{{0x01, 0x40, 0x14}, 24, 256,  4096, 0x20, 1048576, 5000, 300000, "S25FL208K"},   // Spansion S25FL208K

You might try to add it assuming that the commands are similar. Getting late for me - downloaded the datasheet and will try and look tomorrow.
 
Here's my best guess for that chip based on just reading the datasheet.

Code:
{{0x62, 0x06, 0x13}, 24, 256,  4096, 0x20, 524288, 5000, 300000, "SST25PF040C"},

If this actually works, please confirm and I'll add it.
 
Here's a guess for the other chip, again only from reading the datasheet.

Code:
{{0xEF, 0x40, 0x14}, 24, 256, 4096, 0x20, 1048576, 5000, 300000, "W25Q80DV"},
 
Here's my best guess for that chip based on just reading the datasheet.

Code:
{{0x62, 0x06, 0x13}, 24, 256,  4096, 0x20, 524288, 5000, 300000, "SST25PF040C"},

If this actually works, please confirm and I'll add it.

Looks like you beat me too it. But yep.
 
BINGO!

You guys are super geniuses.

I did the following

1. added the line
{{0x62, 0x06, 0x13}, 24, 256, 4096, 0x20, 524288, 5000, 300000, "SST25PF040C"},
2. tied WP to low
3. Tied HOLD to high

Thanks again, you are the best!

Sample results

Code:
C:\Users\Administrator\Documents\Arduino\ChipTester\ChipTester.ino Oct  3 2022 13:05:57
Initializing LittleFS ... LittleFS initialized.

Menu Options:
	l - List files on disk
	e - Erase files on disk
	s - Start Logging data (Restarting logger will append records to existing log)
	x - Stop Logging data
	d - Dump Log
	h - Menu


Logging Data!!!
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,14,8
1023,13,8
1023,13,8
1023,13,9
1023,13,9
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,14,8
1023,13,8
1022,13,8
1023,13,8
1023,14,8
1023,14,8
1023,13,8

Stopped Logging Data!!!
Records written = 29

Menu Options:
	l - List files on disk
	e - Erase files on disk
	s - Start Logging data (Restarting logger will append records to existing log)
	x - Stop Logging data
	d - Dump Log
	h - Menu


Dumping Log!!!
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,14,8
1023,13,8
1023,13,8
1023,13,9
1023,13,9
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,13,8
1023,14,8
1023,13,8
1022,13,8
1023,13,8
1023,14,8
1023,14,8
1023,13,8
 
Seriously mjs513 and Paul, thanks a million. I wish I could pay back as much as I receive :)

My goals are to have an chip on our race cars data logging system that does all the recording, then after a race we dump the data to and SD card for analysis.

SD cards are very unreliable given our race conditions (rain, high humidity, heat, bumps, jolts, etc.).

Kris
 
Seriously mjs513 and Paul, thanks a million. I wish I could pay back as much as I receive :)

My goals are to have an chip on our race cars data logging system that does all the recording, then after a race we dump the data to and SD card for analysis.

SD cards are very unreliable given our race conditions (rain, high humidity, heat, bumps, jolts, etc.).

Kris

Not a problem Kris. Take my word for no need for payback we all work together :) I have been going to town using your graphing library :)

Oh did you get a chance to try the settings for the W25Q80DV chip.
 
mjs513 I only have the Microchip SST25PF040C device and it works as expected. I can't test the Winbond device.

Also for operation you may consider adding a note on how
1. WP must be low
2. HOLD must be high
 
mjs513 I only have the Microchip SST25PF040C device and it works as expected. I can't test the Winbond device.

Also for operation you may consider adding a note on how
1. WP must be low
2. HOLD must be high

Sorry - I misinterpreted your post thought you had the winbond one as well.

Interesting on the WP having to be low. This is the wiring I have been using:
FlashChipWiring.PNG
 
a quick test, I'm seeing the same results, HOLD must be high to initialize.

Case 1
WP 0
Hold 0
Error starting SPI FLASH

Case 2
WP 0
Hold 1
SPI FLASH initialized.

Case 3
WP 1
Hold 0
Error starting SPI FLASH

Case 4
WP 1
Hold 1
SPI FLASH initialized.
 
This is odd. WP seems to have not effect on protecting data. I'll keep experimenting.

Note: These tests are with a Teensy LC and delay(150) after setting digitalWrites to the WP and HOLD pins



Initialize and access test
WP 1
Hold 1
SPI FLASH initialized.

Menu Options:
l - List files on disk
e - Erase files on disk
s - Start Logging data (Restarting logger will append records to existing log)
x - Stop Logging data
d - Dump Log
h - Menu


Space Used = 16384
Filesystem Size = 524288
Directory
---------
BD_12.csv 418
BD_13.csv 396
** no more files **


Logging Data!!!
372,336,392
428,417,324
316,291,327
403,301,280
312,366,332
354,309,191
355,375,334

Stopped Logging Data!!!
Records written = 7

Dumping Log!!!
372,336,392
428,417,324
316,291,327
403,301,280
312,366,332
354,309,191
355,375,334


///////////////////////////////

Initialize and access test
WP 0
Hold 1
SPI FLASH initialized.

Menu Options:
l - List files on disk
e - Erase files on disk
s - Start Logging data (Restarting logger will append records to existing log)
x - Stop Logging data
d - Dump Log
h - Menu


Space Used = 8192
Filesystem Size = 524288
Directory
---------
** no more files **


Logging Data!!!
443,387,401
402,385,403
439,326,238
359,246,275
365,397,216
387,320,263

Stopped Logging Data!!!
Records written = 6

Dumping Log!!!
443,387,401
402,385,403
439,326,238
359,246,275
365,397,216
387,320,263

Space Used = 8192
Filesystem Size = 524288
Directory
---------
B002_data.csv 78
** no more files **
 
Last edited:
Just looked at the datasheet for the Microchip FLASH. This is what it says for the WP pin:
Code:
The Write Protect (WP#) pin enables the lock-down
function of the BPL bit (bit 7) in the status register.
When WP# is driven low, the execution of the WriteStatus-Register (WRSR) instruction is determined by
the value of the BPL bit (see Table 4-1). When WP# is
high, the lock-down function of the BPL bit is disabled

So basically when driven HIGH lockdown is disabled. Even its LOW you have to you will have to set BPL bits to tell it what to protect if its set to 0 with WP LOW then nothing is protected. Check Table 4.3

Mike
 
Back
Top