Overview
- Object ID : 5048 (2026-04-25 03:04:45)
- Author : evanh
- Content : Code
- Microcontroller : Propeller 2
- Language : Generic
- Category : Data Storage
- Licence : MIT
- Tags : FAT16, FAT32, Filesystem, FlexProp, SD card
Content
4-bit SD mode SD card driver plug-in to Flexspin's FAT filesystem layer.
Can be used with Spin2, Basic, C and any languages supported by the Flexspin compiler. Propeller 2 only.
Highest performance is typically when the buffer size matches the FAT cluster size. Writes can easily exceed 10 MB/s on fast cards, and reads 20 MB/s. There is also the option of disabling block read CRC processing to allow reads at sysclock/2. Default is sysclock/4.
Requires Flexspin compiler version 7.0.0 or later. The example tester uses the newly added _vfs_open_fat_handle() API, replacing the older preset list of vfs device open functions. The driver itself uses newly added features around "inline" assembly.
Requires a 4-bit wired SD slot. Main restriction is the four DAT pins have to be in-order on 4-bit pin boundary. Pull-ups are also recommended. Example can be found here - https://forums.parallax.com/discussion/174988/new-sd-mode-p2-accessory-board/p1
I made a basic 4-bit SD slot, without power switch nor LED, by hand wiring a pillaged SD slot - https://forums.parallax.com/discussion/comment/1563018/#Comment_1563018
As of v1.14, the drawing and photo of the hand wired adapter are included in the zip file.
Also included is two other drivers, using 1-bit SPI mode. One is just a copy of Flexspin's built-in sdmm.cc driver repackaged to be a plugin. The other is rehash of the same that plainly bit-bashes the SPI instead of using any smartpins.
There is two example programs that demonstrate mounting and use of the drivers as plugins. You'll need to dig around them to eke out the details. They are defaulted to using 1-bit SPI mode driver and the boot slot pin-out.
As of v1.14, there is now four example programs. And they default to 4-bit SD mode now.
17 Feb 2025: v1.0 release
26 Feb 2025: v1.1, bug fix to support multi-card use - Convert DMA parameter structs to non-static
20 Apr 2025: v1.2, bug fix for sharing amongst cogs - Ensure DIR/OUT, for used pins, finish as set low
26 Apr 2025: v1.3, rework disk_read()/disk_write() to implement lazy CMD12 for sequential performance
30 Apr 2025: v1.4, some size optimising, remove legacy driver interface, bug fix SETSE1 for lazy CMD12
18 May 2025: v1.5, now supports Flexspin's optional FF_USE_TRIM compile switch - Effective when SD card supports erase-discard
26 July 2025: v1.6, fixed a harmless typo that appeared in v1.4: unconditional ROLBYTE instruction in tx block CRC calc
11 Sept 2025: v1.7, changed power down error into just a warning and removed the subsequent excessive power up check
12 Oct 2025: v1.8, merged the command and the response phases into one assembly routine
19 Oct 2025: v1.9, compacted the rxlag calibrate routine to save a little space, uses a much smaller stack buffer too
24 Oct 2025: v1.10, compacted set*set() functions - Compiles to 788 bytes smaller than v1.3. But still 5364 bytes above sdmm.cc
27 Oct 2025: v1.11, merged block read and write routines. Another 364 bytes smaller
3 Nov 2025: v1.12, fixed lazy CMD12 response handling, also improved lazy state tracking - Bad from v1.3
fixed idiot regression, as of v1.8, (Nwr = 2) minimum card-busy turnaround with multi-block writes
16 Nov 2025: v1.13, change ioctl() commands to exchange old value with new value - Both GET and SET in one
24 Apr 2026: v1.14, provide compile options to remove features: power switch control (312 bytes), and lazy CMD12 (208 bytes)