Get a long list of compile warnings with the SdFat library in Seeeduino Xiao

I’ve been trying to use the SdFat library with the Xiao but I get a bunch a warnings and eventually the program does not work. The SdFat is required since it supports long filenames and is supposed to write to a microSD card connected via SPI. The code is here. This code is tested and works on a regular Arduino Nano. I can’t even see the output on the serial monitor.

The output of the compile is here.

I wonder if I’m missing something in setting it up with PlatformIO. Any help in resolving this would be appreciated. Thanks.

Looks like this is your problem…

C:\Users\xxxx.platformio\packages\framework-arduino-samd-seeed\variants\XIAO_m0/variant.h:219:25: warning: extra tokens at end of #endif directive [-Wendif-labels]
#endif SerialUSB
^~~~~~~~~

Yes true. How do I resolve this? (Other than going and editing all these files manually)

which processor are you using? XIAO SAMD21 i assume
how do you have the SD card connected?

Via SPI. This is how its connected:

SD   >  Xiao
------------
3V3  >  3V3
CS   >  D3
MOSI >  D10
CLK  >  D8
MISO >  D9
GND  >  GND

Also, this is what the platformio.ini looks like:

[env:seeed_xiao]
platform = atmelsam
board = seeed_xiao
framework = arduino
lib_deps = greiman/SdFat@^2.2.2
upload_port = COM6

Blockquote

Warning: Major Reformat of Source in 2.2.2

There are a huge number of changes in 2.2.2 since I decided to use clang-format to force Google style formatting.

I did this to avoid warnings from the static analysis programs Cppcheck and cpplint.

clang-format is aggressive so it may actually cause code to fail. For example clang-format rearranges the order of includes according to the selected style.

Blockquote

Version 2.2.2 of SDfat lib is messed up… roll back to 2.2.0 and it works

That did not work. Here is what I’ve changed now:

Changed the CS pin to D2
Changed the Serial baud to 115200
Changed the SD clock speed to 4MHz via SD_SCK_MHZ(4)
Changed the library version to 2.2.0 and then to Adafruit’s fork of the SDFat 2.2.3

I added a test Serial.println("Hello Xiao!"); but that does not show up on the monitor.

EDIT:

I wrote a simple Hello Xiao program to test the serial and that did not show anything on the serial terminal. I still get the same set of warnings when compiling the project.

Ignore my previous comment. I think I have this figured out. I read the documentation listed here. I tried the code listed here with the SD library and everything worked! Also using the Arduino fork of the SdFat library.

I then used the same serial and SD init code with my version and it worked!

I think by default the CS pin is D4.

However, this can be changed to whatever you like in the code. I believe the reference code waits for serial to initialize. Though I cannot figure out why my SD init code did not work earlier but works now.

My version of the working code is below:

#include <Arduino.h>
#include <SPI.h>
#include <SdFat.h>

#define SD_CS_PIN 2
#define LEDPIN 4
#define SERIALBAUD 9600

SdFat SD;
File dataFile;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(SERIALBAUD);
  while (!Serial)
  {
    ;
  }

  Serial.println("Hello Xiao!");

  Serial.print("Initializing SD card...");

  if (!SD.begin(SD_CS_PIN))
  {
    Serial.println(" failed!");
    while (1)
    {
      ;
    }
  }
  else
  {
    Serial.println(" done!");
  }

  String fileName;

  fileName = "GPSData_";
  fileName += String("19");
  fileName += String("01");
  fileName += String("2024");
  fileName += String("_");
  fileName += String("10");
  fileName += String("45");
  fileName += String("00");
  fileName += String(".kml");

  Serial.print("File name is: ");
  Serial.println(fileName);

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  // (O_READ | O_WRITE | O_CREAT) erases any previous content and then writes.
  // FILE_WRITE is (O_RDWR | O_CREAT | O_AT_END)
  dataFile = SD.open(fileName, FILE_WRITE);

  // if the file opened okay, write to it:
  if (dataFile)
  {
    Serial.print("Writing to file...");

    dataFile.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    dataFile.println("<kml xmlns=\"http://www.opengis.net/kml/2.2\">");
    dataFile.println("");
    dataFile.println("  <Document>");
    dataFile.println("    <name>Views with Time</name>");
    dataFile.println("    <open>1</open>");
    dataFile.println("    <description>");
    dataFile.println("      In Google Earth 20, enable historical imagery and sunlight,");
    dataFile.println("      then click on each placemark to fly to that point in time.");
    dataFile.println("    </description>");
    dataFile.println("");
    dataFile.println("    <Placemark>");
    dataFile.println("      <name>Sutro Baths in 1946</name>");
    dataFile.println("      <gx:TimeStamp>");
    dataFile.println("        <when>1946-07-29T05:00:00-08:00</when>");
    dataFile.println("      </gx:TimeStamp>");
    dataFile.println("      <longitude>-122.518172</longitude>");
    dataFile.println("      <latitude>37.778036</latitude>");
    dataFile.println("      <altitude>221.0</altitude>");
    dataFile.println("    </Placemark>");
    dataFile.println("");
    dataFile.println("  </Document>");
    dataFile.println("</kml>");

    dataFile.close();
    Serial.println(" done!");
  }
  else
  {
    // if the file didn't open, print an error:
    Serial.println("Error opening file for writing!!");
  }

  // re-open the file for reading:
  Serial.print("\n\nReading from file: ");
  Serial.println(fileName);
  Serial.println("");

  dataFile = SD.open(fileName, FILE_READ);
  if (dataFile)
  {
    // read from the file until there's nothing else in it:
    while (dataFile.available())
    {
      Serial.write(dataFile.read());
    }
    // close the file:
    dataFile.close();
    Serial.println("\n File read!");
  }
  else
  {
    // if the file didn't open, print an error:
    Serial.println("Error opening file for reading!!");
  }

  // Close the serial port
  Serial.end();
}

