Shop OBEX P1 Docs P2 Docs Learn Events
Read / Write to microSD card on Edge? — Parallax Forums

Read / Write to microSD card on Edge?

jrullanjrullan Posts: 168
edited 2023-05-31 15:00 in Propeller 2

Is there a way or driver to be able to read a file from the microSD card on the Edge?

I would like to store images there and read them into my program without bloating the spin2 file. Similarly, I would like to be able to write to the microSD to use it for data collection.

Any help is appreciated.

Edit: I've seen this post but I'm not sure where is the latest version https://forums.parallax.com/discussion/171176/memory-drivers-for-p2-psram-sram-hyperram-was-hyperram-driver-for-p2

Comments

  • When using flexspin, you can

    OBJ
      c : "libc"
    
    PUB main()
    _mount(@"/sd",c._vfs_open_sdcard())
    

    and then use the C style file I/O functions (fopen and friends) on the libc object.

    Otherwise, there's this: https://forums.parallax.com/discussion/173378/the-actually-functional-spin2-sd-driver-i-hope-kyefat-sdspi-with-audio

  • RaymanRayman Posts: 14,744

    There's also a version of FSRW around that uses the same low level driver.
    That got broke by a change to Spin2 loop index behavior.
    Code was fixed to compensate for that.
    But now, Spin2 has reverted to previous behavior.
    So, code is probably broke again...

  • jrullanjrullan Posts: 168
    edited 2023-05-31 23:01

    @Wuerfel_21 said:
    When using flexspin, you can

    OBJ
      c : "libc"
    
    PUB main()
    _mount(@"/sd",c._vfs_open_sdcard())
    

    and then use the C style file I/O functions (fopen and friends) on the libc object.

    Otherwise, there's this: https://forums.parallax.com/discussion/173378/the-actually-functional-spin2-sd-driver-i-hope-kyefat-sdspi-with-audio

    @Wuerfel_21 would it work even when booting from the microSD card? I ask because the microSD card has to be formatted FAT32 to be used for booting the sketch and I would like to preserve that feature in my project, but at least in your version it seems (if I understood correctly) that it supports a different format KyeFAT....

    Digressing a bit (or a lot) it would be so cool if when booting from the microSD card there would be an equivalent to the DAT FILE directive that could point to an external file from inside the SPIN2 program.

    Edit: Corrected Kye name

  • @Rayman said:
    There's also a version of FSRW around that uses the same low level driver.
    That got broke by a change to Spin2 loop index behavior.
    Code was fixed to compensate for that.
    But now, Spin2 has reverted to previous behavior.
    So, code is probably broke again...

    Do you know where can I find that FSRW?

  • evanhevanh Posts: 16,027

    @jrullan said:
    would it work even when booting from the microSD card? I ask because the microSD card has to be formatted FAT32 to be used for booting the sketch and I would like to preserve that feature in my project, but at least in your version it seems (if I understood correctly) that it supports a different format keyFAT....

    Yes, reads any FAT32 SD card. Including the booted one. KeyFAT is named after the Indian dude that wrote it for the Prop1.

  • ke4pjwke4pjw Posts: 1,169
    edited 2023-05-31 21:01

    I do the types of things you are trying to do, with my light controller project using my own version of FSRW @kye 's FAT32 and @Wuerfel_21 's sdapi driver.

    https://griswoldfx.visualstudio.com/Blitzen 24

    Get the fat32.spin2 and sdspi_with_audio.spin2 files from the repo.

    • It boots from SD.
    • It mounts and accesses the filesystem at runtime.
    • Loads the config into RAM and serves webpages.
    • It self-updates the boot file when new firmware is available on the Internet.

    There are some caveats:

    • You must dismount the SD card before a software reset.
    • You cannot hardware reset the Edge correctly unless you dismount, or remove, or powercycle the SD card. (And you can't power cycle it with Edge)
    • You cannot program the flash once the SD card has been mounted, unless you remove or powercycle the SD card. (See above)

    I will be happy to help you with this, as I spent all of last year researching and fighting issues with it :)

  • RaymanRayman Posts: 14,744

    I'd probably recommend that version that @Wuerfel_21 and @ke4pw mention.
    Maybe FSRW is working or maybe it will not work or maybe it will erase you card and need reformatting, who knows been a while...
    It's posted here though: https://forums.parallax.com/discussion/173378/the-actually-functional-spin2-sd-driver-i-hope-kyefat-sdspi-with-audio/p2

  • evanhevanh Posts: 16,027

    Lol, yes, Kye is his name. Can't believe I verbatim copied the spelling there.

  • @evanh said:
    Lol, yes, Kye is his name. Can't believe I verbatim copied the spelling there.

    OMG! I'm sorry, did not see that, my dyslexia is acting up. Fixed my post.

    @ke4pjw said:
    I do the types of things you are trying to do, with my light controller project using my own version of FSRW @kye 's FAT32 and @Wuerfel_21 's sdapi driver.

    https://griswoldfx.visualstudio.com/Blitzen 24

    Get the fat32.spin2 and sdspi_with_audio.spin2 files from the repo.

    • It boots from SD.
    • It mounts and accesses the filesystem at runtime.
    • Loads the config into RAM and serves webpages.
    • It self-updates the boot file when new firmware is available on the Internet.

    There are some caveats:

    • You must dismount the SD card before a software reset.
    • You cannot hardware reset the Edge correctly unless you dismount, or remove, or powercycle the SD card. (And you can't power cycle it with Edge)
    • You cannot program the flash once the SD card has been mounted, unless you remove or powercycle the SD card. (See above)

    I will be happy to help you with this, as I spent all of last year researching and fighting issues with it :)

    Thanks @ke4pjw , I've been busy with my project and haven't yet worked my way to test Blitzen yet. Maybe once I learn a bit more about this I will feel less intimidated to do some testing with it. I'll give it a go for sure.

Sign In or Register to comment.