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

Skip to content

Commit c1f5a59

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 62054a0 commit c1f5a59

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
@@ -537,6 +537,71 @@ port and LAN(1) for the 1G port.
537537

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

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

0 commit comments

Comments
 (0)
0