diff options
author | Damien George <damien@micropython.org> | 2024-02-02 13:51:18 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-02-07 13:25:10 +1100 |
commit | 4c56b39051b4a992d8691aa504cd2e76b958bf26 (patch) | |
tree | 9bd5e19a08626bf26c222c3e093e65916ce147b0 /docs/reference | |
parent | 7d28789544e4e35d8c931b41765dd64a53c506f1 (diff) | |
download | micropython-4c56b39051b4a992d8691aa504cd2e76b958bf26.tar.gz micropython-4c56b39051b4a992d8691aa504cd2e76b958bf26.zip |
docs: Use vfs module instead of os.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'docs/reference')
-rw-r--r-- | docs/reference/filesystem.rst | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/docs/reference/filesystem.rst b/docs/reference/filesystem.rst index d8092c58dd..48a4658560 100644 --- a/docs/reference/filesystem.rst +++ b/docs/reference/filesystem.rst @@ -108,11 +108,11 @@ RAM using a ``bytearray``:: It can be used as follows:: - import os + import vfs bdev = RAMBlockDev(512, 50) - os.VfsFat.mkfs(bdev) - os.mount(bdev, '/ramdisk') + vfs.VfsFat.mkfs(bdev) + vfs.mount(bdev, '/ramdisk') An example of a block device that supports both the simple and extended interface (i.e. both signatures and behaviours of the @@ -150,11 +150,11 @@ interface (i.e. both signatures and behaviours of the As it supports the extended interface, it can be used with :class:`littlefs <vfs.VfsLfs2>`:: - import os + import vfs bdev = RAMBlockDev(512, 50) - os.VfsLfs2.mkfs(bdev) - os.mount(bdev, '/ramdisk') + vfs.VfsLfs2.mkfs(bdev) + vfs.mount(bdev, '/ramdisk') Once mounted, the filesystem (regardless of its type) can be used as it normally would be used from Python code, for example:: @@ -197,16 +197,16 @@ recommended to use littlefs instead. To format the entire flash using FAT:: # ESP8266 and ESP32 - import os - os.umount('/') - os.VfsFat.mkfs(bdev) - os.mount(bdev, '/') + import vfs + vfs.umount('/') + vfs.VfsFat.mkfs(bdev) + vfs.mount(bdev, '/') # STM32 - import os, pyb - os.umount('/flash') - os.VfsFat.mkfs(pyb.Flash(start=0)) - os.mount(pyb.Flash(start=0), '/flash') + import os, vfs, pyb + vfs.umount('/flash') + vfs.VfsFat.mkfs(pyb.Flash(start=0)) + vfs.mount(pyb.Flash(start=0), '/flash') os.chdir('/flash') Littlefs @@ -222,16 +222,16 @@ resistant to filesystem corruption. To format the entire flash using littlefs v2:: # ESP8266 and ESP32 - import os - os.umount('/') - os.VfsLfs2.mkfs(bdev) - os.mount(bdev, '/') + import vfs + vfs.umount('/') + vfs.VfsLfs2.mkfs(bdev) + vfs.mount(bdev, '/') # STM32 - import os, pyb - os.umount('/flash') - os.VfsLfs2.mkfs(pyb.Flash(start=0)) - os.mount(pyb.Flash(start=0), '/flash') + import os, vfs, pyb + vfs.umount('/flash') + vfs.VfsLfs2.mkfs(pyb.Flash(start=0)) + vfs.mount(pyb.Flash(start=0), '/flash') os.chdir('/flash') A littlefs filesystem can be still be accessed on a PC over USB MSC using the @@ -264,14 +264,14 @@ block devices spanning a subset of the flash device. For example, to configure the first 256kiB as FAT (and available over USB MSC), and the remainder as littlefs:: - import os, pyb - os.umount('/flash') + import os, vfs, pyb + vfs.umount('/flash') p1 = pyb.Flash(start=0, len=256*1024) p2 = pyb.Flash(start=256*1024) - os.VfsFat.mkfs(p1) - os.VfsLfs2.mkfs(p2) - os.mount(p1, '/flash') - os.mount(p2, '/data') + vfs.VfsFat.mkfs(p1) + vfs.VfsLfs2.mkfs(p2) + vfs.mount(p1, '/flash') + vfs.mount(p2, '/data') os.chdir('/flash') This might be useful to make your Python files, configuration and other @@ -282,9 +282,9 @@ failure, etc. The partition at offset ``0`` will be mounted automatically (and the filesystem type automatically detected), but you can add:: - import os, pyb + import vfs, pyb p2 = pyb.Flash(start=256*1024) - os.mount(p2, '/data') + vfs.mount(p2, '/data') to ``boot.py`` to mount the data partition. @@ -297,7 +297,7 @@ define an arbitrary partition layout. At boot, the partition named "vfs" will be mounted at ``/`` by default, but any additional partitions can be mounted in your ``boot.py`` using:: - import esp32, os + import esp32, vfs p = esp32.Partition.find(esp32.Partition.TYPE_DATA, label='foo') - os.mount(p, '/foo') + vfs.mount(p, '/foo') |