-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFD - SD Card support #1321
Comments
For what it's worth, here's what would be my usage:
|
Large card sizes are a must. It would be nice to have an API that was compatible with the SPIFFS API (or at least a way to build a compatible API). |
I've been working on a prototype during the last days and have basic SD access in place now. While incrementally adding FAT file system functions I get a better view on the Lua API thus it's time for an update and call for feedback. SPI layerThe user is supposed to initialize SPI upfront. This allows some degree of freedom regarding the system configuration:
SD card accessThe SD card is identified by its SS/CS pin and can theoretically coexist with other slaves on the same bus. The driver will temporarily reduce SPI clock to 400 kHz during card initialization and switches back to the user configuration. File system layerThis is based on ChaN's FatFS R0.12 code. I see the possibility to have a moderate hierarchical object design while addressing a file or folder is done in a flat way with paths across volumes and directories. This feels more like the traditional approach and avoids artificial mappings between an object tree and FatFS' path definition.
Volume object
Directory object
File object
Info object
BTW I'm developing this on a Wemos D1 Mini with Micro SD shield - perfect match 😉. |
Would it make sense to try to mimic the Lua api a bit closer? What I mean is:
If not, it's ok, I don't think this is a big deal. It's just that I think it's best to stick to standards where possible :) |
Thanks for the feedback @devyte.
Ok
Ok
I don't see a way atm to influence FatFS' buffering strategy.
unlink() -> rename() is a good point. It's also in line with the spiffs module. I've updated my previous post accordingly. |
FAT stores modification time in year/month/day etc. format. Support for correct timestamps requires date&time info to be broken down into these components. |
Pushed a first version to my fatfs branch. Some more clean-up and testing required. |
You say "(potentially) dependent modules" and I say #386 😉 |
The filesystem functions can hit a couple of blocking points and will report these as result codes to the Lua wrapper. This information is currently propagated to Lua land and the script is responsible for any error detection. Eg. Is there a preferred way how to report these errors? |
I read somewhere about Lua
Returning To me it also depends on whether there's some kind of "does-file-exist" function available. If clients have the chance to check for a file's existence prior to opening it it may be ok to throw an error if they don't and the file is missing indeed. If clients have no chance to verify first it'd be a bit "unfair" to throw an error. |
@marcelstoer I agree with you, but this applies only to single-threaded environments. The result of the test may be invalid immediately after the call. |
Yes, and even then there's no 100% guarantee although for all practical purposes it can be assumed. |
Thanks for the feedback. |
The more this module evolves, the more I get the impression that the whole file system topic should be more generic. The separation between FAT SD cards and SPIFFS flash is something which feels more and more like a suboptimal approach.
The |
@devsaurus |
Thanks Arnim for the well thought-out plan 👍. However, just as Erik I also think that "Unified File System" is not the correct term. You're a bstracting, g eneralizing or v irtualizing the file system. |
Thanks @eku and @marcelstoer. |
I've been contemplating this aspect a while now - it just feels wrong from whatever point of view. A better approach IMO is to incrementally enhance the
The term flat API refers to the module functions that restrict Lua land to 1 open file at a time:
Steps 1.-4. keep full backwards compatibility (with single-file restriction for both spiffs and fatfs). While 3. adds API methods that enable multiple open files and directory handling. |
I'm currently looking into the bits and pieces that are needed to add support for SD Cards to the NodemMCU firmware. Even though that the topic is quite clear, I'd like to understand the requirements of potential use cases a bit better before starting with code. So please feel free to feed back to my specific questions or update the topic with additional items.
Low level driver
This will be based on SPI mode as I don't feel like venturing into SD protocol topics on undocumented hardware. It's a drawback performance-wise but common use in the Arduino world. A good start for a driver code is SdFat which implements all SD related functions in one file, supporting
Reading and writing raw blocks of the card could be exposed as Lua API, but I don't see a need for that at the moment. Is there any interest in accessing the card without a file system?
File system
Most prominent will be support for FAT16/FAT32 since it allows for simple data exchange with PCs. There appear to be different shades of FAT support available, trading in memory consumption for features. Thus the most interesting items for selecting an fs implementation are lurking here. How important are the following aspects for your use case?
gets()
/puts()
like API on top of chunk based operationsFatFs would cover all the items mentioned above but I'm open for other proposals.
What about other file systems like ext2/3/4?
The text was updated successfully, but these errors were encountered: