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