Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Infineon Team
Published © MIT

Maximizing Storage: SD Card with FAT and LFS2 Filesystems

Learn how to optimize your storage options by effectively mounting an SD card using both FAT and LFS2 filesystems, with MicroPython!

IntermediateProtip30 minutes622
Maximizing Storage: SD Card with FAT and LFS2 Filesystems

Things used in this project

Hardware components

CY8CPROTO-062-4343W
Infineon CY8CPROTO-062-4343W
×1
Flash Memory Card, MicroSD Card
Flash Memory Card, MicroSD Card
×1

Software apps and online services

MicroPython
MicroPython

Story

Read more

Code

Code with LSF2 Filesystem

MicroPython
import machine
import os

bdev = machine.SDCard(slot=0, width=4, cd="P13_5", cmd="P12_4", clk="P12_5", dat0="P13_0", dat1="P13_1", dat2="P13_2", dat3="P13_3")
try:
    vfs = os.VfsLfs2(bdev, progsize=512, readsize=512)
    os.mount(vfs, "/SDCardLfs2")
except OSError:
    os.VfsLfs2.mkfs(bdev, progsize=512, readsize=512)
    vfs = os.VfsLfs2(bdev, progsize=512, readsize=512)
    os.mount(vfs, "/SDCardLfs2")


TEST_STRING = "This is a test string."


with open("/SDCardLfs2/test_sd_lfs2.txt", "w") as f:
    f.write(TEST_STRING)

with open("/SDCardLfs2/test_sd_lfs2.txt", "r") as f:
    read_data = f.read()
    print(read_data)


bdev.deinit()

Code with FAT Filesystem

MicroPython
import machine
import os


bdev = machine.SDCard(slot=0, width=4, cd="P13_5", cmd="P12_4", clk="P12_5", dat0="P13_0", dat1="P13_1", dat2="P13_2", dat3="P13_3")


try:
    vfs = os.VfsFat(bdev)
    os.mount(vfs, "/SDCardFat")

except OSError:
    os.VfsFat.mkfs(bdev)
    vfs = os.VfsFat(bdev)
    os.mount(vfs, "/SDCardFat")


with open("/SDCardFat/test_sd_fat.txt", "w") as f:
    f.write(TEST_STRING)



with open("/SDCardFat/test_sd_fat.txt", "r") as f:
    read_data = f.read()
    print(read_data)


bdev.deinit()

Credits

Infineon Team
96 projects • 147 followers
Contact

Comments

Please log in or sign up to comment.