Shop OBEX P1 Docs P2 Docs Learn Events
P2 DUAL uSD FAT32 and FLASH Filesystem (spin2/pasm2) — Parallax Forums

P2 DUAL uSD FAT32 and FLASH Filesystem (spin2/pasm2)

Stephen MoracoStephen Moraco Posts: 457
edited 2026-03-08 08:40 in Propeller 2

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

  • RaymanRayman Posts: 16,197

    This sounds great! Thanks.

  • RaymanRayman Posts: 16,197

    Is this flash file system compatible with the one Chip made?

  • Stephen MoracoStephen Moraco Posts: 457
    edited 2026-03-08 19:23

    @Rayman said:
    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:

    v1.1.0

    ### Fixed
    - BUGFIX: SPI write data integrity at power-of-2 half-period clock speeds (writeSector() and writeSectors())

    ### Added
    - Selective debug: 12-channel DEBUG_MASK system for debug[CH_xxx]() output -- developers enable 2-3 channels at a time to stay under the P2 255-record limit
    - FlexSpin compatibility: All 43 compilable files build with both pnut-ts and FlexSpin 7.6.1

    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

  • RaymanRayman Posts: 16,197
    edited 2026-03-11 23:10

    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:

    v1.2.0

    ## SD sub-driver upgraded to v1.4.0: Internal date/time, auto-flush, non-blocking I/O, creation/modification timestamps.

    ### Added
    - Internal date/time: setDate() validates parameters and activates a 2-second clock; getDate() reads the Internal date/time
    - Auto-flush: Dirty file handles and FSInfo flushed automatically after 200 ms idle
    - Non-blocking I/O (SD_INCLUDE_ASYNC): startReadHandle(), startWriteHandle(), isComplete(), getResult(), cancelAsync()
    - Creation timestamps: Files receive correct create timestamps on file create
    - Modification timestamps: Files receive correct write timestamps on close and sync
    - wrtDate(), wrtTime(): Read modification timestamps from directory entries
    - Demo shell: date command (set/display), dir now shows date/time columns
    - DFS_SD_RT_timestamp_tests -- 9 tests for live clock and date validation
    - DFS_SD_RT_async_tests -- 12 tests for non-blocking I/O
    - 3 auto-flush tests added to DFS_SD_RT_volume_tests
    - setDate(): Validates parameters and returns status code (SUCCESS or E_INVALID_PARAM)

    ### Changed

    - Regression suite expanded to 31 standard suites, 1,332 tests

    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

  • RaymanRayman Posts: 16,197

    @"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...

  • RaymanRayman Posts: 16,197

    Might also make BR_TERM = 230_400

  • RaymanRayman Posts: 16,197

    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 help
    

    Might consider some horizontal separation, or maybe vertical separation with return for "more". Or something...

  • RaymanRayman Posts: 16,197
    edited 2026-03-24 19:12

    Can't figure out how to use the demo... Terminal window doesn't seem to match instructions:

    * Press return to start...
    
    P2 Dual Filesystem Shell (SD + Flash)
    - type 'help' for commands
    
    Startup
    When the shell starts, it clears the screen and displays a welcome banner. The prompt shows the active device, current directory, and mount status:
    
    sd:/> _                  (SD mounted, at root)
    sd:/MYDIR> _             (SD mounted, in MYDIR)
    flash:/> _               (Flash active, mounted)
    sd:(unmounted)> _        (SD not mounted)
    

    When I type in "mount sd" it just hangs...

    P2 Dual Filesystem Shell (SD + Flash)
    - type 'help' for commands
    mount sd
    SD:(unmounted)> mount sd
    status
    
    
  • Stephen MoracoStephen Moraco Posts: 457
    edited 2026-03-24 19:27

    @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. ;-)

  • RaymanRayman Posts: 16,197

    @"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?

  • RaymanRayman Posts: 16,197
    edited 2026-03-24 20:34

    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.

  • RaymanRayman Posts: 16,197

    @"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?

  • RaymanRayman Posts: 16,197
    edited 2026-03-24 21:43

    @"Stephen Moraco" Testing a different pin arrangement that doesn't seem to work:

    CON ' ---- P2 Edge Module SPI Pin Assignments (fixed hardware) ----
      PIN_SD_CS   = 57 '60    ' SD chip select (also Flash SCK)
      PIN_MOSI    = 59    ' Shared MOSI
      PIN_MISO    = 58    ' Shared MISO
      PIN_SD_SCK  = 60 '61    ' SD serial clock (also Flash CS)
      PIN_FL_CS   = 61    ' Flash chip select (= SD SCK pin)
      PIN_FL_SCK  = 60    ' Flash serial clock (= SD CS pin)
    

    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...

  • RaymanRayman Posts: 16,197

    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?

  • Stephen MoracoStephen Moraco Posts: 457
    edited 2026-03-24 22:12

    @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.

  • RaymanRayman Posts: 16,197

    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?

Sign In or Register to comment.