Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 48

Thread: T4.1 SerialFlash with soldered optional inboard flashship

  1. #1
    Junior Member
    Join Date
    Mar 2020
    Posts
    18

    T4.1 SerialFlash with soldered optional inboard flashship

    Hi,

    I would like to use SerialFlash to write and read raw audio sample from the optional inboard flashship that I soldered on bottom face of T4.1.
    How can I do that?
    If it's not possible, how can I read-write raw audio sample to this flashship?
    Thx
    Guy

  2. #2
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,392
    You could use Littlfs and an other waveplayer: https://github.com/FrankBoesing/Teen...erLittlsFS.ino
    The example plays a wave file - bit it can work with RAW, too.
    Howver there is no real reason to use RAW files. The wav-header ist rather small, and the data inside wave is "raw".

  3. #3
    Junior Member
    Join Date
    Mar 2020
    Posts
    18
    @Frank B: Thanks a lot for these usefull informations.

  4. #4
    Junior Member
    Join Date
    Mar 2020
    Posts
    18
    @Frank B:

    I can transfer File from SD card to the flashship, so I have for exemple "MOTORLOOP.WAV" file into.

    But when I wanted to play this file with a soft derived from yours, I was never been able to compiled it.

    Code:
    // Simple WAV file player example
    //
    //
    // This example code is in the public domain.
    
    
    #include <LittleFS.h>
    LittleFS_QSPIFlash myfs;
    uint64_t fTot, totSize1;
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <Bounce.h>
    
    // GUItool: begin automatically generated code
    AudioPlaySdWav             playSdWav1;     //xy=323,171
    AudioPlaySdWav             playSdWav2;     //xy=323,171
    AudioPlaySdWav             playSdWav3;     //xy=323,171
    AudioPlaySdWav             playSdWav4;     //xy=323,171
    AudioPlaySdWav             playSdWav5;     //xy=323,171
    AudioPlaySdWav             playSdWav6;     //xy=323,171
    AudioPlaySdWav             playSdWav7;     //xy=323,171
    AudioPlaySdWav             playSdWav8;     //xy=323,171
    
    AudioMixer4              mixer1;         //xy=647,123
    AudioMixer4              mixer3;         //xy=648,212
    //AudioOutputPT8211        pt8211_1;       //xy=828,169
    //AudioOutputI2S           audioOutput;
    AudioOutputMQS           mqs1;
    AudioConnection          patchCord1(playSdWav1, 0, mixer1, 0);
    AudioConnection          patchCord2(playSdWav2, 1, mixer3, 0);
    AudioConnection          patchCord3(playSdWav3, 2, mixer1, 1);
    AudioConnection          patchCord4(playSdWav4, 3, mixer3, 1);
    AudioConnection          patchCord5(playSdWav5, 4, mixer1, 2);
    AudioConnection          patchCord6(playSdWav6, 5, mixer3, 2);
    AudioConnection          patchCord7(playSdWav7, 6, mixer1, 3);
    AudioConnection          patchCord8(playSdWav8, 7, mixer3, 3);
    AudioConnection          patchCord9(mixer1, 0, mqs1, 1);
    AudioConnection          patchCord10(mixer3, 0, mqs1, 1);
    AudioConnection          patchCord11(mixer1, 0, mqs1, 0);
    AudioConnection          patchCord12(mixer3, 0, mqs1, 0);
    //AudioControlSGTL5000     sgtl5000_1;
    
    // GUItool: end automatically generated code
    
    
    // Bounce objects to read six pushbuttons (pins 0-5)
    //
    Bounce button0 = Bounce(0, 5);
    Bounce button1 = Bounce(1, 5);  // 5 ms debounce time
    Bounce button2 = Bounce(2, 5);
    Bounce button3 = Bounce(3, 5);
    Bounce button4 = Bounce(4, 5);
    Bounce button5 = Bounce(5, 5);
    Bounce button6 = Bounce(6, 5);
    
    void setup() {
      Serial.begin(9600);
      if (CrashReport) {
        Serial.println(CrashReport);
        CrashReport.clear();
      }
      
      AudioMemory(50);
      
      Serial.println("LittleFS Test"); delay(5);
      if (!myfs.begin()) {
      //if (!myfs.begin(chipSelect)) {
        Serial.println("Error starting qspidisk");
        while (1) ;
      }
      Serial.printf("TotalSize (Bytes): %d\n", myfs.totalSize());
      //myfs.deviceErase();
    
      delay(1000);
      Serial.println("started");
      printDirectory();
    
     // Configure the pushbutton pins for pullups.
      // Each button should connect from the pin to GND.
      pinMode(0, INPUT_PULLUP);
      pinMode(1, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
      pinMode(3, INPUT_PULLUP);
      pinMode(4, INPUT_PULLUP);
      pinMode(5, INPUT_PULLUP);
      pinMode(6, INPUT_PULLUP);
    }
    
    void playFile(const char *filename)
    {
      Serial.print("Playing file: ");
      Serial.println(filename);
    
      // Start playing the file.  This sketch continues to
      // run while the file plays.
      File ccc = myfs.open(filename);  ///Change to play off QSPI flash
      playSdWav1.play(ccc);
    
      // Simply wait for the file to finish playing.
      while (playSdWav1.isPlaying()) {
            Serial.println("play wav");
        delay(100);
      }
    }
    
    
    void loop() {
     
     // Update all the button objects
      button0.update();
      button1.update();
      button2.update();
      button3.update();
      button4.update();
      button5.update();
      button6.update();
    
      // When the buttons are pressed, just start a sound playing.
      // The audio library will play each sound through the mixers
      // so any combination can play simultaneously.
      //
      if (button0.fallingEdge()) {
        playFile("MOTORLOOP.WAV");
      }
      while (playSdWav1.isPlaying()) {
      }
      
    }
    
    void printDirectory() {
    
      Serial.println("printDirectory\n--------------");
      printDirectory(myfs.open("/"), 0);
      Serial.println();
    }
    
    
    void printDirectory(File dir, int numTabs) {
      //dir.whoami();
      uint64_t fSize = 0;
      uint32_t dCnt = 0, fCnt = 0;
      if ( 0 == dir ) {
        Serial.printf( "\t>>>\t>>>>> No Dir\n" );
        return;
      }
      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;
          totSize1 += 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();
        //Serial.flush();
      }
    }
    The compilation error is :
    Code:
    WavFilePlayerLittlsFS: In function 'void playFile(const char*)':
    WavFilePlayerLittlsFS:100: error: no matching function for call to 'AudioPlaySdWav::play(File&)'
       playSdWav1.play(ccc);
                          ^
    In file included from /home/microguy/TÚlÚchargements/arduino-1.8.15/hardware/teensy/avr/libraries/Audio/Audio.h:128:0,
                     from /home/microguy/Nexcloud/New_Teensy_2021/Prog/test flash w25q128/WavFilePlayerLittlsFS/WavFilePlayerLittlsFS.ino:11:
    /home/microguy/TÚlÚchargements/arduino-1.8.15/hardware/teensy/avr/libraries/Audio/play_sd_wav.h:39:7: note: candidate: bool AudioPlaySdWav::play(const char*)
      bool play(const char *filename);
           ^
    /home/microguy/TÚlÚchargements/arduino-1.8.15/hardware/teensy/avr/libraries/Audio/play_sd_wav.h:39:7: note:   no known conversion for argument 1 from 'File' to 'const char*'
    I tried different things to solve this problem but I didn't find the solution.....

  5. #5
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,392
    Does it work if you use
    AudioPlayWav instead AudioPlaySdWav?

  6. #6
    Junior Member
    Join Date
    Mar 2020
    Posts
    18
    Quote Originally Posted by Frank B View Post
    Does it work if you use
    AudioPlayWav instead AudioPlaySdWav?
    No, compiler doesn't know this command.

  7. #7
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,392
    Have updated the example.. indeed it was outdated. Sorry for that.
    Just tested it - it's working.

    It runs onPT8211 by default, and NAND flash - You have to edit these things.

  8. #8
    Junior Member
    Join Date
    Mar 2020
    Posts
    18
    Quote Originally Posted by Frank B View Post
    Have updated the example.. indeed it was outdated. Sorry for that.
    Just tested it - it's working.

    It runs onPT8211 by default, and NAND flash - You have to edit these things.
    Yeah!!! Big thanks!!! your example works great!

  9. #9
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,392
    Great

    Btw, MJS wrote it.

  10. #10
    Junior Member
    Join Date
    Mar 2020
    Posts
    18
    New problem...

    If I try to play a sound in a loop, it's OK. But If I add a second sound "X" time during the loop, it's always crashing with "X" beetween 2 and 300. in a first time, the "single sound" stops playing and in a second time, the loop stops too .

    Some ideas?

  11. #11
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,392
    No.
    Do you have some code?

  12. #12
    Junior Member
    Join Date
    Mar 2020
    Posts
    18
    Quote Originally Posted by Frank B View Post
    No.
    Do you have some code?
    This is the code I tried :
    Code:
    // Simple WAV file player example
    //
    //
    // This example code is in the public domain.
    
    
    #include <LittleFS.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <Bounce.h>
    #include <play_wav.h>
    
    LittleFS_QSPIFlash myfs;
    uint64_t fTot, totSize1;
    
    // GUItool: begin automatically generated code
    AudioPlayWav           playWav1;     //xy=232,621
    AudioPlayWav           playWav2; //xy=230,663
    AudioPlayWav           playWav3; //xy=232,706
    AudioPlayWav           playWav4; //xy=230,749
    AudioPlayWav           playWav5; //xy=230,850
    AudioPlayWav           playWav6; //xy=229,890
    AudioPlayWav           playWav7; //xy=226,929
    AudioPlayWav           playWav8; //xy=227,968
    AudioMixer4              mixerSingle;         //xy=450,905
    AudioMixer4              mixerloop;         //xy=455,681
    AudioMixer4              mixerFinal;         //xy=654,814
    AudioAmplifier           amp1;           //xy=809,815
    AudioOutputMQS           mqs1;           //xy=972,818
    AudioConnection          patchCord1(playWav1, 0, mixerloop, 0);
    AudioConnection          patchCord2(playWav2, 0, mixerloop, 1);
    AudioConnection          patchCord3(playWav3, 0, mixerloop, 2);
    AudioConnection          patchCord4(playWav4, 0, mixerloop, 3);
    AudioConnection          patchCord5(playWav5, 0, mixerSingle, 0);
    AudioConnection          patchCord6(playWav6, 0, mixerSingle, 1);
    AudioConnection          patchCord7(playWav7, 0, mixerSingle, 2);
    AudioConnection          patchCord8(playWav8, 0, mixerSingle, 3);
    AudioConnection          patchCord9(mixerSingle, 0, mixerFinal, 1);
    AudioConnection          patchCord10(mixerloop, 0, mixerFinal, 0);
    AudioConnection          patchCord11(mixerFinal, amp1);
    AudioConnection          patchCord12(amp1, 0, mqs1, 0);
    AudioConnection          patchCord13(amp1, 0, mqs1, 1);
    // GUItool: end automatically generated code
    
    
    extern uint32_t _AudioPlaySdWavInstances;
    
    
    int count = 0;
    
    void setup() {
      Serial.begin(9600);
      AudioMemory(50);
      mixerloop.gain(0, 0.3);
      mixerSingle.gain(0,1.3);
      Serial.println("LittleFS Test"); delay(5);
      if (!myfs.begin()) {
        Serial.println("Error starting qspidisk");
        while (1) ;
      }
      Serial.printf("TotalSize (Bytes): %d\n", myfs.totalSize());
      
    
      delay(1000);
      Serial.println("started");
      printDirectory();
    
    // Initialize processor and memory measurements
      AudioProcessorUsageMaxReset();
      AudioMemoryUsageMaxReset();
    
    }
    
    
    void playLoopFile(const char *filename)
    {
      //Serial.print("Playing Loop file: ");
     // Serial.println(filename);
      File ccc = myfs.open(filename);  //Change to play off QSPI flash
      playWav1.play(ccc);
    }
    void playSingleFile1(const char *filename1)
    {
      if(!playWav5.isPlaying()){
      File cc5 = myfs.open(filename1);  //Change to play off QSPI flash
      playWav5.play(cc5);
      }
    }
    void playSingleFile2(const char *filename2)
    {
      if(!playWav6.isPlaying()){
      File cc6 = myfs.open(filename2);  //Change to play off QSPI flash
      playWav6.play(cc6);
      }
    }  
    
    
    unsigned long last_time = millis();
    
    void loop() {
    
    
      // When the buttons are pressed, just start a sound playing.
      // The audio library will play each sound through the mixers
      // so any combination can play simultaneously.
      //
      if (!playWav1.isPlaying()){
      playLoopFile("Pompe.wav");
      }
        
    if(millis() - last_time >= 200) {
        
        Serial.print("Proc = ");
        Serial.print(AudioProcessorUsage());
        Serial.print(" (");    
        Serial.print(AudioProcessorUsageMax());
        Serial.print("),  Mem = ");
        Serial.print(AudioMemoryUsage());
        Serial.print(" (");    
        Serial.print(AudioMemoryUsageMax());
        Serial.println(")");
        
        last_time = millis();
       
        if (!playWav5.isPlaying()){
        playSingleFile1("DEMARRE.WAV");
        count++;
        Serial.println(count);
        }
        
        if (!playWav6.isPlaying()){
        playSingleFile2("ding dong.wav");
        }
    
      
    }
    }
    
    void printDirectory() {
    
      Serial.println("printDirectory\n--------------");
      printDirectory(myfs.open("/"), 0);
      Serial.println();
    }
    
    
    void printDirectory(File dir, int numTabs) {
      //dir.whoami();
      uint64_t fSize = 0;
      uint32_t dCnt = 0, fCnt = 0;
      if ( 0 == dir ) {
        Serial.printf( "\t>>>\t>>>>> No Dir\n" );
        return;
      }
      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;
          totSize1 += 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();
        //Serial.flush();
      }
    }
    You need to change some part according to your setting and 3 wav to play (each wav is less than 5sec).


    EDIT: it seems that if you change 1 sample sound by another, it play first sample for some time after ... I think there is a problem into the memory management.
    Last edited by microguy; 10-15-2021 at 05:06 PM.

  13. #13
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,392
    Indeed, playing multiple files seems not to work with LittlFS.
    I'll have a look.

  14. #14
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,392
    Looks like there is no way to use several files with Littlfs.
    It's just too slow.

    Code:
    #include <LittleFS.h>
    
    //LittleFS_QSPIFlash myfs;
    LittleFS_QPINAND   myfs;
    
    File f1,f2,f3;
    
    void setup() {
      Serial.begin(9600);
      delay(1000);
      
      // try to add QSPI Flash
      if (myfs.begin()) {
        Serial.println("Added QSPI Flash");
      } else {
        Serial.println("No Littlefs");
        abort();
      }
     long ms;
     ms = millis();
     f1 = myfs.open("1.txt");
     Serial.printf("%d ms\n", millis() - ms);
    
     ms = millis();
     f2 = myfs.open("2.txt");
     Serial.printf("%d ms\n", millis() - ms);
     
     ms = millis();
     f3 = myfs.open("3.txt");
     Serial.printf("%d ms\n", millis() - ms);
     
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
    Just opening a file, without reading takes 10 milliseconds.
    The Audiolibrary needs to read the files more often, so, no chance. It has to be (minimum) 10 times faster. And that's only for open(). Did not bother to measure concurrend reads().

    Code:
    Added QSPI Flash
    9 ms
    9 ms
    8 ms
    Then, I saw LittlFS is a very old version. Maybe this is the problem.
    As my last bug reports got no answers, and one was even "fixed" by editing a comment in the sourcecode, it make no sense for me to report that. Maybe you want?
    Edit: It may have more chances, then.

    Frank

    Edit: Also, it's not thread-safe. The newer versions seems to be and has utility funcs (which will not be supported by FS.h anyway)
    Last edited by Frank B; 10-15-2021 at 07:18 PM.

  15. #15
    Junior Member
    Join Date
    Mar 2020
    Posts
    18
    From my point of view, it's really strange that the problem comes only from a problem of reading speed as sound is not hanging but crashing definitely.
    I need to reset Teensy, furthermore crash happen at variable frequency....
    Maybe, a solution could be to load in advance file in ram before playing? do you think it could be possible?
    Some time, with a 5 second loop, I can play a 2nd sample (3sec) 500 time without crash but with the same 2 sample sometime only 2 times....

  16. #16
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,392
    If the file open takes 10ms it gets interrupted 3 times by the audio library. This goes wrong, obviously. I added some testcode, and some of the hangs/crashes occur in open().
    In your special case it's a bit of luck, because you define 8 files, so 5 are pause, which gives it a bit higher chance to succeed.
    (btw, your code is a bit confusing.. and using local File() is not ideal..

    I did not test RAM or ERAM.

    However, the _exact_ same code in the library plays 14 stereo files from SD - but that needs a very fast SD Card.
    Feel free to submit a PR if you find a bug.

  17. #17
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,647
    Quote Originally Posted by Frank B
    Just opening a file, without reading takes 10 milliseconds.
    The Audiolibrary needs to read the files more often, so, no chance. It has to be (minimum) 10 times faster. And that's only for open(). Did not bother to measure concurrend reads().

    Code:
    Added QSPI Flash
    9 ms
    9 ms
    8 ms
    Then, I saw LittlFS is a very old version. Maybe this is the problem.
    As my last bug reports got no answers, and one was even "fixed" by editing a comment in the sourcecode, it make no sense for me to report that. Maybe you want?
    Edit: It may have more chances, then.
    Ran your test case on a QSPI Flash (64MegaByte one forgot the number) and got (I am using 1.56beta2):
    Code:
    Added QSPI Flash
    0 ms
    0 ms
    0 ms
    or changing your code to measure microseconds:
    Code:
    Added QSPI Flash
    30 micros
    37 micros
    37 micros
    Now for a QSPI NAND Flash chip (M02)
    Code:
    Added QSPI Flash
    85 micros
    92 micros
    92 micros
    I will try and run the audio example when I get a chance but in the middle of a couple of things around the house but wanted to try this out. Here is the sketch I used.
    Code:
    #include <LittleFS.h>
    
    LittleFS_QSPIFlash myfs;
    //LittleFS_QPINAND   myfs;
    
    File f1,f2,f3;
    
    void setup() {
      Serial.begin(9600);
      delay(1000);
      
      // try to add QSPI Flash
      if (myfs.begin()) {
        Serial.println("Added QSPI Flash");
      } else {
        Serial.println("No Littlefs");
        abort();
      }
      
     uint64_t ms;
     ms = micros();
     f1 = myfs.open("1.txt");
     Serial.printf("%u micros\n", micros() - ms);
    
     ms = micros();
     f2 = myfs.open("2.txt");
     Serial.printf("%u micros\n", micros() - ms);
     
     ms = micros();
     f3 = myfs.open("3.txt");
     Serial.printf("%u micros\n", micros() - ms);
     
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }

  18. #18
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    15,259
    @Frank - where was the newer improved LittleFS source seen?

  19. #19
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,647
    @Frank B
    I modified the test sketch in post #12 to use multiple files with a LittleFS QSPI Flash and the audio shield (rev D) on the T4.1 and it seems to be working, i.e., heard all 3 files playing at the same time. Here is the sketch I used and printout from the serial monitor. Not sure why you are seeing such poor results with LittleFS and QSPI Flash.
    Code:
    // Simple WAV file player example
    //
    //
    // This example code is in the public domain.
    
    
    #include <LittleFS.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <Bounce.h>
    #include <play_wav.h>
    
    LittleFS_QSPIFlash myfs;
    uint64_t fTot, totSize1;
    
    // GUItool: begin automatically generated code
    AudioPlayWav           playWav1;     //xy=232,621
    AudioPlayWav           playWav2; //xy=230,663
    AudioPlayWav           playWav3; //xy=232,706
    AudioPlayWav           playWav4; //xy=230,749
    AudioPlayWav           playWav5; //xy=230,850
    AudioPlayWav           playWav6; //xy=229,890
    AudioPlayWav           playWav7; //xy=226,929
    AudioPlayWav           playWav8; //xy=227,968
    AudioMixer4              mixerSingle;         //xy=450,905
    AudioMixer4              mixerloop;         //xy=455,681
    AudioMixer4              mixerFinal;         //xy=654,814
    AudioAmplifier           amp1;           //xy=809,815
    AudioOutputI2S           mqs1;           //xy=972,818
    AudioConnection          patchCord1(playWav1, 0, mixerloop, 0);
    AudioConnection          patchCord2(playWav2, 0, mixerloop, 1);
    AudioConnection          patchCord3(playWav3, 0, mixerloop, 2);
    AudioConnection          patchCord4(playWav4, 0, mixerloop, 3);
    AudioConnection          patchCord5(playWav5, 0, mixerSingle, 0);
    AudioConnection          patchCord6(playWav6, 0, mixerSingle, 1);
    AudioConnection          patchCord7(playWav7, 0, mixerSingle, 2);
    AudioConnection          patchCord8(playWav8, 0, mixerSingle, 3);
    AudioConnection          patchCord9(mixerSingle, 0, mixerFinal, 1);
    AudioConnection          patchCord10(mixerloop, 0, mixerFinal, 0);
    AudioConnection          patchCord11(mixerFinal, amp1);
    AudioConnection          patchCord12(amp1, 0, mqs1, 0);
    AudioConnection          patchCord13(amp1, 0, mqs1, 1);
    // GUItool: end automatically generated code
    AudioControlSGTL5000     sgtl5000_1;
    
    
    extern uint32_t _AudioPlaySdWavInstances;
    
    
    int count = 0;
    
    void setup() {
      Serial.begin(9600);
      AudioMemory(50);
      mixerloop.gain(0, 0.3);
      mixerSingle.gain(0,1.3);
    
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
      
      Serial.println("LittleFS Test"); delay(5);
      if (!myfs.begin()) {
        Serial.println("Error starting qspidisk");
        while (1) ;
      }
      Serial.printf("TotalSize (Bytes): %d\n", myfs.totalSize());
      
    
      delay(1000);
      Serial.println("started");
      printDirectory();
    
      
    // Initialize processor and memory measurements
      AudioProcessorUsageMaxReset();
      AudioMemoryUsageMaxReset();
    
    }
    
    
    void playLoopFile(const char *filename)
    {
      //Serial.print("Playing Loop file: ");
     // Serial.println(filename);
      File ccc = myfs.open(filename);  //Change to play off QSPI flash
      playWav1.play(ccc);
    }
    void playSingleFile1(const char *filename1)
    {
      if(!playWav5.isPlaying()){
      File cc5 = myfs.open(filename1);  //Change to play off QSPI flash
      playWav5.play(cc5);
      }
    }
    void playSingleFile2(const char *filename2)
    {
      if(!playWav6.isPlaying()){
      File cc6 = myfs.open(filename2);  //Change to play off QSPI flash
      playWav6.play(cc6);
      }
    }  
    
    
    unsigned long last_time = millis();
    
    void loop() {
    
    
      // When the buttons are pressed, just start a sound playing.
      // The audio library will play each sound through the mixers
      // so any combination can play simultaneously.
      //
      if (!playWav1.isPlaying()){
      playLoopFile("operational.wav");
      }
        
    if(millis() - last_time >= 200) {
        
        Serial.print("Proc = ");
        Serial.print(AudioProcessorUsage());
        Serial.print(" (");    
        Serial.print(AudioProcessorUsageMax());
        Serial.print("),  Mem = ");
        Serial.print(AudioMemoryUsage());
        Serial.print(" (");    
        Serial.print(AudioMemoryUsageMax());
        Serial.println(")");
        
        last_time = millis();
       
        if (!playWav5.isPlaying()){
        playSingleFile1("one_moment.wav");
        count++;
        Serial.println(count);
        }
        
        if (!playWav6.isPlaying()){
        playSingleFile2("calculations.wav");
        }
    
      
    }
    }
    
    void printDirectory() {
    
      Serial.println("printDirectory\n--------------");
      printDirectory(myfs.open("/"), 0);
      Serial.println();
    }
    
    
    void printDirectory(File dir, int numTabs) {
      //dir.whoami();
      uint64_t fSize = 0;
      uint32_t dCnt = 0, fCnt = 0;
      if ( 0 == dir ) {
        Serial.printf( "\t>>>\t>>>>> No Dir\n" );
        return;
      }
      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;
          totSize1 += 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();
        //Serial.flush();
      }
    }

    Code:
    LittleFS Test
    TotalSize (Bytes): 16777216
    started
    printDirectory
    --------------
    FILE	calculations.wav		426812
    FILE	completed.wav		276972
    FILE	dangerous_to_remain.wav		373404
    FILE	enough_info.wav		513900
    FILE	functional.wav		237868
    FILE	odd1.wav		553516
    FILE	one_moment.wav		202748
    FILE	operational.wav		772652
    FILE	sorry_dave.wav		791676
    FILE	stop.wav		201356
    
     0 dirs with 10 files of Size 4350904 Bytes
    
    Proc = 0.05 (0.05),  Mem = 0 (0)
    1
    Proc = 6.85 (7.18),  Mem = 1 (4)
    Proc = 5.87 (7.18),  Mem = 1 (4)
    Proc = 0.32 (7.18),  Mem = 1 (4)
    Proc = 0.32 (7.18),  Mem = 1 (4)
    Proc = 5.13 (7.18),  Mem = 1 (4)
    Proc = 0.22 (7.18),  Mem = 1 (4)
    2
    Proc = 0.32 (7.18),  Mem = 1 (4)
    Proc = 0.32 (7.18),  Mem = 1 (4)
    Proc = 6.11 (7.18),  Mem = 1 (4)
    Proc = 5.13 (7.18),  Mem = 1 (4)
    Proc = 0.32 (7.18),  Mem = 1 (4)
    Proc = 0.22 (7.18),  Mem = 1 (4)
    3
    Proc = 0.26 (7.18),  Mem = 1 (4)
    Last edited by mjs513; 10-16-2021 at 12:53 AM. Reason: Updated code

  20. #20
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,392
    Well, the original is here, I think:
    https://github.com/littlefs-project/littlefs/

    It shows version number:
    #define LFS_VERSION 0x00020004 and is >9 month old

    and has:
    Code:
    #ifdef LFS_THREADSAFE
        // Lock the underlying block device. Negative error codes
        // are propogated to the user.
        int (*lock)(const struct lfs_config *c);
    
        // Unlock the underlying block device. Negative error codes
        // are propogated to the user.
        int (*unlock)(const struct lfs_config *c);
    #endif
    So I *assume* it's a bit better - even if there is no way to call these functions with FS.h.
    My lib can't even know that a file is on LittleFS. There is no way to know that.

    TD version shows:
    #define LFS_VERSION 0x00020002
    And is from march 2020.

    Github history shows work on threadsafety.
    (Did not look in detail)


    Speeds:
    I have no idea why it takes 10ms.
    Any hints?
    It does not work for microguy, too

    If you want to see microseconds:
    Code:
    Added QSPI Flash
    8962 us
    8457 us
    8459 us
    If you tell me a way to reduce these times, i'll try it.
    Last edited by Frank B; 10-16-2021 at 07:01 AM.

  21. #21
    Junior Member
    Join Date
    Mar 2020
    Posts
    18
    @mjs513 : Maybe you can try to play the test software for longer than three times because a crash can happen at any time (quickly though).

    I'm sorry as I can't execute the memory access time test during this week-end (no access to my teensy board).

  22. #22
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,392
    Well... tested it with non existing files
    The times match the times which Defragster and MJS posted, then.
    Not that surprising.

    Are you both sure you have used existing files?


    Then, I did a low-level format and copied the files again, via MTP.
    Now, I get:

    Code:
    Added QSPI Flash
    3708 us
    3808 us
    3808 us
    Still 4 milliseconds.
    Any Idea?

    Edit. Oops.. used wrong filenames. So even with non-existing files its 4 millisconds.

    This is the correct test, now:
    Code:
    Added QSPI Flash
    14138 us
    12430 us
    10622 us
    Worse than before low level format.
    This is with NAND.
    Last edited by Frank B; 10-16-2021 at 09:34 AM.

  23. #23
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,392
    Ok, resoldered my faulty board with NOR flash.
    These times look way better:

    Code:
    546 us
    418 us
    593 us
    Can someone confirm, that tha 10x slower times are with NAND only?

  24. #24
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,647
    Quote Originally Posted by Frank B View Post
    Ok, resoldered my faulty board with NOR flash.
    These times look way better:

    Code:
    546 us
    418 us
    593 us
    Can someone confirm, that tha 10x slower times are with NAND only?
    Yes Frank the NAND is slower at least for a W25M02.
    Code:
    Added QSPI NOR Flash (16MB)
    781 micros
    813 micros
    780 micros
    
    Added QSPI NAND Flash (256MB)
    8765 micros
    2937 micros
    7075 micros
    NOTE: These are the same files that I used for my audio test.

    If I use new files as in your example
    Code:
    2838 micros
    2937 micros
    2938 micros

  25. #25
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    7,647
    [QUOTE = Frank B]Well, the original is here, I think:
    https://github.com/littlefs-project/littlefs/

    It shows version number:
    #define LFS_VERSION 0x00020004 and is >9 month old[/QUOTE]

    Yep you are right. The LittleFS base you pointed to in Github has not been updated for awhile. But the Teensy LittleFS is a wrapper for LittleFS that allows using different media (as you know) from a single library. Also its linked to FS.h class that provides the common thread through all the file systems. Does that make sense.

    So yes it can get confusing when referring to LittleFS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •