Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 37 of 37

Thread: SdFat SDIO for Teensy 4.0

  1. #26
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,564
    Quote Originally Posted by defragster View Post
    FAILS write at 150 MHz.
    do you mean CPU clock at 150MHz?

  2. #27
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,918
    Quote Originally Posted by WMXZ View Post
    do you mean CPU clock at 150MHz?
    Yes. Set in the IDE - edited to show F_CPU_ACTUAL in setup {also print __FILE__ so I know what the sketch will do when I type 'Any' char}:
    Code:
    Use a freshly formatted SD for best performance.
    Sketch is :T:\TEMP\arduino_modified_sketch_197682\bench.ino
    	 F_CPU=151200000
    Type any character to start
    FreeStack: 441608
    Type is FAT32
    Card size: 31.91 GB (GB = 1E9 bytes)
    
    Manufacturer ID: 0X3
    OEM ID: SD
    Product: SU32G
    Version: 8.0
    Serial number: 0XAC3E2E1C
    Manufacturing date: 9/2012
    
    error: open failed
    SdError: 0X23,0X1
    Should have presented that as the SdError may be useful - though should repro. Wondering if a CLOCK isn't set right?

    Also fails at 24 MHz - a bit earlier on begin():
    Code:
    Sketch is :T:\TEMP\arduino_modified_sketch_69952\bench.ino
    	 F_CPU=24000000
    Type any character to start
    FreeStack: 441608
    begin() failed
    Do not reformat the SD.
    SdError: 0X17,0X1

  3. #28
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,564
    Quote Originally Posted by defragster View Post
    Yes. Set in the IDE - edited to show F_CPU_ACTUAL in setup {also print __FILE__ so I know what the sketch will do when I type 'Any' char}:
    I ask as I run T4 +AudioCard-uSD (spi) + sdfat-beta at 24 MHz CPU clock without problems (I think)
    so issue may be with SDIO clock generation

  4. #29
    Greiman, with the SdFat-beta library: Is it possible to generate in the serial monitor a list of the files contained in a folder inside any microSD card installed in the Teensy 4?.

    Will you have an example?

    Thank you for making the SdFat library compatible with teensy 4. We have been able to use your library for handling .avi, .jpg, .jpeg files stored on a microSD card connected in SDIO; by a profound modification in the gameduino library 23x.

  5. #30
    Senior Member
    Join Date
    Dec 2013
    Posts
    265
    Will you have an example?
    Here is what I have you can probably modify it to suit your needs.

    Code:
    #include <SdFat.h> // SdFat V "2.0.0"
    
    SdFat SD;
    File m_pSource;
    
    const int DIR_max = 250; // [# of Directory - max]
    const int max_DIR_name_lenght = 255;
    char CURDIRname[max_DIR_name_lenght] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Elements with missing values will be initialized to 0;
    uint32_t DIRcount = 1; // COUNT of all DIRs on SD CARD
    char DIR_list_array[DIR_max][max_DIR_name_lenght]; // [# of DIRs max][max DIR name lenght];
    
    //============================================================================
    //------------                    setup()                        -------------
    //============================================================================
    void setup() {
      // put your setup code here, to run once:
    
      Serial.begin(9600);
      while (!Serial && millis() < 15000) {}  // wait for Serial Monitor with 15sec. timeout.
    
    #if defined(SdFat_h)
      Serial.print( "SdFat version "), Serial.println( SD_FAT_VERSION ), Serial.println("");
    #elif defined(__SD_H__)
      Serial.println( "SD - a slightly more friendly wrapper for sdfatlib"), Serial.println("");
    #endif
    
      if (!SD.begin(SdioConfig(FIFO_SDIO))) { // SdFat.h Ver 2.0.0 Beta only...
        Serial.println("m.SD initialization failed!");
      } else {
        Serial.println("m.SD initialization OK");
      }
    
      LISTDIRs();
    
      m_pSource = SD.open("/"); // ROOT
      PrintFiles(m_pSource);
      m_pSource.close();
    }
    //----------------------------------------------------------------------------
    
    //============================================================================
    //------------                    loop()                        -------------
    //============================================================================
    void loop() {
      // put your main code here, to run repeatedly:
    }
    //----------------------------------------------------------------------------
    
    //============================================================================
    //------------ LIST ALL DIRs ON SD CARD & SAVE IN DIR_list_array -------------
    //============================================================================
    void LISTDIRs() {
      Serial.println("\t**List Directories**");
      m_pSource = SD.open("/"); // ROOT
      char dirname[max_DIR_name_lenght]; // SDFAT // max_DIR_name_lenght
      if (m_pSource.isDirectory()) {
        strcpy(DIR_list_array[DIRcount], "/"); // array
    
        Serial.print("ROOT# ");
        Serial.print(DIRcount);
        Serial.print("\t");
        Serial.println(DIR_list_array[DIRcount]); // SDFAT LIB
        DIRcount++;
      }
      while (true) {
        File DIR = m_pSource.openNextFile();
    
        if (! DIR) {
          // no more files
          Serial.println("\t **no more Directories** ");
          //dir.close();
          break;
        }
        DIR.getName(dirname, sizeof(dirname));
        if (DIR.isDirectory()) {
          //DIRcount++;
          strcpy(DIR_list_array[DIRcount], dirname); // array
          strcat(DIR_list_array[DIRcount], "/");
          Serial.print("DIR# ");
          Serial.print(DIRcount);
          Serial.print("\t");
          Serial.println(DIR_list_array[DIRcount]); // SDFAT LIB
          DIRcount++;
        }
        DIR.close();
      }
      DIRcount --;
      Serial.print("\t **Directory count ");
      Serial.print(DIRcount), Serial.println(" **"), Serial.println();
      m_pSource.close();
    }
    //----------------------------------------------------------------------------
    
    //============================================================================
    // Print Files in Cur. Directory
    //============================================================================
    void PrintFiles(File dir) {
      Serial.println("\t**List Files in Cur. Directory**");
      char filename[max_DIR_name_lenght]; // SDFAT
      while (true) {
    
        File entry = dir.openNextFile();
        if (! entry) {
          // no more files
          Serial.println("\t **no more files**"), Serial.println();
          break;
        }
        entry.getName(filename, sizeof(filename));
    
        if (entry.isDirectory()) {
          //Serial.println(" / ");
          //printDirectory(entry, numTabs + 1);
        } else {
          Serial.print(filename); // SDFAT LIB
          // files have sizes, directories do not
          Serial.print("       \t");
          Serial.println(entry.size(), DEC);
        }
        entry.close();
      }
    }
    //----------------------------------------------------------------------------

  6. #31
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,918
    re: post #27 above { fail at 24 and 150 MHz } - it may be a clock setting issue : pjrc.com/threads/58567-Teensyduino-1-49-Beta-1
    Resolved perhaps in TD 1.49 by release.

  7. #32
    Junior Member
    Join Date
    Jan 2020
    Posts
    1
    Thanks so much to Bill Greiman for this library - SDIO on T3 amazing - before I found it 20Mb/sec read from SD was the stuff of mad man's dreams!

    Do anyone know for sure if this uses SPI when it in SDIO mode or it all handled with bit banging across the four data lines?
    I need to use the SPI bus for shift register filling and need to change speed and data direction (to LSB first).
    I know changing settings may conflict if SPI already in use.

    Thanks

    Dave

  8. #33
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,564
    Quote Originally Posted by Dave_R View Post
    Thanks so much to Bill Greiman for this library - SDIO on T3 amazing - before I found it 20Mb/sec read from SD was the stuff of mad man's dreams!

    Do anyone know for sure if this uses SPI when it in SDIO mode or it all handled with bit banging across the four data lines?
    I need to use the SPI bus for shift register filling and need to change speed and data direction (to LSB first).
    I know changing settings may conflict if SPI already in use.

    Thanks

    Dave
    It uses native SDIO driver of T3.5/6, T4.0 (no SPI or bitbanging)

  9. #34
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,799
    Hi Bill
    In the old SDFat library there was a class called FatFileSystem. In trying to convert some old sketches what would the equivalent be or is there one? Example of challenge:
    Code:
    typedef FatFileSystem vfs_t;
    any pointers would help. Thanks in advance.

  10. #35
    Member
    Join Date
    Oct 2018
    Location
    London
    Posts
    58
    Finally got a T4 to run the bench.ino and TeensySdioDemo.ino using SdFat v2 on a breadboard! Thought I'd post how, for anyone struggling to do the same:

    I used blackketter's board from OSH:

    https://oshpark.com/shared_projects/tZbsjC0v

    The soldering is very delicate and requires preparation of the breakout board to carefully remove all foil flaps around the castellated copper using fine tweesers. This needs to be done with a microscope to ensure that there are no fine fragments shorting to an adjacent hole. It is well worth checking that there is no conductivity between any of the SDIO pins before proceeding any further.
    Click image for larger version. 

