8000 mimxrt: Add some documentation for the MSC mode. · micropython/micropython@bb76b8b · GitHub
[go: up one dir, main page]

Skip to content

Commit bb76b8b

Browse files
committed
mimxrt: Add some documentation for the MSC mode.
Including some notes about littlfs file system and MSC access. When the board is formatted with littlfs, the FS access method by the PC is different.
1 parent 4e62061 commit bb76b8b

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

docs/mimxrt/quickref.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,71 @@ port and LAN(1) for the 1G port.
540540

541541
For details of the network interface refer to the class :ref:`network.LAN <network.LAN>`.
542542

543+
544+
External drive mode
545+
-------------------
546+
547+
On some boards a mode is enabled, that mounts the board's internal file system as
548+
external USB drive, called MSC support. Data of that drive can be accessed and changed by the PC.
549+
In that state, access to the internal drive by the MicroPython is limited to
550+
read-only mode, avoiding file corruption. Changes made by the PC to the file system may not be visible
551+
at the board until the drive is ejected by the PC or a soft reset of the board
552+
is made.
553+
554+
To enable write access to by the board, eject the drive at the PC **and** perform
555+
a soft-reset on the board, either by pushing Ctrl-D at REPL or calling machine.soft_reset().
556+
557+
The external drive mode (MSC mode) is enabled of disabled according to the following rules:
558+
559+
a) For a FAT file system, MSC will be enabled by default.
560+
b) For a LFS file system, MSC will be disabled by default.
561+
c) The setting can be overridden by a file with the name
562+
set_usb_mode.py, which can define the usb_mode with the lines:
563+
564+
usb_mode = "vcp+msc" # enable MSC
565+
566+
or
567+
568+
usb_mode = "vcp" # do not enable MSC
569+
570+
If the file set_usb_mode.py does not exist or is faulty, the default is used.
571+
572+
The read-only state of the local file system access can be told by an IOCTL call of the file
573+
system's block device.::
574+
575+
import mimxrt
576+
577+
bdev = mimxrt.Flash()
578+
readonly = bdev.ioctl(7, 0)
579+
580+
If the drive is in read-only state, bdev.ioctl(7, 0) returns `True`.
581+
582+
The file system of the board has to be of FAT type for mounting and using with standard PC
583+
tools. But FAT is not enforced at the board. If the board's file system is littlefs, MSC
584+
mode is disable by default. If enabled in boot.py, the file system will be attached to the
585+
PC and will be accessible as a drive (e.g. /dev/sdc using Linux), but by default
586+
there is no file access. In that case, the files are locally still writeable.
587+
Changing the board's file system to FAT can be done then by formatting it from the PC.
588+
Alternatively, you can erase the root sector. Then, the FAT file system will be
589+
created at the next power-up. For erasing the root sector, write::
590+
591+
from mimxrt import Flash
592+
Flash().ioctl(6, 0)
593+
594+
Using littlefs-fuse for Linux you can mount the board's littlefs file system to the PC.
595+
See: https://github.com/littlefs-project/littlefs-fuse
596+
The block_size if 4096, the block_count depends on the size of the filesystem. e.g.::
597+
598+
# mounting the lfs2 file system of a Teensy 4.1 board at the PC
599+
mkdir mount
600+
sudo ./lfs --block_size=4096 --block_count=1791 -o allow_other -o nonempty /dev/sdc mount
601+
cd mount
602+
ls -l
603+
604+
In that case, the exclusive write access is NOT enforced. So be careful to only write
605+
to the file system by the PC.
606+
607+
543608
Transferring files
544609
------------------
545610

0 commit comments

Comments
 (0)
0