P2 DUAL uSD FAT32 and FLASH Filesystem (spin2/pasm2)
Stephen Moraco
Posts: 457
New P2 Dual Filesystem Driver — SD FAT32 + Flash in One Cog
Version 1.0.0
This is the first public release of a unified dual-filesystem driver for the P2 Edge Module. It gives you simultaneous access to both the onboard 16 MB Flash chip and a microSD card through a single worker cog and a single API — every file operation takes a device parameter, so you can read, write, and copy across both devices seamlessly.
Incorporates P2 uSD FAT32 FS v1.3.1 and P2 FLASH FS v2.0.0
What's in the box
- Unified Driver (dual_sd_fat32_flash_fs.spin2) — SD FAT32 and Flash filesystems managed by one dedicated cog with automatic SPI bus switching, hardware lock serialization, 6 simultaneous file/directory handles (configurable), 3 of which can be flash files (configurable), per-cog working directories, and cross-device copyFile() / moveFile()
- 7 Utilities — SD and Flash format, audit, and fsck (with auto-repair for SD), plus an SD card characterizer for benchmarking and card identification
- Demo Shell — Interactive dual-device terminal with sd/fl device switching, dir, cd, type, hexdump, copy, format, fsck, audit, bench, and more
- 4 Example Programs — Basic read/write, cross-device copy, data logger, and SD manifest reader copy to flash
- Full Documentation
Testing: 1,308 regression tests across 29 suites (SD, Flash, cross-device, dual-device, multi-cog), all validated on P2 hardware.
Known limitations:
- 8.3 filenames only (no LFN)
- SPI mode only, 25 MHz maximum
Compiles with pnut/pnut-ts.
Set up to compile with FlexSpin and Spin Tools IDE, but needs testing.
(Working through issues with FlexSpin; watch for a point release shortly.)
Hardware: P2 Edge Modules P2-EC and P2-EC32MB (both have built-in microSD socket and onboard 16 MB Flash chip).
Need only one device? Standalone alternatives produce smaller binaries: P2 FLASH FS and P2 uSD FAT32 FS.
Visit the Repo for full documentation, including a driver tutorial, theory of operations, and utilities guide.
The release package can be downloaded from the Release page as dual-fs-driver-{version}.zip.
If you find issues, please file them at the Issues.
Enjoy!
Stephen

