Skip to content

Commit 226c034

Browse files
committed
tools/mpremote: Remove support for pyb.USB_VCP in/out specialisation.
The sys.stdin.buffer and sys.stdout.buffer streams work just as well (and are just as fast) as pyb.USB_VCP on stm32 devices, so there's no need to have the USB_VCP specialisation code, which just adds complexity. Also, on stm32 devices with both USB and UART (or other serial interface), if something other than the USB_VCP port is used for the serial connection then mpremote mount will not work because it will default to reading and writing on USB_VCP instead of the other connected serial stream. As part of this simplification, support for a second port as input is removed (this feature was never exposed to the user). Signed-off-by: Damien George <[email protected]>
1 parent 5555f14 commit 226c034

File tree

1 file changed

+12
-35
lines changed

1 file changed

+12
-35
lines changed

tools/mpremote/mpremote/pyboardextended.py

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,18 @@
2424
}
2525

2626
fs_hook_code = """\
27-
import uos, uio, ustruct, micropython, usys
27+
import uos, uio, ustruct, micropython
2828
2929
SEEK_SET = 0
3030
3131
class RemoteCommand:
32-
def __init__(self, use_second_port):
32+
def __init__(self):
33+
import uselect, usys
3334
self.buf4 = bytearray(4)
34-
try:
35-
import pyb
36-
self.fout = pyb.USB_VCP()
37-
if use_second_port:
38-
self.fin = pyb.USB_VCP(1)
39-
else:
40-
self.fin = pyb.USB_VCP()
41-
except:
42-
import usys
43-
self.fout = usys.stdout.buffer
44-
self.fin = usys.stdin.buffer
45-
import select
46-
self.poller = select.poll()
47-
self.poller.register(self.fin, select.POLLIN)
35+
self.fout = usys.stdout.buffer
36+
self.fin = usys.stdin.buffer
37+
self.poller = uselect.poll()
38+
self.poller.register(self.fin, uselect.POLLIN)
4839
4940
def poll_in(self):
5041
for _ in self.poller.ipoll(1000):
@@ -317,8 +308,8 @@ def open(self, path, mode):
317308
return RemoteFile(c, fd, mode.find('b') == -1)
318309
319310
320-
def __mount(use_second_port):
321-
uos.mount(RemoteFS(RemoteCommand(use_second_port)), '/remote')
311+
def __mount():
312+
uos.mount(RemoteFS(RemoteCommand()), '/remote')
322313
uos.chdir('/remote')
323314
"""
324315

@@ -571,28 +562,14 @@ def __init__(self, dev, *args, **kwargs):
571562
self.device_name = dev
572563
self.mounted = False
573564

574-
def mount_local(self, path, dev_out=None):
565+
def mount_local(self, path):
575566
fout = self.serial
576-
if dev_out is not None:
577-
try:
578-
fout = serial.Serial(dev_out)
579-
except serial.SerialException:
580-
port = list(serial.tools.list_ports.grep(dev_out))
581-
if not port:
582-
raise
583-
for p in port:
584-
try:
585-
fout = serial.Serial(p.device)
586-
break
587-
except serial.SerialException:
588-
pass
589567
self.mounted = True
590568
if self.eval('"RemoteFS" in globals()') == b"False":
591569
self.exec_(fs_hook_code)
592-
self.exec_("__mount(%s)" % (dev_out is not None))
570+
self.exec_("__mount()")
593571
self.cmd = PyboardCommand(self.serial, fout, path)
594572
self.serial = SerialIntercept(self.serial, self.cmd)
595-
self.dev_out = dev_out
596573

597574
def soft_reset_with_mount(self, out_callback):
598575
self.serial.write(b"\x04")
@@ -618,7 +595,7 @@ def soft_reset_with_mount(self, out_callback):
618595
n = self.serial.inWaiting()
619596
self.serial.write(b"\x01")
620597
self.exec_(fs_hook_code)
621-
self.exec_("__mount(%s)" % (self.dev_out is not None))
598+
self.exec_("__mount()")
622599
self.exit_raw_repl()
623600
self.read_until(4, b">>> ")
624601
self.serial = SerialIntercept(self.serial, self.cmd)

0 commit comments

Comments
 (0)