8000 mimxrt: Set MSC default modes. · micropython/micropython@62054a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 62054a0

Browse files
committed
mimxrt: Set MSC default modes.
1. USB will be enabled BEFORE boot.py is executed, avoiding deadlocks by user written code. 2. MSC support is enabled in _boot.py according to the following rules: a) For a FAT file system, MSC will be enabled by default. b) For a LFS file system, MSC will be disabled by default. c) The setting can be overriden by a file with the name set_usb_mode.py, which can define usb_mode with the lines: usb_mode = "vcp+msc" # enable MSC or usb_mode = "vcp" # do not enable MSC If that file does not exist or is faulty, the default is used.
1 parent 40fa2d1 commit 62054a0

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

ports/mimxrt/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ int main(void) {
8585
// Execute _boot.py to set up the filesystem.
8686
pyexec_frozen_module("_boot.py");
8787

88+
// deferred tusb_init allowing a fs to be created before MSC access
89+
tusb_init();
90+
8891
// Execute user scripts.
8992
int ret = pyexec_file_if_exists("boot.py");
9093
if (ret & PYEXEC_FORCED_EXIT) {
9194
goto soft_reset_exit;
9295
}
9396

94-
// deferred tusb_init allowing a fs to be created before MSC access
95-
tusb_init();
96-
9797
// Do not execute main.py if boot.py failed
9898
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL && ret != 0) {
9999
ret = pyexec_file_if_exists("main.py");

ports/mimxrt/modules/_boot.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def fs_type(bdev):
3838
os.VfsFat.mkfs(bdev)
3939
vfs = os.VfsFat(bdev)
4040
os.mount(vfs, "/flash")
41+
usb_mode = "vcp+msc"
4142
else:
4243
try:
4344
vfs = os.VfsLfs2(bdev, progsize=256)
@@ -46,11 +47,25 @@ def fs_type(bdev):
4647
os.VfsLfs2.mkfs(bdev, progsize=256)
4748
vfs = os.VfsLfs2(bdev, progsize=256)
4849
os.mount(vfs, "/flash")
50+
usb_mode = "vcp"
4951

5052
os.chdir("/flash")
5153
sys.path.append("/flash")
5254
sys.path.append("/flash/lib")
5355

56+
try:
57+
from set_usb_mode import usb_mode
58+
except:
59+
pass
60+
61+
# Configure USB mode according to the default or the
62+
# config file in the file system
63+
if hasattr(mimxrt, "usb_mode"):
64+
try:
65+
mimxrt.usb_mode(usb_mode)
66+
except:
67+
pass
68+
5469
# do not mount the SD card if SKIPSD exists.
5570
try:
5671
os.stat("SKIPSD")

ports/mimxrt/msc_disk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
uint8_t tud_msc_state = EJECTED;
3838

39-
static bool msc_enabled = false;
39+
static bool msc_enabled = true;
4040

4141
void update_msc_state(void) {
4242
if (tud_msc_state == TRANSIT) {

0 commit comments

Comments
 (0)
0