Comments
This sounds great! Thanks.
Is this flash file system compatible with the one Chip made?
Yes, it is the very same as the release in my repo quite a while ago. (links in the announcement post to the repo's)
NEWS
I just released v1.1.0 - Incorporates P2 uSD FAT32 FS v1.3.2 and P2 FLASH FS v2.0.0
Here's what's new/fixed:
Hardware: P2 Edge Modules P2-EC and P2-EC32MB (both have built-in microSD socket and onboard 16 MB Flash chip).
Need only one device? Standalone alternatives produce smaller binaries: P2 FLASH FS and P2 uSD FAT32 FS.
Visit the Repo for full documentation, including a driver tutorial, theory of operations, and utilities guide.
The release package can be downloaded from the Release page as dual-fs-driver-{version}.zip.
If you find issues, please file them at the Issues.
Enjoy!
Stephen
So flexprop has at least two different flash drivers, one based on Chip’s code.
If this is still compatible, would be very nice. Could use the shell.c example to copy files from flash to/from PC over plan9 already…
Pc to usd should already work too.
Guess flash to usd might also work…
NEWS
I just released v1.2.0 - Incorporates P2 uSD FAT32 FS v1.4.0 and P2 FLASH FS v2.0.0
Here's what's new/fixed:
Hardware: P2 Edge Modules P2-EC and P2-EC32MB (both have built-in microSD socket and onboard 16 MB Flash chip).
Need only one device? Standalone alternatives produce smaller binaries: P2 FLASH FS and P2 uSD FAT32 FS.
Visit the Repo for full documentation, including a driver tutorial, theory of operations, and utilities guide.
The release package can be downloaded from the Release page as dual-fs-driver-{version}.zip.
If you find issues, please file them at the Issues.
Enjoy!
Stephen
@"Stephen Moraco" I'm testing it out now on a new board...
First thing I see in shell demo is this:
CLK_FREQ = 350_000_000
Thinking this is way to high. Think the P2 spec is 180 MHz and most 2 layer implementations can only achieve around 320 MHz with any reliability.
Might recommend dialing this down to 250 MHz or so...
Might also make BR_TERM = 230_400
At first glance, this is a bit confusing in the demo help:
SD:(unmounted)> help Dual FS Shell v1.0.0 Device/Mount Navigation Files ------------------------- ------------------------- ------------------------- dvc {sd|fl} Switch dir List (ls) type <file> Show (cat) mount [sd|fl|all] Mount tree [<path>] Dir tree hexdump <file> Hex (hd) unmount [sd|fl] Eject cd [<path>] Change dir copy <s> <d> Copy (cp) stats FS stats pwd Show dir del <file> Delete (rm) card Card (SD) mkdir <dir> Create dir ren <old> <new> Rename version Driver rmdir <dir> Remove dir move <s> <d> Move (mv) label [<name>] Vol label audit Check FS touch <file> Create cls Clear fsck Repair FS demo Demo files alias Aliases bench Throughput format [sd|fl] date [y m d h m s] Set/show date/time help This helpMight consider some horizontal separation, or maybe vertical separation with return for "more". Or something...
Can't figure out how to use the demo... Terminal window doesn't seem to match instructions:
When I type in "mount sd" it just hangs...
@Rayman i'm reading all of this and thinking. Meanwhile does this match the bahavior?
DEMO README.md
Meanwhile, the clock and term settings are what i'm using reliably all the time.
I never think to set them as i'm just expecting anyone to adapt to their hardware.
Do we have a community standard for these? I'll be glad to adjust to them.
I'm always working to make sure my tools work at best speeds (measuring with Logic Analyzer, looking at error rates and things. so these speeds are just common for me. For instance i run 2mbit term on all OSes: Windows, Linux and macOS.
But you are right, i would likely not be running the clock at 350MHz in a production product. ;-)
@"Stephen Moraco"
I think almost all the Parallax demos run at 180 MHz or so. Except HDMI at 250 MHz.
There may be an PSRAM demo that runs higher.
FlashDemo = 180 MHz
Looks like all the @JonnyMac demos are at 200 MHz.
350 MHz is really pushing the envelope. Think even heard of a P2 chip malfunctioning at a lower freq... But, that was maybe 1 in 20 or so...
Still, why risk trouble for no reason?
Think got demo working. Seems need to run in regular terminal and not the debug terminal...
Should it not work in the Spin Tools debug terminal?
@Rayman, ok, sounds good. I'll drop the demo clock and add instructions for dialing this in to your project's needs.
@"Stephen Moraco" As said above, demo is now working (or mostly working?) in spin tools ide terminal window.
But, have a question about the prompt...
At first get "SD:(unmounted)>", which seems right.
Is there any way to get anything else at first? If not, seems could simplify those instructions.
Or, at least clarify that prompt will be one of the those four.
Anyway, possible issue that I'm seeing is that after doing something like mount or dir, don't get that prompt again, just blank line.
Is it supposed to reshow the prompt?
@"Stephen Moraco" Testing a different pin arrangement that doesn't seem to work:
Guess this is using one extra pin for SD CS and also using same pin for sd and flash CLK.
Any chance this should work?
Guess should try with uncombined driver first...
Could change the board to be the regular way too...
This has me rethinking idea of messing with uSD/flash pinout.
Think will just change my new board to regular way. Board has a mistake anyway, so not a big deal.
Maybe instructions should include caveat that pin settings can't really be changed?
@Rayman, yep, will add the caveat. In the longer term, the option to target one's own boards can be made conditional on this driver's compilation, should there be sufficient interest.
Wouldn’t bother too much with that. Think I’m the only one doing unique things…
Although, the four bit usd board would be on its own pins, not shared. Can be used in this 1 bit mode…
Maybe that is easier case?