Name:	castellation.jpg 
Views:	2 
Size:	119.6 KB 
ID:	19361

    I used solder flux for my first board, but this ran between the breakout and the Teensy boards and increased the conductivity between adjacent pins. This board never worked that well. I could get it to run SD.h examples but none of the SdFat examples.

    For my second attempt, I prepared the surfaces carefully using a flux pen, taking care not use excess. I directly soldered each pin carefully and then checked the resistance between the 3v3 and the pins of interest. They should all be above 1M Ohm.

    I tried connecting to different boards. The Adafruit SD Board worked great with Arduino Uno and Seeeduino Xiao. I see the Xiao being used as a serial data logger in combo with one of the SD breakout boards.

    For the Teensy 4.0, I used the Pololu microSD Breakout and the Waveshare Micro SD Board.
    Click image for larger version. 

Name:	Pololu_Micro_SD_T.png 
Views:	3 
Size:	182.1 KB 
ID:	19362Name:  Pololu_Micro_SD.jpg
Views: 70
Size:  56.3 KBClick image for larger version. 

Name:	Waveshare_Micro_SD.jpg 
Views:	2 
Size:	46.9 KB 
ID:	19358

    For breadboard use, I favoured the Waveshare board with its single row of pins and visible labels (always nice to sanity check you wiring on the board itself). Although, the Pololu board may stack nicely (above the T4) into the female headers of the T4 breakout board.
    Click image for larger version. 

