Problems with (external) library using SDFat

Nanoprecision

Active member
Dear all,

I try to get the "sd-config-file" library up&runing on my T4.1:

This lib includes the "SDFat" library.
I'm using an example as provided within the lib (ReadWrite_ConfigFile.ino).
The sketch compiles if I add "#include <SD.h>", but the methods of the lib cannot access the SD-Card.

I've borrowed some code from the example "SDFat_Usage.ino" provided with TeensyDuino, which can
initialize the SD-Card, but still the methods from the "sd-config-file" lib cannot access the SD-Card.


Any hint what to change/implement/include/omit to be able to use the "sd-config-file" lib?

Thanks so much,
Tom


BTW:
Arduino IDE 2.3.6
Windows 11
Teensy 4.1
all libs are up-to-date




C++:
/**
 * SdConfigFile Library Example Sketch
 *
 * This example sketch shows how to read parameters from and write new
 * values to an SD Card Configuration File using the SdConfigFile library
 *
 * SdConfigFile <https://github.com/chillibasket/sd-config-file>
 * created:      25th January 2022
 * last updated: 27th February 2022
 * Copyright (C) 2022 by Simon Bluett
 *
 * Released in the public domain under the MIT license
 *
 * This example sketch requires the SdFat library to be installed:
 * SdFat <https://github.com/greiman/SdFat>
 */


/**
 * By default, the SdConfigFile library supports FAT16 and FAT32
 * SD card file system types. However, EXFAT support can also be
 * enabled by using one of the two "#defines" below. Note that
 * support for the EXFAT file system takes up more memory.
 *
 * SD_CONFIG_FILE_USE_EXFAT: support only EXFAT SD Cards
 * SD_CONFIG_FILE_USE_FSFAT: support both FAT16/32 and EXFAT SD Cards
 * default: FAT16 and FAT32 support only
 *
 * Uncomment the line below depending on your requirements:
 */
//#define SD_CONFIG_FILE_USE_EXFAT
//#define SD_CONFIG_FILE_USE_FSFAT


/**
 * Include the Sd config file library
 */
#include <SD.h>
#include <SdConfigFile.h>


/**
 * Instantiate Sd config file object, passing
 * the chip select pin number as a variable
 */
SdConfigFile configFile(BUILTIN_SDCARD);


/**
 * Name of the configuration file to open
 */
String configFileName = "test_file.txt";
char configFileName2[] = "test_file2.txt";


// Define some variables which we will set using the
// values from the SD card configuration file
int intValue = 0;

/**
 * Setup function
 */
void setup() {

    bool ok;
  // int chipSelect = 10; // only for SPI, can't use BUILTIN_SDCARD here

    // Start serial comms and wait for user to open the serial monitor
    Serial.begin(115200);
    while(!Serial);
    delay(1000);

  // ok = SD.sdfs.begin(SdioConfig(DMA_SDIO));
    ok = SD.begin(BUILTIN_SDCARD);

  if (!ok) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  Serial.println();

///  code runs up to here

    // Use the "read" method and supply the directory and file name
    while (configFile.read(configFileName))
    {
        configFile.get("IntValue", intValue);
    }
    Serial.print("IntValue: "); Serial.println(intValue);
}


void loop() {
    // Empty!
}
 
I haven't tried this library, but here are two things to check.

First, for Teensy, you must use the version of SdFat that is installed with the Teensy board support package. You may also have the standard version of SdFat in your Arduino libraries, and if so, that version may get used instead of the Teensy version. Check your build output for messages about "duplicate libraries". That should tell you whether you have two version of SdFat, and if so, which one is being used.

Second, it's possible this library has not been updated since updates were made to SdFat. I looked at the source, though, and it doesn't seem to be doing anything fancy, so my gut feeling is the first issue.

Let us know what you find.
 
Hello,

thanks for your tips.

ok, I can answer my own question:
the SDConfigFile library implements an sd.begin(chipSelect).
This is of course failing when trying to call with BUILTIN_SDCARD.

*My* solution:
delete sd.begin() in the library and use a working sd.begin() in the main program.

There is definitely a better solution possible, but that‘s beyond my skills.
 
Update:

there seems to be more than just this issue.
Now the Teensy enters an endless reboot loop when tryint to write to the DS-Card...
let's see.
 
as @joepasquariello indicated you must use the Teensyduino version of SdFat as it differs slightly from official version. As these mods are only a few, you may edit the chillibasket version to line up with the Teensyduino version (I have done this in the past myself). Maybe deleting physically the SdFat from chillibasket library could work, as Arduino may then find and use the right version.
 
Hi,
I am using the built-in version of SDFat form Teensyduino; no other SDFat lib is installed.

I've now spent a couple of hours to get the lib up&running, but no success.
Instead of trying to fix things I don't understand, I'll try a different lib, though it is much less elegant.
 
@Nanoprecision - I went through the library and found that it is using an older version of SdFat. I am almost finished updating the library to use the current versions of SD and SdFat in TD1.60B5. It is in a partially working state. The SD/Sdfat rename function has totally changed. I probably won't have time to finish for a couple of day's. But I think the library will work. It was originally written for the T3.6 in ~2022...
 