void loop()
{
  // nothing happens after setup
}

Hi there,
FWIW , I was able to compile the original post as is C&P in arduino IDE.
No errors SO .
:wink:

Linking everything together...
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\arm-none-eabi-gcc\\7-2017q4/bin/arm-none-eabi-g++" "-LC:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10" -Os -Wl,--gc-sections -save-temps "-TC:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\hardware\\samd\\1.8.5\\variants\\XIAO_m0/linker_scripts/gcc/flash_with_bootloader.ld" "-Wl,-Map,C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10/sketch_jan19a.ino.map" --specs=nano.specs --specs=nosys.specs -mcpu=cortex-m0plus -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -u _printf_float -u _scanf_float -Wl,--wrap,_write -u __wrap__write -o "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10/sketch_jan19a.ino.elf" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\sketch\\sketch_jan19a.ino.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SPI\\SPI.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\Adafruit_ZeroDMA\\Adafruit_ZeroDMA.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\ExFatLib\\ExFatDbg.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\ExFatLib\\ExFatFile.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\ExFatLib\\ExFatFilePrint.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\ExFatLib\\ExFatFileWrite.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\ExFatLib\\ExFatFormatter.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\ExFatLib\\ExFatName.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\ExFatLib\\ExFatPartition.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\ExFatLib\\ExFatVolume.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FatLib\\FatDbg.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FatLib\\FatFile.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FatLib\\FatFileLFN.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FatLib\\FatFilePrint.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FatLib\\FatFileSFN.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FatLib\\FatFormatter.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FatLib\\FatName.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FatLib\\FatPartition.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FatLib\\FatVolume.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FreeStack.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FsLib\\FsFile.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FsLib\\FsNew.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\FsLib\\FsVolume.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\MinimumSerial.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\SdCard\\SdCardInfo.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\SdCard\\SdSpiCard.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\SdCard\\SdioTeensy.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\SpiDriver\\SdSpiArtemis.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\SpiDriver\\SdSpiChipSelect.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\SpiDriver\\SdSpiDue.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\SpiDriver\\SdSpiESP.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\SpiDriver\\SdSpiParticle.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\SpiDriver\\SdSpiSTM32.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\SpiDriver\\SdSpiSTM32Core.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\SpiDriver\\SdSpiTeensy3.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\common\\FmtNumber.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\common\\FsCache.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\common\\FsDateTime.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\common\\FsName.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\common\\FsStructs.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\common\\FsUtf.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\common\\PrintBasic.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\common\\upcase.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\iostream\\StdioStream.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\iostream\\StreamBaseClass.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\iostream\\istream.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\libraries\\SdFat_-_Adafruit_Fork\\iostream\\ostream.cpp.o" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10\\core\\variant.cpp.o" -Wl,--start-group "-LC:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\CMSIS\\5.7.0/CMSIS/DSP/Lib/GCC/" -larm_cortexM0l_math -lm "-LC:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\hardware\\samd\\1.8.5\\variants\\XIAO_m0" -lm "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10/core\\core.a" -Wl,--end-group
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\arm-none-eabi-gcc\\7-2017q4/bin/arm-none-eabi-objcopy" -O binary "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10/sketch_jan19a.ino.elf" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10/sketch_jan19a.ino.bin"
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\arm-none-eabi-gcc\\7-2017q4/bin/arm-none-eabi-objcopy" -O ihex -R .eeprom "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10/sketch_jan19a.ino.elf" "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10/sketch_jan19a.ino.hex"
open C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5\bootloaders\XIAOM0\bootloader-XIAO_m0-v3.7.0-33-g90ff611-dirty.hex: The system cannot find the file specified.

Using library SPI at version 1.0 in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5\libraries\SPI 
Using library Adafruit Zero DMA Library at version 1.0.4 in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5\libraries\Adafruit_ZeroDMA 
Using library SdFat - Adafruit Fork at version 2.2.3 in folder: D:\Arduino_projects\libraries\SdFat_-_Adafruit_Fork 
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\arm-none-eabi-gcc\\7-2017q4/bin/arm-none-eabi-size" -A "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\68F83E4DFA09423467A368F745A35A10/sketch_jan19a.ino.elf"
Sketch uses 48624 bytes (18%) of program storage space. Maximum is 262144 bytes.

HTH
GL :slight_smile: PJ

Same here too. It does not show errors, but it didn’t work as well. The warnings are shown only in PlatformIO.

Hmm,
What BSP are you using in Arduino?
GL :slight_smile: PJ

Glad you got it though. :+1:

Too many acronyms in this post which I’m too old to understand :slight_smile:

1 Like

LOL, Nah’ , Your never too OLD! :smiley: :v:
The Board Support Package (what chip do you select in the Arduino IDE)
HopeThatHelps
GL :slight_smile: PJ :+1:

Yes you have to be a true monkey wrench to understand him… send him a bag of peanuts…lol

Hahaha :slight_smile:

I did not use the Arduino IDE. I used PlatformIO in VS Code. Within that, I used the Atmel SAMD package and selected the board as Seeeduino Xiao.

Hurling one at him right now :grin: