SD Card library status

I’ve lost latest updated on SD card development.
Right now what is the option avaiable to acces SD card?
PetitFatFS vs SDFileSystem vs TheUltimateSDLibrary™?

Forum is full of information but all scattered around, and mixed by issues and different timeline.

Practically I needs to write about 18k to the SD card without critical speed.
As bonus I’d like to keep the same code for pokitto sim and hardware as close as possible.

If you need to create/delete/resize at runtime files - SDFileSystem

If you can use storage files of fixed size - PetitFatFS

1 Like

I’ll take that!

I’m looking at the Example “SDCardIO” and I’m in doubt about the different path used beetween SIM and HW .
Also what is the “sd” mount point in the path?

You can mount more than one SD card at the same time with that library, so you need to give it an identifier.

1 Like

I’d really like to write this eventually.

Preferably something a bit like a stripped down std::FILE,
but less pointers, more RAII and more member functions,
and a few filesystem-like features.
Focusing only on moving bytes and files around, leaving character encoding to another library.

E.g. something like:

namespace FileSystem
{
	enum class FileError
	{
		None,
		FileNotFound,
		// ... etc
	};

	class FileWriter
	{
	private:
		// Constructor TBC
	
	public:
		~FileWriter();
	
	public:
		bool isOpen() const;
		bool isEndOfFile() const;

		bool hasError() const;
		FileError getError() const;

		bool writeByte(char data);

		template<std::size_t size>
		std::size_t writeBytes(const char (&data)[size]);
	};

	class FileReader
	{	
	private:
		// Constructor TBC
	
	public:
		~FileReader();
	
	public:
		bool isOpen() const;
		bool isEndOfFile() const;

		bool hasError() const;
		FileError getError() const;

		bool readByte(char & data);

		template<std::size_t size>
		std::size_t readBytes(char (&data)[size]);
	};

	template<std::size_t size>
	File openFile(const char (&path)[size]);

	template<std::size_t size>
	bool fileExists(const char (&path)[size]);

	template<std::size_t size>
	bool deleteFile(const char (&path)[size]);
	
	enum class FileCreateStatus
	{
		Success,
		FileAlreadyExists,
		NotEnoughSpaceOnDisk,
		// ... etc
	};

	template<std::size_t size>
	FileCreateStatus createFile(const char (&path)[size]);
	
	enum class FileMoveStatus
	{
		Success,
		SourceFileNotFound,
		DestinationFileAlreadyExists,
		NotEnoughSpaceOnDisk,
		// ... etc
	};

	template<std::size_t sourceSize, std::size_t destinationSize>
	FileMoveStatus moveFile(const char (&sourcePath)[sourceSize], const char (&destinationPath)[size]);

	template<std::size_t sourceSize, std::size_t destinationSize>
	FileMoveStatus moveFile(const char (&sourcePath)[sourceSize], const char (&destinationPath)[size], bool overwrite);
}

And it would be moveable, but not copyable,
and the file would close when the destructor is called,
so you can just let the file fall out of scope.

Or maybe the reading API and the writing API would be split into FileReader and FileWriter?
Actually yes, separate APIs for reading and writing is probably better to start with.
Mixing reading and writing can cause big headaches.

1 Like