@Nanoprecision - I went through the library and found that it is using an older version of SdFat. I am almost finished updating the library to use the current versions of SD and SdFat in TD1.60B5. It is in a partially working state. The SD/Sdfat rename function has totally changed. I probably won't have time to finish for a couple of day's. But I think the library will work. It was originally written for the T3.6 in ~2022...
What version of TeensyDuino are you using?
 
Dear all,
@Nanoprecision - I went through the library and found that it is using an older version of SdFat. I am almost finished updating the library to use the current versions of SD and SdFat in TD1.60B5. It is in a partially working state. The SD/Sdfat rename function has totally changed. I probably won't have time to finish for a couple of day's. But I think the library will work. It was originally written for the T3.6 in ~2022...

@wwatson : awesome! That's so much appreciated!
I am using Teensyduino 1.5.9.

It is not that urgent, I can and will wait :)

Tom
 
@Nanoprecision - I went through the library and found that it is using an older version of SdFat. I am almost finished updating the library to use the current versions of SD and SdFat in TD1.60B5. It is in a partially working state. The SD/Sdfat rename function has totally changed. I probably won't have time to finish for a couple of day's. But I think the library will work. It was originally written for the T3.6 in ~2022...
Nice. Just tried it myself and was getting a ton of errors. Glad you are making progress on it.
 
Dear all,


@wwatson : awesome! That's so much appreciated!
I am using Teensyduino 1.5.9.

It is not that urgent, I can and will wait :)

Tom
If you are using Teensyduino 1.59, I suggest you use the SdFat (and SD) library from that release. Certain files are different in SdFat and SD (from 1.60b5 release).
 
Nice. Just tried it myself and was getting a ton of errors. Glad you are making progress on it.
@mjs513 - Thanks, I still don't fully understand the authors program yet but I do see that the major source of errors were coming from incompatible function calls to the currrent SD and SdFat library. So it was necessary to upgrade them :D
 
@mjs513 - Thanks, I still don't fully understand the authors program yet but I do see that the major source of errors were coming from incompatible function calls to the currrent SD and SdFat library. So it was necessary to upgrade them :D
I have a general idea of what he is trying to do but it seems like its a bit convoluted. I keep getting stuck on this error
Code:
error: 'BUILTIN_SDCARD' was not declared in this scope
   45 | SdConfigFile configFile(BUILTIN_SDCARD);
      |                         ^~~~~~~~~~~~~~
 
@mjs513 - If I remember correctly "SD.h" is not included in the library. Only "SdFat.h". Also their are two more instances of "begin()" in the sd_config.cpp file that need to be commented out. Sorry this took so long to reply😀 I don't do so well typing on a cell phone. I should be home later today...
 
@mjs513 - If I remember correctly "SD.h" is not included in the library. Only "SdFat.h". Also their are two more instances of "begin()" in the sd_config.cpp file that need to be commented out. Sorry this took so long to reply😀 I don't do so well typing on a cell phone. I should be home later today...
SD.h IS included in the SD Library, at least in TD 1.60b5.

Are you ALL sure that you are NOT mixing up releases ( 1.59/1.60b5 ) of the SD and SdFat drivers with different releases of Teensyduino?
I don't know whether there is a conflict but there could be.
 
SD.h IS included in the SD Library, at least in TD 1.60b5.

Are you ALL sure that you are NOT mixing up releases ( 1.59/1.60b5 ) of the SD and SdFat drivers with different releases of Teensyduino?
I don't know whether there is a conflict but there could be.
I was not talking about SD.h being included in the SD library. It was not included in sd_config library. Also, TD 1.59 does work as well as TD 1.6.0B5. No observed conflicts yet;)
 
I'm back now. I forked a copy of "sd-config-file" and created another branch on it that I can upload what I have done so far if anybody wants to play with it. I'll do that tomorrow. Right now time to eat and sleep🍗 I do know that there are other bugs besides the SD ones...
 
File inherits Stream, so can't you use File::readBytesUntil() with a terminator argument of '\n'?
 
File inherits Stream, so can't you use File::readBytesUntil() with a terminator argument of '\n'?
The correct way to do this is to add it to SD library which means also updating FS.h in the core - havent played with it in such a long time not sure I remember :)

To be honest probably the way to go.
 
The correct way to do this is to add it to SD library which means also updating FS.h in the core - havent played with it in such a long time not sure I remember :)
I disagree, because fgets is a formatted I/O function provided by libc. Formatted I/O sits on top of low-level functions like read(), write(), etc. that take file descriptor arguments, which is the level of functionality the abstract File class should be aimed at.
 
I disagree, because fgets is a formatted I/O function provided by libc. Formatted I/O sits on top of low-level functions like read(), write(), etc. that take file descriptor arguments, which is the level of functionality the abstract File class should be aimed at.
Actually in terms of SdFat its actually a function embedded in the library:
C++:
int ExFatFile::fgets(char* str, int num, const char* delim) {
  char ch;
  int n = 0;
  int r = -1;
  while ((n + 1) < num && (r = read(&ch, 1)) == 1) {
    // delete CR
    if (ch == '\r') {
      continue;
    }
    str[n++] = ch;
    if (!delim) {
      if (ch == '\n') {
        break;
      }
    } else {
      if (strchr(delim, ch)) {
        break;
      }
    }
  }
  if (r < 0) {
    // read error
    return -1;
  }
  str[n] = '\0';
  return n;
}

The same function exits for Fat and fat32.

So all I am doing it adding the reference to the SD library to use the function in SdFat
 
Back
Top