mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Refactor firmware uploading to the embedded boards with SAM-BA bootloader
This commit is contained in:
@ -14,7 +14,7 @@
|
||||
|
||||
import sys
|
||||
|
||||
VERSION = (2, 9, "3.dev0")
|
||||
VERSION = (2, 9, "3.dev1")
|
||||
__version__ = ".".join([str(s) for s in VERSION])
|
||||
|
||||
__title__ = "platformio"
|
||||
|
@ -65,7 +65,7 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
|
||||
if not upload_options.get("disable_flushing", False):
|
||||
env.FlushSerialBuffer("$UPLOAD_PORT")
|
||||
|
||||
before_ports = [i['port'] for i in get_serialports(use_grep=True)]
|
||||
before_ports = get_serialports()
|
||||
|
||||
if upload_options.get("use_1200bps_touch", False):
|
||||
env.TouchSerialPort("$UPLOAD_PORT", 1200)
|
||||
|
@ -41,7 +41,7 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
|
||||
if not upload_options.get("disable_flushing", False):
|
||||
env.FlushSerialBuffer("$UPLOAD_PORT")
|
||||
|
||||
before_ports = [i['port'] for i in get_serialports(use_grep=True)]
|
||||
before_ports = get_serialports()
|
||||
|
||||
if upload_options.get("use_1200bps_touch", False):
|
||||
env.TouchSerialPort("$UPLOAD_PORT", 1200)
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import sys
|
||||
from os.path import isfile, join
|
||||
from shutil import copyfile
|
||||
from time import sleep
|
||||
@ -49,21 +50,25 @@ def TouchSerialPort(env, port, baudrate):
|
||||
|
||||
def WaitForNewSerialPort(env, before):
|
||||
print "Waiting for the new upload port..."
|
||||
prev_port = env.subst("$UPLOAD_PORT")
|
||||
new_port = None
|
||||
elapsed = 0
|
||||
while elapsed < 5:
|
||||
now = [i['port'] for i in get_serialports(use_grep=True)]
|
||||
diff = list(set(now) - set(before))
|
||||
if diff:
|
||||
new_port = diff[0]
|
||||
break
|
||||
|
||||
while elapsed < 5 and new_port is None:
|
||||
now = get_serialports()
|
||||
for p in now:
|
||||
if p not in before:
|
||||
new_port = p['port']
|
||||
break
|
||||
before = now
|
||||
sleep(0.25)
|
||||
elapsed += 0.25
|
||||
|
||||
if not new_port and env.subst("$UPLOAD_PORT") in now:
|
||||
new_port = env.subst("$UPLOAD_PORT")
|
||||
if not new_port:
|
||||
for p in now:
|
||||
if prev_port == p['port']:
|
||||
new_port = p['port']
|
||||
break
|
||||
|
||||
if not new_port:
|
||||
env.Exit("Error: Couldn't find a board on the selected port. "
|
||||
"Check that you have the correct port selected. "
|
||||
|
@ -280,34 +280,7 @@ def exec_command(*args, **kwargs):
|
||||
return result
|
||||
|
||||
|
||||
def get_serialports(use_grep=False):
|
||||
|
||||
def _grep_serial_ports():
|
||||
result = []
|
||||
if system() == "Windows":
|
||||
output = exec_command(["mode"]).get("out", "")
|
||||
for line in output.split("\n"):
|
||||
line = line.strip()
|
||||
if "COM" in line:
|
||||
result.append({"port": line[line.index("COM"):-1],
|
||||
"description": "", "hwid": ""})
|
||||
else:
|
||||
if system() == "Linux":
|
||||
patterns = ["/dev/%s*" % p for p in (
|
||||
"ttyS", "ttyUSB", "ttyACM", "ttyAMA", "rfcomm", "ttyO")]
|
||||
else:
|
||||
patterns = ["/dev/tty.*", "/dev/cu.*"]
|
||||
for pattern in patterns:
|
||||
for port in glob(pattern):
|
||||
result.append(
|
||||
{"port": port, "description": "", "hwid": ""})
|
||||
return result
|
||||
|
||||
if use_grep:
|
||||
result = _grep_serial_ports()
|
||||
if result:
|
||||
return result
|
||||
|
||||
def get_serialports():
|
||||
try:
|
||||
from serial.tools.list_ports import comports
|
||||
except ImportError:
|
||||
@ -325,9 +298,9 @@ def get_serialports(use_grep=False):
|
||||
result.append({"port": p, "description": d, "hwid": h})
|
||||
|
||||
# fix for PySerial
|
||||
if not result and not use_grep and system() == "Darwin":
|
||||
result = _grep_serial_ports()
|
||||
|
||||
if not result and system() == "Darwin":
|
||||
for p in glob("/dev/tty.*"):
|
||||
result.append({"port": p, "description": "", "hwid": ""})
|
||||
return result
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user