tinygo-org / drivers

TinyGo drivers for sensors, displays, wireless adaptors, and other devices that use I2C, SPI, GPIO, ADC, and UART interfaces.
https://tinygo.org
BSD 3-Clause "New" or "Revised" License
609 stars 193 forks source link

SPI Flash driver #45

Closed deadprogram closed 2 years ago

deadprogram commented 5 years ago

I'd like to have a driver for SPI flash drives similar to what https://github.com/adafruit/Adafruit_SPIFlash can do. Ideally, it would also support the CircuitPython extensions to the file system for when those are in use.

aykevl commented 5 years ago

That would be useful. When defining such a driver, think of these things:

bgould commented 5 years ago

FYI I'm making decent progress with this... I'm able to access the "internal" SPI flash on the Itsy Bitsy M0 and have implemented functions for doing low level IO operations on the block device. Also I've forked https://github.com/mitchellh/go-fs and with a few tweaks have been able to use that start implementing functionality to read from a FAT filesystem.

@deadprogram I was wondering if you could please clarify what functionality you mean by "the CircuitPython extensions to the file system for when those are in use" - can you point me to any documentation on what those extensions do so that I can think about making accomodations for that as I am working?

deadprogram commented 5 years ago

Great news about your progress!

I was looking and seems like the FAT filesystem used is now standardized? There appears to have been some MBR hacks previously, but looks like they were removed from the Adafruit code.

bgould commented 4 years ago

Updates:

Of the two, LittleFS is more full-featured and is recommended for use with SPI flash, as it is far superior with respect to resiliency and wear leveling.

The FAT implementation is currently read-only, but is useful for the following scenarios for instance:

I do eventually intend to make the FAT library be read-write, but for the library I used to be effective on SPI NOR flash it will require a caching layer that is not implemented yet. Also if read-write is really necessary, LittleFS is superior in all circumstances except for when it comes to compatibility with a host system (and even in that case, there is a littlefs FUSE module can possibly be utilized).

I will work on preparing documentation on how to wire everything together into a usable setup.

bgould commented 4 years ago

One thing to add... both of the filesystem implementations I mentioned above are designed to be as close as possible to the os package, and both are easy to integrate with https://github.com/tinygo-org/tinygo/pull/1012 if/when that gets included in TinyGo.