Name:	Sdio_Breadboard.jpg 
Views:	2 
Size:	116.6 KB 
ID:	19359Click image for larger version. 

Name:	sdio_board.jpg 
Views:	3 
Size:	113.8 KB 
ID:	19360

    Next, with the SdFat lib (v2) in the <arduino>/libraries folder, I ran the bench and TeensySdioDemo examples (without modification).

    Code:
    FILE_SIZE_MB = 5
    BUF_SIZE = 512 bytes
    Starting write test, please wait.
    
    write speed and latency
    speed,max,min,avg
    KB/Sec,usec,usec,usec
    10309.28,9846,22,49
    10266.94,9300,22,49
    
    Starting read test, please wait.
    
    read speed and latency
    speed,max,min,avg
    KB/Sec,usec,usec,usec
    22522.52,480,22,22
    22522.52,480,22,22
    The next step will be to build the stackable version...
    Last edited by microderm; 03-14-2020 at 01:15 AM. Reason: typos

  11. #36
    Member
    Join Date
    Oct 2018
    Location
    London
    Posts
    58
    I used the Pololu to build the stackable SD module, placing a 0.1F cap between GND and 3v3.

    Click image for larger version. 

Name:	sd_stack.jpg 
Views:	6 
Size:	150.4 KB 
ID:	19365

    The example TeensySdioDemo.ino works for both SDIO options 1 and 2, but the SPI options 3 and 4 fail:

    Code:
    Type '1' for FIFO SDIO
         '2' for DMA SDIO
         '3' for Dedicated SPI
         '4' for Shared SPI
    Error: begin failed
    SD_CARD_ERROR_CMD0, ErrorData: 0XFF
    I presume the error is because SdFat isn't configured to use SPI over the SDIO pins AND the SD module (Pololu) isn't built to read SPI data.

  12. #37
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,564
    Quote Originally Posted by microderm View Post

    I presume the error is because SdFat isn't configured to use SPI over the SDIO pins AND the SD module (Pololu) isn't built to read SPI data.
    The adapter is capable of both protocols and SdFat uses SPI library, so you have to configure SPI library first before initiating SdFat.
    You are using T4 and I'm not sure if there is a SPI overlaid to SDIO (as it is with T3.6), but reading the PinMux table in the IMXRT1062 documentation you may figure out and adapt SPI to these pins or adapt code.

Posting Permissions

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