chipKIT® Development Platform

Inspired by Arduino™

SD Card Library Println Return Value (Compatability Issue)

Created Fri, 23 Jan 2015 10:21:17 +0000 by ahnise


ahnise

Fri, 23 Jan 2015 10:21:17 +0000

I noticed that when using the SD card driver, the File class println function has no return value. On Arduino this returns the number of characters sent.

  1. This appears to be a compatability issue with Arduino Does it make sense to add a return value to the println function ?
  2. In Arduino, this value is checked to make sure that a transfer occurred, and to detect if there was some issue writing to the SD card (in other words general error checking)
  3. In chipkit, what is the defacto way of checking that a write to the SD card worked ? Is it enough to check the that the file open operation worked correctly ?

majenko

Fri, 23 Jan 2015 10:53:49 +0000

As part of our drive towards an Arduino 1.5.x compatible core things like the Print class have been / are being updated to work the same as Arduino. That includes the return value of println() in the SD card library.

The latest test versions of MPIDE all have the updated Print class in them with the proper return values:

size_t print(const String &);
    size_t print(const char[]);
    size_t print(char);
    size_t print(unsigned char, int = DEC);
    size_t print(int, int = DEC);
    size_t print(unsigned int, int = DEC);
    size_t print(long, int = DEC);
    size_t print(unsigned long, int = DEC);
    size_t print(double, int = 2);
    size_t print(const Printable&);

    size_t println(const String &s);
    size_t println(const char[]);
    size_t println(char);
    size_t println(unsigned char, int = DEC);
    size_t println(int, int = DEC);
    size_t println(unsigned int, int = DEC);
    size_t println(long, int = DEC);
    size_t println(unsigned long, int = DEC);
    size_t println(double, int = 2);
    size_t println(const Printable&);
    size_t println(void);

However, the SD card library doesn't currently do any error checking and just assumes each character wrote correctly.

The SD library is ancient, slow, and a rather rancid pile of something unmentionable. It was the version from 0022 of the Arduino environment which has been "bent" to fit the chipKIT. It's really not very suitable, and I am actually in the process of working on a replacement for it. Eventually there will be multiple options for SD libraries depending on how you work and what facilities you require. One of my tasks is to port the popular SdFat and Fat16Lib libraries from Arduino to chipKIT, as well as writing my own modular Filesystem library to support other filesystems (ext2, NTFS, HFS+, etc) and different backing stores (ramdisk, CF, USB, etc). The latter is a long way off yet though, but SdFat may be sooner.